key.vue 1.6 KB
Newer Older
1
<template>
G
guoweijia 已提交
2
  <div
郭维嘉 已提交
3
    :class="['key', { active: isCurrentKey($store.state.currentKey) }]"
G
guoweijia 已提交
4 5
    :style="{
      'min-width': keyWidth + 'px',
郭维嘉 已提交
6
      flex: type === 'Fill' ? 1 : 'none'
G
guoweijia 已提交
7 8
    }"
  >
9 10 11 12 13 14 15 16 17 18 19 20 21
    <div class="multiple" v-if="subName">
      <span v-html="subName"></span>
      <span v-html="primaryName"></span>
    </div>
    <span v-else v-html="primaryName"></span>
  </div>
</template>

<script>
export default {
  props: {
    type: {
      type: String,
郭维嘉 已提交
22
      default: ""
23 24 25
    },
    primaryName: {
      type: String,
郭维嘉 已提交
26
      default: ""
27 28 29
    },
    subName: {
      type: String,
郭维嘉 已提交
30 31
      defualt: ""
    }
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  },
  computed: {
    keyWidth() {
      let keyWidth = 44;
      const keyType = this.type;
      if (!keyType) return keyWidth;
      switch (keyType) {
        case "Letter":
          keyWidth = 44;
          break;
        case "Tab":
          keyWidth = 72;
          break;
        case "Caps Lock":
          keyWidth = 82;
          break;
G
guoweijia 已提交
48 49 50 51 52
        case "Shift":
          keyWidth = 110;
          break;
        case "Function":
          keyWidth = 80;
53 54 55 56 57
          break;
        default:
          break;
      }
      return keyWidth;
郭维嘉 已提交
58
    }
59
  },
郭维嘉 已提交
60 61 62 63 64 65
  methods: {
    isCurrentKey(key) {
      if (key === null) return false;
      return key.toLowerCase() === this.primaryName.toLowerCase();
    }
  }
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
};
</script>

<style lang="less" scoped>
.key {
  height: 44px;
  line-height: 44px;
  background: skyblue;
  border-radius: 4px;
  margin: 2px;
  .multiple {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: 100%;
    span {
      line-height: 1em;
    }
  }
郭维嘉 已提交
85 86 87
  &.active {
    opacity: 0.4;
  }
88 89
}
</style>