Newer
Older
urbanLifeline_YanAn / src / components / Crontab / hour.vue
@zhangqy zhangqy on 3 Oct 3 KB first commit
  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.  
  9. <el-form-item>
  10. <el-radio v-model='radioValue' :label="2">
  11. 周期从
  12. <el-input-number v-model='cycle01' :min="0" :max="22" /> -
  13. <el-input-number v-model='cycle02' :min="cycle01 + 1" :max="23" />
  14. </el-radio>
  15. </el-form-item>
  16.  
  17. <el-form-item>
  18. <el-radio v-model='radioValue' :label="3">
  19. <el-input-number v-model='average01' :min="0" :max="22" /> 时开始,每
  20. <el-input-number v-model='average02' :min="1" :max="23 - average01" /> 小时执行一次
  21. </el-radio>
  22. </el-form-item>
  23.  
  24. <el-form-item>
  25. <el-radio v-model='radioValue' :label="4">
  26. 指定
  27. <el-select clearable v-model="checkboxList" placeholder="可多选" multiple :multiple-limit="10">
  28. <el-option v-for="item in 24" :key="item" :label="item - 1" :value="item - 1" />
  29. </el-select>
  30. </el-radio>
  31. </el-form-item>
  32. </el-form>
  33. </template>
  34.  
  35. <script setup>
  36. const emit = defineEmits(['update'])
  37. const props = defineProps({
  38. cron: {
  39. type: Object,
  40. default: {
  41. second: "*",
  42. min: "*",
  43. hour: "*",
  44. day: "*",
  45. month: "*",
  46. week: "?",
  47. year: "",
  48. }
  49. },
  50. check: {
  51. type: Function,
  52. default: () => {
  53. }
  54. }
  55. })
  56. const radioValue = ref(1)
  57. const cycle01 = ref(0)
  58. const cycle02 = ref(1)
  59. const average01 = ref(0)
  60. const average02 = ref(1)
  61. const checkboxList = ref([])
  62. const checkCopy = ref([0])
  63. const cycleTotal = computed(() => {
  64. cycle01.value = props.check(cycle01.value, 0, 22)
  65. cycle02.value = props.check(cycle02.value, cycle01.value + 1, 23)
  66. return cycle01.value + '-' + cycle02.value
  67. })
  68. const averageTotal = computed(() => {
  69. average01.value = props.check(average01.value, 0, 22)
  70. average02.value = props.check(average02.value, 1, 23 - average01.value)
  71. return average01.value + '/' + average02.value
  72. })
  73. const checkboxString = computed(() => {
  74. return checkboxList.value.join(',')
  75. })
  76. watch(() => props.cron.hour, value => changeRadioValue(value))
  77. watch([radioValue, cycleTotal, averageTotal, checkboxString], () => onRadioChange())
  78. function changeRadioValue(value) {
  79. if (value === '*') {
  80. radioValue.value = 1
  81. } else if (value.indexOf('-') > -1) {
  82. const indexArr = value.split('-')
  83. cycle01.value = Number(indexArr[0])
  84. cycle02.value = Number(indexArr[1])
  85. radioValue.value = 2
  86. } else if (value.indexOf('/') > -1) {
  87. const indexArr = value.split('/')
  88. average01.value = Number(indexArr[0])
  89. average02.value = Number(indexArr[1])
  90. radioValue.value = 3
  91. } else {
  92. checkboxList.value = [...new Set(value.split(',').map(item => Number(item)))]
  93. radioValue.value = 4
  94. }
  95. }
  96. function onRadioChange() {
  97. switch (radioValue.value) {
  98. case 1:
  99. emit('update', 'hour', '*', 'hour')
  100. break
  101. case 2:
  102. emit('update', 'hour', cycleTotal.value, 'hour')
  103. break
  104. case 3:
  105. emit('update', 'hour', averageTotal.value, 'hour')
  106. break
  107. case 4:
  108. if (checkboxList.value.length === 0) {
  109. checkboxList.value.push(checkCopy.value[0])
  110. } else {
  111. checkCopy.value = checkboxList.value
  112. }
  113. emit('update', 'hour', checkboxString.value, 'hour')
  114. break
  115. }
  116. }
  117. </script>
  118.  
  119. <style lang="scss" scoped>
  120. .el-input-number--small, .el-select, .el-select--small {
  121. margin: 0 0.2rem;
  122. }
  123. .el-select, .el-select--small {
  124. width: 18.8rem;
  125. }
  126. </style>