Index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="cip-cron__container">
  3. <div class="cip-cron">
  4. <ul class="cip-cron__tabs">
  5. <li
  6. class="cip-cron__tab"
  7. v-for="item in state.text.tabs"
  8. :key="item"
  9. :class="{ 'active': state.activeComponent === item.value }"
  10. @click="onHandleTab(item.value)"
  11. >
  12. {{ item.name }}
  13. </li>
  14. </ul>
  15. <keep-alive>
  16. <component
  17. class="cip-cron__content"
  18. :size="size"
  19. :text="state.text"
  20. :is="state.activeComponent"
  21. @postResult="getResult"
  22. ></component>
  23. </keep-alive>
  24. </div>
  25. <express-field
  26. v-if="showField"
  27. :text="state.text"
  28. :cron="state.cron"
  29. ></express-field>
  30. <div class="cip-cron__express" v-if="showCron">
  31. <span class="cip-cron__express__name">Cron表达式 </span>
  32. <span class="cip-cron__express__value">{{ state.cron }}</span>
  33. </div>
  34. <div class="cip-cron__button">
  35. <el-button @click="handleChange" type="primary" size="small">
  36. {{ state.text.Save }}
  37. </el-button>
  38. </div>
  39. <slot name="append"></slot>
  40. </div>
  41. </template>
  42. <script>
  43. import { config } from './config'
  44. import second from './children/second.vue'
  45. import minute from './children/minute.vue'
  46. import hour from './children/hour.vue'
  47. import day from './children/day.vue'
  48. import month from './children/month.vue'
  49. import year from './children/year.vue'
  50. import week from './children/week.vue'
  51. import expressField from './children/express-field.vue'
  52. import { reactive, computed, defineComponent, watch } from 'vue'
  53. import { generateProps, generateEmits } from '../helper/component-util'
  54. import { componentScheme } from './component.scheme'
  55. import {
  56. ElSelect,
  57. ElOption,
  58. ElInputNumber,
  59. ElRadioGroup,
  60. ElRadio,
  61. ElButton
  62. } from 'element-plus'
  63. export default defineComponent({
  64. name: 'cip-cron',
  65. components: {
  66. ElSelect,
  67. ElOption,
  68. ElInputNumber,
  69. ElRadioGroup,
  70. ElRadio,
  71. ElButton,
  72. expressField,
  73. second,
  74. minute,
  75. hour,
  76. day,
  77. month,
  78. year,
  79. week
  80. },
  81. props: generateProps(componentScheme),
  82. emits: generateEmits(componentScheme),
  83. setup (props, { emit }) {
  84. const state = reactive({
  85. text: computed(() => config),
  86. activeComponent: 'second',
  87. secondsText: '',
  88. minutesText: '',
  89. hoursText: '',
  90. daysText: '',
  91. weeksText: '',
  92. monthsText: '',
  93. yearsText: '',
  94. cron: computed(() => {
  95. return `${state.secondsText || '*'} ${state.minutesText || '*'} ${state.hoursText || '*'
  96. } ${state.daysText || '*'} ${state.monthsText || '*'} ${state.weeksText || '?'
  97. } ${state.yearsText || ''}`
  98. })
  99. })
  100. const getResult = ({ textData, type }) => {
  101. state[type] = textData
  102. }
  103. const handleChange = () => {
  104. if (typeof state.cron !== 'string') return false
  105. emit('postChange', state.cron)
  106. }
  107. const onHandleTab = (index) => {
  108. state.activeComponent = index
  109. }
  110. watch(
  111. () => state.cron,
  112. (value) => {
  113. if (typeof state.cron !== 'string') return
  114. emit('update:value', value)
  115. }
  116. )
  117. return {
  118. state,
  119. getResult,
  120. handleChange,
  121. onHandleTab
  122. }
  123. }
  124. })
  125. </script>
  126. <style lang="less">
  127. @import url('./index.less');
  128. </style>