中国算力平台算力登记系统2.0
YZFG
2024-09-30 43dc2996fd2033991539ed35a0429238829a5417
commit | author | age
43dc29 1 <template>
Y 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="22" /> -
13                 <el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 1" :max="23" /> 小时
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="22" /> 小时开始,每
21                 <el-input-number v-model='average02' :min="1" :max="23 - 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 24" :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: 0,
42             cycle02: 1,
43             average01: 0,
44             average02: 1,
45             checkboxList: [],
46             checkNum: this.$options.propsData.check
47         }
48     },
49     name: 'crontab-hour',
50     props: ['check', 'cron'],
51     methods: {
52         // 单选按钮值变化时
53         radioChange() {
54             if (this.cron.min === '*') {
55                 this.$emit('update', 'min', '0', 'hour');
56             }
57             if (this.cron.second === '*') {
58                 this.$emit('update', 'second', '0', 'hour');
59             }
60             switch (this.radioValue) {
61                 case 1:
62                     this.$emit('update', 'hour', '*')
63                     break;
64                 case 2:
65                     this.$emit('update', 'hour', this.cycleTotal);
66                     break;
67                 case 3:
68                     this.$emit('update', 'hour', this.averageTotal);
69                     break;
70                 case 4:
71                     this.$emit('update', 'hour', this.checkboxString);
72                     break;
73             }
74         },
75         // 周期两个值变化时
76         cycleChange() {
77             if (this.radioValue == '2') {
78                 this.$emit('update', 'hour', this.cycleTotal);
79             }
80         },
81         // 平均两个值变化时
82         averageChange() {
83             if (this.radioValue == '3') {
84                 this.$emit('update', 'hour', this.averageTotal);
85             }
86         },
87         // checkbox值变化时
88         checkboxChange() {
89             if (this.radioValue == '4') {
90                 this.$emit('update', 'hour', this.checkboxString);
91             }
92         }
93     },
94     watch: {
95         'radioValue': 'radioChange',
96         'cycleTotal': 'cycleChange',
97         'averageTotal': 'averageChange',
98         'checkboxString': 'checkboxChange'
99     },
100     computed: {
101         // 计算两个周期值
102         cycleTotal: function () {
103             const cycle01 = this.checkNum(this.cycle01, 0, 22)
104             const cycle02 = this.checkNum(this.cycle02, cycle01 ? cycle01 + 1 : 1, 23)
105             return cycle01 + '-' + cycle02;
106         },
107         // 计算平均用到的值
108         averageTotal: function () {
109             const average01 = this.checkNum(this.average01, 0, 22)
110             const average02 = this.checkNum(this.average02, 1, 23 - average01 || 0)
111             return average01 + '/' + average02;
112         },
113         // 计算勾选的checkbox值合集
114         checkboxString: function () {
115             let str = this.checkboxList.join();
116             return str == '' ? '*' : str;
117         }
118     }
119 }
120 </script>