min.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <el-form size="small">
  3. <el-form-item>
  4. <el-radio v-model='radioValue' :label="1">
  5. 分钟,允许的通配符[, - * /]
  6. </el-radio>
  7. </el-form-item>
  8. <el-form-item>
  9. <el-radio v-model='radioValue' :label="2">
  10. 周期从
  11. <el-input-number v-model='cycle01' :max="58" :min="0"/>
  12. -
  13. <el-input-number v-model='cycle02' :max="59" :min="cycle01 ? cycle01 + 1 : 1"/>
  14. 分钟
  15. </el-radio>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-radio v-model='radioValue' :label="3">
  19. <el-input-number v-model='average01' :max="58" :min="0"/>
  20. 分钟开始,每
  21. <el-input-number v-model='average02' :max="59 - average01 || 0" :min="1"/>
  22. 分钟执行一次
  23. </el-radio>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-radio v-model='radioValue' :label="4">
  27. 指定
  28. <el-select v-model="checkboxList" clearable multiple placeholder="可多选" style="width:100%">
  29. <el-option v-for="item in 60" :key="item" :value="item-1">{{ item - 1 }}</el-option>
  30. </el-select>
  31. </el-radio>
  32. </el-form-item>
  33. </el-form>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. radioValue: 1,
  40. cycle01: 1,
  41. cycle02: 2,
  42. average01: 0,
  43. average02: 1,
  44. checkboxList: [],
  45. checkNum: this.$options.propsData.check
  46. }
  47. },
  48. name: 'crontab-min',
  49. props: ['check', 'cron'],
  50. methods: {
  51. // 单选按钮值变化时
  52. radioChange() {
  53. switch (this.radioValue) {
  54. case 1:
  55. this.$emit('update', 'min', '*', 'min');
  56. break;
  57. case 2:
  58. this.$emit('update', 'min', this.cycleTotal, 'min');
  59. break;
  60. case 3:
  61. this.$emit('update', 'min', this.averageTotal, 'min');
  62. break;
  63. case 4:
  64. this.$emit('update', 'min', this.checkboxString, 'min');
  65. break;
  66. }
  67. },
  68. // 周期两个值变化时
  69. cycleChange() {
  70. if (this.radioValue == '2') {
  71. this.$emit('update', 'min', this.cycleTotal, 'min');
  72. }
  73. },
  74. // 平均两个值变化时
  75. averageChange() {
  76. if (this.radioValue == '3') {
  77. this.$emit('update', 'min', this.averageTotal, 'min');
  78. }
  79. },
  80. // checkbox值变化时
  81. checkboxChange() {
  82. if (this.radioValue == '4') {
  83. this.$emit('update', 'min', this.checkboxString, 'min');
  84. }
  85. },
  86. },
  87. watch: {
  88. 'radioValue': 'radioChange',
  89. 'cycleTotal': 'cycleChange',
  90. 'averageTotal': 'averageChange',
  91. 'checkboxString': 'checkboxChange',
  92. },
  93. computed: {
  94. // 计算两个周期值
  95. cycleTotal: function () {
  96. const cycle01 = this.checkNum(this.cycle01, 0, 58)
  97. const cycle02 = this.checkNum(this.cycle02, cycle01 ? cycle01 + 1 : 1, 59)
  98. return cycle01 + '-' + cycle02;
  99. },
  100. // 计算平均用到的值
  101. averageTotal: function () {
  102. const average01 = this.checkNum(this.average01, 0, 58)
  103. const average02 = this.checkNum(this.average02, 1, 59 - average01 || 0)
  104. return average01 + '/' + average02;
  105. },
  106. // 计算勾选的checkbox值合集
  107. checkboxString: function () {
  108. let str = this.checkboxList.join();
  109. return str == '' ? '*' : str;
  110. }
  111. }
  112. }
  113. </script>