day.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <el-form size="small">
  3. <el-form-item>
  4. <el-radio v-model='radioValue' :label="1">
  5. 日,允许的通配符[, - * / L M]
  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="0" :max="31" /> -
  17. <el-input-number v-model='cycle02' :min="0" :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="0" :max="31" /> 号开始,每
  23. <el-input-number v-model='average02' :min="0" :max="31" /> 日执行一次
  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="0" :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 === 1) {
  68. this.$emit('update', 'day', '*', 'day');
  69. this.$emit('update', 'week', '?', 'day');
  70. this.$emit('update', 'month', '*', 'day');
  71. } else {
  72. if (this.cron.hour === '*') {
  73. this.$emit('update', 'hour', '0', 'day');
  74. }
  75. if (this.cron.min === '*') {
  76. this.$emit('update', 'min', '0', 'day');
  77. }
  78. if (this.cron.second === '*') {
  79. this.$emit('update', 'second', '0', 'day');
  80. }
  81. }
  82. switch (this.radioValue) {
  83. case 2:
  84. this.$emit('update', 'day', '?');
  85. break;
  86. case 3:
  87. this.$emit('update', 'day', this.cycle01 + '-' + this.cycle02);
  88. break;
  89. case 4:
  90. this.$emit('update', 'day', this.average01 + '/' + this.average02);
  91. break;
  92. case 5:
  93. this.$emit('update', 'day', this.workday + 'W');
  94. break;
  95. case 6:
  96. this.$emit('update', 'day', 'L');
  97. break;
  98. case 7:
  99. this.$emit('update', 'day', this.checkboxString);
  100. break;
  101. }
  102. ('day rachange end');
  103. },
  104. // 周期两个值变化时
  105. cycleChange() {
  106. if (this.radioValue == '3') {
  107. this.$emit('update', 'day', this.cycleTotal);
  108. }
  109. },
  110. // 平均两个值变化时
  111. averageChange() {
  112. if (this.radioValue == '4') {
  113. this.$emit('update', 'day', this.averageTotal);
  114. }
  115. },
  116. // 最近工作日值变化时
  117. workdayChange() {
  118. if (this.radioValue == '5') {
  119. this.$emit('update', 'day', this.workday + 'W');
  120. }
  121. },
  122. // checkbox值变化时
  123. checkboxChange() {
  124. if (this.radioValue == '7') {
  125. this.$emit('update', 'day', this.checkboxString);
  126. }
  127. },
  128. // 父组件传递的week发生变化触发
  129. weekChange() {
  130. //判断week值与day不能同时为“?”
  131. if (this.cron.week == '?' && this.radioValue == '2') {
  132. this.radioValue = '1';
  133. } else if (this.cron.week !== '?' && this.radioValue != '2') {
  134. this.radioValue = '2';
  135. }
  136. },
  137. },
  138. watch: {
  139. "radioValue": "radioChange",
  140. 'cycleTotal': 'cycleChange',
  141. 'averageTotal': 'averageChange',
  142. 'workdayCheck': 'workdayChange',
  143. 'checkboxString': 'checkboxChange',
  144. },
  145. computed: {
  146. // 计算两个周期值
  147. cycleTotal: function () {
  148. this.cycle01 = this.checkNum(this.cycle01, 1, 31)
  149. this.cycle02 = this.checkNum(this.cycle02, 1, 31)
  150. return this.cycle01 + '-' + this.cycle02;
  151. },
  152. // 计算平均用到的值
  153. averageTotal: function () {
  154. this.average01 = this.checkNum(this.average01, 1, 31)
  155. this.average02 = this.checkNum(this.average02, 1, 31)
  156. return this.average01 + '/' + this.average02;
  157. },
  158. // 计算工作日格式
  159. workdayCheck: function () {
  160. this.workday = this.checkNum(this.workday, 1, 31)
  161. return this.workday;
  162. },
  163. // 计算勾选的checkbox值合集
  164. checkboxString: function () {
  165. let str = this.checkboxList.join();
  166. return str == '' ? '*' : str;
  167. }
  168. }
  169. }
  170. </script>