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