day.vue 4.4 KB

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