华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.0 KiB

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