yyt
2024-06-26 0cceb649e1dc443c2a91d26d81eacb0867c96db3
提交 | 用户 | 时间
0cceb6 1 <template>
Y 2     <el-form size="small">
3         <el-form-item>
4             <el-radio v-model='radioValue' :label="1">
5                 日,允许的通配符[, - * ? / L W]
6             </el-radio>
7         </el-form-item>
8
9         <el-form-item>
10             <el-radio v-model='radioValue' :label="2">
11                 不指定
12             </el-radio>
13         </el-form-item>
14
15         <el-form-item>
16             <el-radio v-model='radioValue' :label="3">
17                 周期从
18                 <el-input-number v-model='cycle01' :min="1" :max="30" /> -
19                 <el-input-number v-model='cycle02' :min="cycle01 ? cycle01 + 1 : 2" :max="31" /> 日
20             </el-radio>
21         </el-form-item>
22
23         <el-form-item>
24             <el-radio v-model='radioValue' :label="4">
25                 从
26                 <el-input-number v-model='average01' :min="1" :max="30" /> 号开始,每
27                 <el-input-number v-model='average02' :min="1" :max="31 - average01 || 1" /> 日执行一次
28             </el-radio>
29         </el-form-item>
30
31         <el-form-item>
32             <el-radio v-model='radioValue' :label="5">
33                 每月
34                 <el-input-number v-model='workday' :min="1" :max="31" /> 号最近的那个工作日
35             </el-radio>
36         </el-form-item>
37
38         <el-form-item>
39             <el-radio v-model='radioValue' :label="6">
40                 本月最后一天
41             </el-radio>
42         </el-form-item>
43
44         <el-form-item>
45             <el-radio v-model='radioValue' :label="7">
46                 指定
47                 <el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%">
48                     <el-option v-for="item in 31" :key="item" :value="item">{{item}}</el-option>
49                 </el-select>
50             </el-radio>
51         </el-form-item>
52     </el-form>
53 </template>
54
55 <script>
56 export default {
57     data() {
58         return {
59             radioValue: 1,
60             workday: 1,
61             cycle01: 1,
62             cycle02: 2,
63             average01: 1,
64             average02: 1,
65             checkboxList: [],
66             checkNum: this.$options.propsData.check
67         }
68     },
69     name: 'crontab-day',
70     props: ['check', 'cron'],
71     methods: {
72         // 单选按钮值变化时
73         radioChange() {
74             ('day rachange');
75             if (this.radioValue !== 2 && this.cron.week !== '?') {
76                 this.$emit('update', 'week', '?', 'day')
77             }
78
79             switch (this.radioValue) {
80                 case 1:
81                     this.$emit('update', 'day', '*');
82                     break;
83                 case 2:
84                     this.$emit('update', 'day', '?');
85                     break;
86                 case 3:
87                     this.$emit('update', 'day', this.cycleTotal);
88                     break;
89                 case 4:
90                     this.$emit('update', 'day', this.averageTotal);
91                     break;
92                 case 5:
93                     this.$emit('update', 'day', this.workday + 'W');
94                     break;
95                 case 6:
96                     this.$emit('update', 'day', 'L');
97                     break;
98                 case 7:
99                     this.$emit('update', 'day', this.checkboxString);
100                     break;
101             }
102             ('day rachange end');
103         },
104         // 周期两个值变化时
105         cycleChange() {
106             if (this.radioValue == '3') {
107                 this.$emit('update', 'day', this.cycleTotal);
108             }
109         },
110         // 平均两个值变化时
111         averageChange() {
112             if (this.radioValue == '4') {
113                 this.$emit('update', 'day', this.averageTotal);
114             }
115         },
116         // 最近工作日值变化时
117         workdayChange() {
118             if (this.radioValue == '5') {
119                 this.$emit('update', 'day', this.workdayCheck + 'W');
120             }
121         },
122         // checkbox值变化时
123         checkboxChange() {
124             if (this.radioValue == '7') {
125                 this.$emit('update', 'day', this.checkboxString);
126             }
127         }
128     },
129     watch: {
130         'radioValue': 'radioChange',
131         'cycleTotal': 'cycleChange',
132         'averageTotal': 'averageChange',
133         'workdayCheck': 'workdayChange',
134         'checkboxString': 'checkboxChange',
135     },
136     computed: {
137         // 计算两个周期值
138         cycleTotal: function () {
139             const cycle01 = this.checkNum(this.cycle01, 1, 30)
140             const cycle02 = this.checkNum(this.cycle02, cycle01 ? cycle01 + 1 : 2, 31, 31)
141             return cycle01 + '-' + cycle02;
142         },
143         // 计算平均用到的值
144         averageTotal: function () {
145             const average01 = this.checkNum(this.average01, 1, 30)
146             const average02 = this.checkNum(this.average02, 1, 31 - average01 || 0)
147             return average01 + '/' + average02;
148         },
149         // 计算工作日格式
150         workdayCheck: function () {
151             const workday = this.checkNum(this.workday, 1, 31)
152             return workday;
153         },
154         // 计算勾选的checkbox值合集
155         checkboxString: function () {
156             let str = this.checkboxList.join();
157             return str == '' ? '*' : str;
158         }
159     }
160 }
161 </script>