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