month.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <el-radio-group v-model="state.month.cronEvery" class="el-radio-flex">
  3. <el-radio :label="1">{{ text.Month.every }}</el-radio>
  4. <el-radio :label="5">{{ text.Month.noTouch }}</el-radio>
  5. <el-radio :label="2">
  6. {{ text.Month.interval[0] }}
  7. <el-input-number
  8. :size="size"
  9. type="number"
  10. v-model="state.month.incrementIncrement"
  11. :min="0"
  12. :max="12"
  13. />
  14. {{ text.Month.interval[1] }}
  15. <el-input-number
  16. :size="size"
  17. type="number"
  18. v-model="state.month.incrementStart"
  19. :min="0"
  20. :max="12"
  21. />
  22. </el-radio>
  23. <el-radio :label="3">
  24. {{ text.Month.cycle[0] }}
  25. <el-input-number
  26. :size="size"
  27. type="number"
  28. v-model="state.month.rangeStart"
  29. :min="1"
  30. :max="12"
  31. />
  32. {{ text.Month.cycle[1] }}
  33. <el-input-number
  34. :size="size"
  35. type="number"
  36. v-model="state.month.rangeEnd"
  37. :min="1"
  38. :max="12"
  39. />
  40. </el-radio>
  41. <el-radio :label="4">
  42. {{ text.Month.specific }}
  43. <el-select multiple v-model="state.month.specificSpecific" :size="size">
  44. <el-option v-for="(val, index) in 12" :key="index" :value="val">{{
  45. val
  46. }}</el-option>
  47. </el-select>
  48. </el-radio>
  49. </el-radio-group>
  50. </template>
  51. <script>
  52. import { reactive, computed, defineComponent, watch } from 'vue'
  53. import {
  54. ElSelect,
  55. ElOption,
  56. ElInputNumber,
  57. ElRadioGroup,
  58. ElRadio
  59. } from 'element-plus'
  60. export default defineComponent({
  61. name: 'month',
  62. components: {
  63. ElSelect,
  64. ElOption,
  65. ElInputNumber,
  66. ElRadioGroup,
  67. ElRadio
  68. },
  69. props: {
  70. text: {},
  71. size: {
  72. type: String,
  73. default: 'small'
  74. }
  75. },
  76. setup(props, { emit }) {
  77. const dealData = () => {
  78. let months = ''
  79. state.month.specificSpecific.map((val) => {
  80. months += val + ','
  81. })
  82. months = months.slice(0, -1)
  83. return months
  84. }
  85. const state = reactive({
  86. month: {
  87. cronEvery: 1,
  88. incrementStart: 3,
  89. incrementIncrement: 5,
  90. rangeStart: 1,
  91. rangeEnd: 1,
  92. specificSpecific: []
  93. },
  94. monthsText: computed(() => {
  95. const cronEvery = state.month.cronEvery
  96. const monthsObj = {
  97. 1: '*',
  98. 2: state.month.incrementStart + '/' + state.month.incrementIncrement,
  99. 3: state.month.rangeStart + '-' + state.month.rangeEnd,
  100. 4: dealData(),
  101. 5: '?'
  102. }
  103. return monthsObj[cronEvery]
  104. })
  105. })
  106. watch(
  107. () => state.monthsText,
  108. (v) => {
  109. const result = {
  110. textData: v,
  111. type: 'monthsText'
  112. }
  113. emit('postResult', result)
  114. },
  115. { immediate: true, deep: true }
  116. )
  117. return {
  118. state
  119. }
  120. }
  121. })
  122. </script>