-
admin
2024-05-17 1ccd6932893e47722574e6d1147e63b2ec4972c1
提交 | 用户 | 时间
e57a89 1 <template>
2     <el-form size="small">
3         <el-form-item>
4             <el-radio v-model='radioValue' :label="1">
5                 秒,允许的通配符[, - * /]
6             </el-radio>
7         </el-form-item>
8
9         <el-form-item>
10             <el-radio v-model='radioValue' :label="2">
11                 周期从
12                 <el-input-number v-model='cycle01' :min="0" :max="58" /> -
13                 <el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 1" :max="59" /> 秒
14             </el-radio>
15         </el-form-item>
16
17         <el-form-item>
18             <el-radio v-model='radioValue' :label="3">
19                 从
20                 <el-input-number v-model='average01' :min="0" :max="58" /> 秒开始,每
21                 <el-input-number v-model='average02' :min="1" :max="59 - average01 || 0" /> 秒执行一次
22             </el-radio>
23         </el-form-item>
24
25         <el-form-item>
26             <el-radio v-model='radioValue' :label="4">
27                 指定
28                 <el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%">
29                     <el-option v-for="item in 60" :key="item" :value="item-1">{{item-1}}</el-option>
30                 </el-select>
31             </el-radio>
32         </el-form-item>
33     </el-form>
34 </template>
35
36 <script>
37 export default {
38     data() {
39         return {
40             radioValue: 1,
41             cycle01: 1,
42             cycle02: 2,
43             average01: 0,
44             average02: 1,
45             checkboxList: [],
46             checkNum: this.$options.propsData.check
47         }
48     },
49     name: 'crontab-second',
50     props: ['check', 'radioParent'],
51     methods: {
52         // 单选按钮值变化时
53         radioChange() {
54             switch (this.radioValue) {
55                 case 1:
56                     this.$emit('update', 'second', '*', 'second');
57                     break;
58                 case 2:
59                     this.$emit('update', 'second', this.cycleTotal);
60                     break;
61                 case 3:
62                     this.$emit('update', 'second', this.averageTotal);
63                     break;
64                 case 4:
65                     this.$emit('update', 'second', this.checkboxString);
66                     break;
67             }
68         },
69         // 周期两个值变化时
70         cycleChange() {
71             if (this.radioValue == '2') {
72                 this.$emit('update', 'second', this.cycleTotal);
73             }
74         },
75         // 平均两个值变化时
76         averageChange() {
77             if (this.radioValue == '3') {
78                 this.$emit('update', 'second', this.averageTotal);
79             }
80         },
81         // checkbox值变化时
82         checkboxChange() {
83             if (this.radioValue == '4') {
84                 this.$emit('update', 'second', this.checkboxString);
85             }
86         }
87     },
88     watch: {
89         'radioValue': 'radioChange',
90         'cycleTotal': 'cycleChange',
91         'averageTotal': 'averageChange',
92         'checkboxString': 'checkboxChange',
93         radioParent() {
94             this.radioValue = this.radioParent
95         }
96     },
97     computed: {
98         // 计算两个周期值
99         cycleTotal: function () {
100             const cycle01 = this.checkNum(this.cycle01, 0, 58)
101             const cycle02 = this.checkNum(this.cycle02, cycle01 ? cycle01 + 1 : 1, 59)
102             return cycle01 + '-' + cycle02;
103         },
104         // 计算平均用到的值
105         averageTotal: function () {
106             const average01 = this.checkNum(this.average01, 0, 58)
107             const average02 = this.checkNum(this.average02, 1, 59 - average01 || 0)
108             return average01 + '/' + average02;
109         },
110         // 计算勾选的checkbox值合集
111         checkboxString: function () {
112             let str = this.checkboxList.join();
113             return str == '' ? '*' : str;
114         }
115     }
116 }
117 </script>