week.vue 4.2 KB

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