week.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 !== 2 && this.cron.day !== '?') {
  63. this.$emit('update', 'day', '?', 'week');
  64. }
  65. switch (this.radioValue) {
  66. case 1:
  67. this.$emit('update', 'week', '*');
  68. break;
  69. case 2:
  70. this.$emit('update', 'week', '?');
  71. break;
  72. case 3:
  73. this.$emit('update', 'week', this.cycle01 + '-' + this.cycle02);
  74. break;
  75. case 4:
  76. this.$emit('update', 'week', this.average01 + '#' + this.average02);
  77. break;
  78. case 5:
  79. this.$emit('update', 'week', this.weekday + 'L');
  80. break;
  81. case 6:
  82. this.$emit('update', 'week', this.checkboxString);
  83. break;
  84. }
  85. },
  86. // 周期两个值变化时
  87. cycleChange() {
  88. if (this.radioValue == '3') {
  89. this.$emit('update', 'week', this.cycleTotal);
  90. }
  91. },
  92. // 平均两个值变化时
  93. averageChange() {
  94. if (this.radioValue == '4') {
  95. this.$emit('update', 'week', this.averageTotal);
  96. }
  97. },
  98. // 最近工作日值变化时
  99. weekdayChange() {
  100. if (this.radioValue == '5') {
  101. this.$emit('update', 'week', this.weekday + 'L');
  102. }
  103. },
  104. // checkbox值变化时
  105. checkboxChange() {
  106. if (this.radioValue == '6') {
  107. this.$emit('update', 'week', this.checkboxString);
  108. }
  109. },
  110. },
  111. watch: {
  112. "radioValue": "radioChange",
  113. 'cycleTotal': 'cycleChange',
  114. 'averageTotal': 'averageChange',
  115. 'weekdayCheck': 'weekdayChange',
  116. 'checkboxString': 'checkboxChange',
  117. },
  118. computed: {
  119. // 计算两个周期值
  120. cycleTotal: function () {
  121. this.cycle01 = this.checkNum(this.cycle01, 1, 7)
  122. this.cycle02 = this.checkNum(this.cycle02, 1, 7)
  123. return this.cycle01 + '-' + this.cycle02;
  124. },
  125. // 计算平均用到的值
  126. averageTotal: function () {
  127. this.average01 = this.checkNum(this.average01, 1, 4)
  128. this.average02 = this.checkNum(this.average02, 1, 7)
  129. return this.average01 + '#' + this.average02;
  130. },
  131. // 最近的工作日(格式)
  132. weekdayCheck: function () {
  133. this.weekday = this.checkNum(this.weekday, 1, 7)
  134. return this.weekday;
  135. },
  136. // 计算勾选的checkbox值合集
  137. checkboxString: function () {
  138. let str = this.checkboxList.join();
  139. return str == '' ? '*' : str;
  140. }
  141. }
  142. }
  143. </script>