year.vue 4.4 KB
Newer Older
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
<template lang="html">
  <div :val="value_">
    <div>
      <el-radio v-model="type" label="1" size="mini" border>{{ $t('components.cronEditor.year.everyYear') }}</el-radio>
    </div>
    <div>
      <el-radio v-model="type" label="5" size="mini" border>{{ $t('components.cronEditor.public.notSpecify') }}</el-radio>
    </div>
    <div>
      <el-radio v-model="type" label="2" size="mini" border>{{ $t('components.cronEditor.public.cycle') }}</el-radio>
      <span style="margin-left: 10px; margin-right: 5px;">{{ $t('components.cronEditor.public.from') }}</span>
      <el-input-number @change="type = '2'" v-model="cycle.start" :min="2000" size="mini" style="width: 100px;"></el-input-number>
      <span style="margin-left: 5px; margin-right: 5px;">{{ $t('components.cronEditor.public.to') }}</span>
      <el-input-number @change="type = '2'" v-model="cycle.end" :min="2000"  size="mini" style="width: 100px;"></el-input-number>
      {{ $t('components.cronEditor.year.title') }}
    </div>
  </div>
</template>

<script lang='ts'>
import { Vue, Watch, Component } from 'vue-property-decorator';

@Component({})
export default class Year extends Vue {

    /**
     * Cron表达式
     *
     * @type {any}
     * @memberof Day
     */ 
    public value: any;

    /**
     * 标签类型标识
     *
     * @type {any}
     * @memberof Day
     */ 
    public type: string = '1';

    /**
     * 周期
     *
     * @type {any}
     * @memberof Day
     */ 
    public cycle: any = {
        start: 0,
        end: 0
    };

    /**
     * 循环
     *
     * @type {any}
     * @memberof Day
     */ 
    public loop: any = {
        start: 0,
        end: 0
    }

    /**
     * 周
     *
     * @type {any}
     * @memberof Day
     */ 
    public week: any = {
        start: 0,
        end: 0
    }

    /**
     * 工作日
     *
     * @type {any}
     * @memberof Day
     */ 
    public work: number = 0;

    /**
     * 最后
     *
     * @type {any}
     * @memberof Day
     */ 
    public last: number = 0;

    /**
     * 指定
     *
     * @type {any}
     * @memberof Day
     */ 
    public appoint: any = [];

    /**
     * 获取Cron表达式
     * 
     * @returns
     * @memberof Day
     */
    get value_() {
      let result = []
      switch (this.type) {
        case '1': // 每秒
          result.push('*')
          break
        case '2': // 年期
          result.push(`${this.cycle.start}-${this.cycle.end}`)
          break
        case '3': // 循环
          result.push(`${this.loop.start}/${this.loop.end}`)
          break
        case '4': // 指定
          result.push(this.appoint.join(','))
          break
        case '6': // 最后
          result.push(`${this.last === 0 ? '' : this.last}L`)
          break
        default: // 不指定
          result.push('?')
          break
      }
      this.$emit('input', result.join(''))
      return result.join('')    
    }

    /**
     * 数据值变化
     * 
     * @returns
     * @memberof Day
     */
    @Watch('value')
    public updateVal() {
         if (!this.value) {
        return
      }
      if (this.value === '?') {
        this.type = '5'
      } else if (this.value.indexOf('-') !== -1) { // 2周期
        if (this.value.split('-').length === 2) {
          this.type = '2'
          this.cycle.start = this.value.split('-')[0]
          this.cycle.end = this.value.split('-')[1]
        }
      } else if (this.value.indexOf('/') !== -1) { // 3循环
        if (this.value.split('/').length === 2) {
          this.type = '3'
          this.loop.start = this.value.split('/')[0]
          this.loop.end = this.value.split('/')[1]
        }
      } else if (this.value.indexOf('*') !== -1) { // 1每
        this.type = '1'
      } else if (this.value.indexOf('L') !== -1) { // 6最后
        this.type = '6'
        this.last = this.value.replace('L', '')
      } else if (this.value.indexOf('#') !== -1) { // 7指定周
        if (this.value.split('#').length === 2) {
          this.type = '7'
          this.week.start = this.value.split('#')[0]
          this.week.end = this.value.split('#')[1]
        }
      } else if (this.value.indexOf('W') !== -1) { // 8工作日
        this.type = '8'
        this.work = this.value.replace('W', '')
      } else { // *
        this.type = '4'
        this.appoint = this.value.split(',')
      }
    }

    public created() {
      this.updateVal();
    }
}
</script>

<style lang="css">
.el-checkbox+.el-checkbox {
    margin-left: 10px;
}
</style>