Newer
Older
DH_Apicture / src / components / patrolCrontab / second.vue
@zhangqy zhangqy on 29 Nov 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="58" /> -
  13. <el-input-number v-model='cycle02' :min="cycle01 + 1" :max="59" />
  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="58" /> 秒开始,每
  20. <el-input-number v-model='average02' :min="1" :max="59 - 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 60" :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, 58)
  65. cycle02.value = props.check(cycle02.value, cycle01.value + 1, 59)
  66. return cycle01.value + '-' + cycle02.value
  67. })
  68. const averageTotal = computed(() => {
  69. average01.value = props.check(average01.value, 0, 58)
  70. average02.value = props.check(average02.value, 1, 59 - average01.value)
  71. return average01.value + '/' + average02.value
  72. })
  73. const checkboxString = computed(() => {
  74. return checkboxList.value.join(',')
  75. })
  76. watch(() => props.cron.second, 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. // 单选按钮值变化时
  97. function onRadioChange() {
  98. switch (radioValue.value) {
  99. case 1:
  100. emit('update', 'second', '*', 'second')
  101. break
  102. case 2:
  103. emit('update', 'second', cycleTotal.value, 'second')
  104. break
  105. case 3:
  106. emit('update', 'second', averageTotal.value, 'second')
  107. break
  108. case 4:
  109. if (checkboxList.value.length === 0) {
  110. checkboxList.value.push(checkCopy.value[0])
  111. } else {
  112. checkCopy.value = checkboxList.value
  113. }
  114. emit('update', 'second', checkboxString.value, 'second')
  115. break
  116. }
  117. }
  118. </script>
  119.  
  120. <style lang="scss" scoped>
  121. .el-input-number--small, .el-select, .el-select--small {
  122. margin: 0 0.2rem;
  123. }
  124. .el-select, .el-select--small {
  125. width: 18.8rem;
  126. }
  127. </style>