week.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <el-form size='small'>
  3. <el-form-item>
  4. <el-radio v-model='radioValue' :label="1">
  5. 周,允许的通配符[, - * ? / L #]
  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-select clearable v-model="cycle01">
  17. <el-option
  18. v-for="(item,index) of weekList"
  19. :key="index"
  20. :label="item.value"
  21. :value="item.key"
  22. :disabled="item.key === 1"
  23. >{{item.value}}</el-option>
  24. </el-select>
  25. -
  26. <el-select clearable v-model="cycle02">
  27. <el-option
  28. v-for="(item,index) of weekList"
  29. :key="index"
  30. :label="item.value"
  31. :value="item.key"
  32. :disabled="item.key < cycle01 && item.key !== 1"
  33. >{{item.value}}</el-option>
  34. </el-select>
  35. </el-radio>
  36. </el-form-item>
  37. <el-form-item>
  38. <el-radio v-model='radioValue' :label="4">
  39. <el-input-number v-model='average01' :min="1" :max="4" /> 周的星期
  40. <el-select clearable v-model="average02">
  41. <el-option v-for="(item,index) of weekList" :key="index" :label="item.value" :value="item.key">{{item.value}}</el-option>
  42. </el-select>
  43. </el-radio>
  44. </el-form-item>
  45. <el-form-item>
  46. <el-radio v-model='radioValue' :label="5">
  47. 本月最后一个星期
  48. <el-select clearable v-model="weekday">
  49. <el-option v-for="(item,index) of weekList" :key="index" :label="item.value" :value="item.key">{{item.value}}</el-option>
  50. </el-select>
  51. </el-radio>
  52. </el-form-item>
  53. <el-form-item>
  54. <el-radio v-model='radioValue' :label="6">
  55. 指定
  56. <el-select clearable v-model="checkboxList" placeholder="可多选" multiple style="width:100%">
  57. <el-option v-for="(item,index) of weekList" :key="index" :label="item.value" :value="item.key">{{item.value}}</el-option>
  58. </el-select>
  59. </el-radio>
  60. </el-form-item>
  61. </el-form>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. radioValue: 2,
  68. weekday: 2,
  69. cycle01: 2,
  70. cycle02: 3,
  71. average01: 1,
  72. average02: 2,
  73. checkboxList: [],
  74. weekList: [
  75. {
  76. key: 2,
  77. value: '星期一'
  78. },
  79. {
  80. key: 3,
  81. value: '星期二'
  82. },
  83. {
  84. key: 4,
  85. value: '星期三'
  86. },
  87. {
  88. key: 5,
  89. value: '星期四'
  90. },
  91. {
  92. key: 6,
  93. value: '星期五'
  94. },
  95. {
  96. key: 7,
  97. value: '星期六'
  98. },
  99. {
  100. key: 1,
  101. value: '星期日'
  102. }
  103. ],
  104. checkNum: this.$options.propsData.check
  105. }
  106. },
  107. name: 'crontab-week',
  108. props: ['check', 'cron'],
  109. methods: {
  110. // 单选按钮值变化时
  111. radioChange() {
  112. if (this.radioValue !== 2 && this.cron.day !== '?') {
  113. this.$emit('update', 'day', '?', 'week');
  114. }
  115. switch (this.radioValue) {
  116. case 1:
  117. this.$emit('update', 'week', '*');
  118. break;
  119. case 2:
  120. this.$emit('update', 'week', '?');
  121. break;
  122. case 3:
  123. this.$emit('update', 'week', this.cycleTotal);
  124. break;
  125. case 4:
  126. this.$emit('update', 'week', this.averageTotal);
  127. break;
  128. case 5:
  129. this.$emit('update', 'week', this.weekdayCheck + 'L');
  130. break;
  131. case 6:
  132. this.$emit('update', 'week', this.checkboxString);
  133. break;
  134. }
  135. },
  136. // 周期两个值变化时
  137. cycleChange() {
  138. if (this.radioValue == '3') {
  139. this.$emit('update', 'week', this.cycleTotal);
  140. }
  141. },
  142. // 平均两个值变化时
  143. averageChange() {
  144. if (this.radioValue == '4') {
  145. this.$emit('update', 'week', this.averageTotal);
  146. }
  147. },
  148. // 最近工作日值变化时
  149. weekdayChange() {
  150. if (this.radioValue == '5') {
  151. this.$emit('update', 'week', this.weekday + 'L');
  152. }
  153. },
  154. // checkbox值变化时
  155. checkboxChange() {
  156. if (this.radioValue == '6') {
  157. this.$emit('update', 'week', this.checkboxString);
  158. }
  159. },
  160. },
  161. watch: {
  162. 'radioValue': 'radioChange',
  163. 'cycleTotal': 'cycleChange',
  164. 'averageTotal': 'averageChange',
  165. 'weekdayCheck': 'weekdayChange',
  166. 'checkboxString': 'checkboxChange',
  167. },
  168. computed: {
  169. // 计算两个周期值
  170. cycleTotal: function () {
  171. this.cycle01 = this.checkNum(this.cycle01, 1, 7)
  172. this.cycle02 = this.checkNum(this.cycle02, 1, 7)
  173. return this.cycle01 + '-' + this.cycle02;
  174. },
  175. // 计算平均用到的值
  176. averageTotal: function () {
  177. this.average01 = this.checkNum(this.average01, 1, 4)
  178. this.average02 = this.checkNum(this.average02, 1, 7)
  179. return this.average02 + '#' + this.average01;
  180. },
  181. // 最近的工作日(格式)
  182. weekdayCheck: function () {
  183. this.weekday = this.checkNum(this.weekday, 1, 7)
  184. return this.weekday;
  185. },
  186. // 计算勾选的checkbox值合集
  187. checkboxString: function () {
  188. let str = this.checkboxList.join();
  189. return str == '' ? '*' : str;
  190. }
  191. }
  192. }
  193. </script>