day.vue 4.0 KB

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