day.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 !== 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.cycle01 + '-' + this.cycle02);
  79. break;
  80. case 4:
  81. this.$emit('update', 'day', this.average01 + '/' + this.average02);
  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.workday + 'W');
  111. }
  112. },
  113. // checkbox值变化时
  114. checkboxChange() {
  115. if (this.radioValue == '7') {
  116. this.$emit('update', 'day', this.checkboxString);
  117. }
  118. },
  119. // 父组件传递的week发生变化触发
  120. weekChange() {
  121. //判断week值与day不能同时为“?”
  122. if (this.cron.week == '?' && this.radioValue == '2') {
  123. this.radioValue = '1';
  124. } else if (this.cron.week !== '?' && this.radioValue != '2') {
  125. this.radioValue = '2';
  126. }
  127. },
  128. },
  129. watch: {
  130. "radioValue": "radioChange",
  131. 'cycleTotal': 'cycleChange',
  132. 'averageTotal': 'averageChange',
  133. 'workdayCheck': 'workdayChange',
  134. 'checkboxString': 'checkboxChange',
  135. },
  136. computed: {
  137. // 计算两个周期值
  138. cycleTotal: function () {
  139. this.cycle01 = this.checkNum(this.cycle01, 1, 31)
  140. this.cycle02 = this.checkNum(this.cycle02, 1, 31)
  141. return this.cycle01 + '-' + this.cycle02;
  142. },
  143. // 计算平均用到的值
  144. averageTotal: function () {
  145. this.average01 = this.checkNum(this.average01, 1, 31)
  146. this.average02 = this.checkNum(this.average02, 1, 31)
  147. return this.average01 + '/' + this.average02;
  148. },
  149. // 计算工作日格式
  150. workdayCheck: function () {
  151. this.workday = this.checkNum(this.workday, 1, 31)
  152. return this.workday;
  153. },
  154. // 计算勾选的checkbox值合集
  155. checkboxString: function () {
  156. let str = this.checkboxList.join();
  157. return str == '' ? '*' : str;
  158. }
  159. }
  160. }
  161. </script>