all files / src/timePicker/ clockNumber.vue

14.29% Statements 2/14
0% Branches 0/6
100% Functions 0/0
15.38% Lines 2/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111              1×                           1×                                                                                                                                                                                  
<template>
<span class="mu-clock-number" :class="numberClass" :style="numberStyle">{{value === 0 ? '00' : value}}</span>
</template>
 
<script>
import {isInner} from './timeUtils'
 
const positions = [
    [0, 5],
    [54.5, 16.6],
    [94.4, 59.5],
    [109, 114],
    [94.4, 168.5],
    [54.5, 208.4],
    [0, 223],
    [-54.5, 208.4],
    [-94.4, 168.5],
    [-109, 114],
    [-94.4, 59.5],
    [-54.5, 19.6]
]
const innerPositions = [
    [0, 40],
    [36.9, 49.9],
    [64, 77],
    [74, 114],
    [64, 151],
    [37, 178],
    [0, 188],
    [-37, 178],
    [-64, 151],
    [-74, 114],
    [-64, 77],
    [-37, 50]
]
 
export default {
  props: {
    value: {
      type: Number,
      default: 0
    },
    type: {
      type: String,
      default: 'minute',
      validator (val) {
        return ['hour', 'minute'].indexOf(val) !== -1
      }
    },
    selected: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    isInner () {
      return isInner(this)
    },
    numberClass () {
      return {
        selected: this.selected,
        inner: this.isInner
      }
    },
    numberStyle () {
      let pos = this.value
      if (this.type === 'hour') {
        pos %= 12
      } else {
        pos = pos / 5
      }
      let transformPos = positions[pos]
      if (this.isInner) transformPos = innerPositions[pos]
      const [x, y] = transformPos
      return {
        transform: `translate(${x}px, ${y}px)`,
        left: this.isInner ? 'calc(50% - 14px)' : 'calc(50% - 16px)'
      }
    }
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-clock-number{
  display: inline-block;
  width: 32px;
  height: 32px;
  line-height: 24px;
  position: absolute;
  top: 10px;
  text-align: center;
  padding-top: 5px;
  font-size: 1.1em;
  pointer-events: none;
  border-radius: 100%;
  box-sizing: border-box;
  transform: translate(0px, 5px);
  user-select: none;
  &.selected {
    background-color: @primaryColor;
    color: @alternateTextColor;
  }
  &.inner {
    width: 28px;
    height: 28px;
  }
}
</style>