Crontab.vue 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. <!--
  2. * @Descripttion: cron规则生成器
  3. * @version: 1.0
  4. * @Author: sakuya
  5. * @Date: 2021年12月29日15:23:54
  6. * @LastEditors:
  7. * @LastEditTime:
  8. -->
  9. <script setup lang="ts">
  10. import {
  11. ElInput,
  12. ElInputNumber,
  13. ElDropdown,
  14. ElDropdownMenu,
  15. ElDropdownItem,
  16. ElDialog,
  17. ElTabs,
  18. ElTabPane,
  19. ElSelect,
  20. ElOption,
  21. ElForm,
  22. ElFormItem,
  23. ElRadioGroup,
  24. ElRadioButton,
  25. ElMessage
  26. } from 'element-plus'
  27. import { ref, computed, onMounted, reactive, watch, PropType, defineEmits } from 'vue'
  28. interface shortcutsType {
  29. text: string
  30. value: string
  31. }
  32. const props = defineProps({
  33. modelValue: { type: String, default: '* * * * * ?' },
  34. shortcuts: { type: Array as PropType<shortcutsType[]>, default: () => [] }
  35. })
  36. const defaultValue = ref('')
  37. const dialogVisible = ref(false)
  38. const getYear = () => {
  39. let v: number[] = []
  40. let y = new Date().getFullYear()
  41. for (let i = 0; i < 11; i++) {
  42. v.push(y + i)
  43. }
  44. return v
  45. }
  46. const cronValue = reactive({
  47. second: {
  48. type: '0',
  49. range: {
  50. start: 1,
  51. end: 2
  52. },
  53. loop: {
  54. start: 0,
  55. end: 1
  56. },
  57. appoint: [] as string[]
  58. },
  59. minute: {
  60. type: '0',
  61. range: {
  62. start: 1,
  63. end: 2
  64. },
  65. loop: {
  66. start: 0,
  67. end: 1
  68. },
  69. appoint: [] as string[]
  70. },
  71. hour: {
  72. type: '0',
  73. range: {
  74. start: 1,
  75. end: 2
  76. },
  77. loop: {
  78. start: 0,
  79. end: 1
  80. },
  81. appoint: [] as string[]
  82. },
  83. day: {
  84. type: '0',
  85. range: {
  86. start: 1,
  87. end: 2
  88. },
  89. loop: {
  90. start: 1,
  91. end: 1
  92. },
  93. appoint: [] as string[]
  94. },
  95. month: {
  96. type: '0',
  97. range: {
  98. start: 1,
  99. end: 2
  100. },
  101. loop: {
  102. start: 1,
  103. end: 1
  104. },
  105. appoint: [] as string[]
  106. },
  107. week: {
  108. type: '5',
  109. range: {
  110. start: '2',
  111. end: '3'
  112. },
  113. loop: {
  114. start: 0,
  115. end: '2'
  116. },
  117. last: '2',
  118. appoint: [] as string[]
  119. },
  120. year: {
  121. type: '-1',
  122. range: {
  123. start: getYear()[0],
  124. end: getYear()[1]
  125. },
  126. loop: {
  127. start: getYear()[0],
  128. end: 1
  129. },
  130. appoint: [] as string[]
  131. }
  132. })
  133. const data = reactive({
  134. second: ['0', '5', '15', '20', '25', '30', '35', '40', '45', '50', '55', '59'],
  135. minute: ['0', '5', '15', '20', '25', '30', '35', '40', '45', '50', '55', '59'],
  136. hour: [
  137. '0',
  138. '1',
  139. '2',
  140. '3',
  141. '4',
  142. '5',
  143. '6',
  144. '7',
  145. '8',
  146. '9',
  147. '10',
  148. '11',
  149. '12',
  150. '13',
  151. '14',
  152. '15',
  153. '16',
  154. '17',
  155. '18',
  156. '19',
  157. '20',
  158. '21',
  159. '22',
  160. '23'
  161. ],
  162. day: [
  163. '1',
  164. '2',
  165. '3',
  166. '4',
  167. '5',
  168. '6',
  169. '7',
  170. '8',
  171. '9',
  172. '10',
  173. '11',
  174. '12',
  175. '13',
  176. '14',
  177. '15',
  178. '16',
  179. '17',
  180. '18',
  181. '19',
  182. '20',
  183. '21',
  184. '22',
  185. '23',
  186. '24',
  187. '25',
  188. '26',
  189. '27',
  190. '28',
  191. '29',
  192. '30',
  193. '31'
  194. ],
  195. month: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
  196. week: [
  197. {
  198. value: '1',
  199. label: '周日'
  200. },
  201. {
  202. value: '2',
  203. label: '周一'
  204. },
  205. {
  206. value: '3',
  207. label: '周二'
  208. },
  209. {
  210. value: '4',
  211. label: '周三'
  212. },
  213. {
  214. value: '5',
  215. label: '周四'
  216. },
  217. {
  218. value: '6',
  219. label: '周五'
  220. },
  221. {
  222. value: '7',
  223. label: '周六'
  224. }
  225. ],
  226. year: getYear()
  227. })
  228. const value_second = computed(() => {
  229. let v = cronValue.second
  230. if (v.type == '0') {
  231. return '*'
  232. } else if (v.type == '1') {
  233. return v.range.start + '-' + v.range.end
  234. } else if (v.type == '2') {
  235. return v.loop.start + '/' + v.loop.end
  236. } else if (v.type == '3') {
  237. return v.appoint.length > 0 ? v.appoint.join(',') : '*'
  238. } else {
  239. return '*'
  240. }
  241. })
  242. const value_minute = computed(() => {
  243. let v = cronValue.minute
  244. if (v.type == '0') {
  245. return '*'
  246. } else if (v.type == '1') {
  247. return v.range.start + '-' + v.range.end
  248. } else if (v.type == '2') {
  249. return v.loop.start + '/' + v.loop.end
  250. } else if (v.type == '3') {
  251. return v.appoint.length > 0 ? v.appoint.join(',') : '*'
  252. } else {
  253. return '*'
  254. }
  255. })
  256. const value_hour = computed(() => {
  257. let v = cronValue.hour
  258. if (v.type == '0') {
  259. return '*'
  260. } else if (v.type == '1') {
  261. return v.range.start + '-' + v.range.end
  262. } else if (v.type == '2') {
  263. return v.loop.start + '/' + v.loop.end
  264. } else if (v.type == '3') {
  265. return v.appoint.length > 0 ? v.appoint.join(',') : '*'
  266. } else {
  267. return '*'
  268. }
  269. })
  270. const value_day = computed(() => {
  271. let v = cronValue.day
  272. if (v.type == '0') {
  273. return '*'
  274. } else if (v.type == '1') {
  275. return v.range.start + '-' + v.range.end
  276. } else if (v.type == '2') {
  277. return v.loop.start + '/' + v.loop.end
  278. } else if (v.type == '3') {
  279. return v.appoint.length > 0 ? v.appoint.join(',') : '*'
  280. } else if (v.type == '4') {
  281. return 'L'
  282. } else if (v.type == '5') {
  283. return '?'
  284. } else {
  285. return '*'
  286. }
  287. })
  288. const value_month = computed(() => {
  289. let v = cronValue.month
  290. if (v.type == '0') {
  291. return '*'
  292. } else if (v.type == '1') {
  293. return v.range.start + '-' + v.range.end
  294. } else if (v.type == '2') {
  295. return v.loop.start + '/' + v.loop.end
  296. } else if (v.type == '3') {
  297. return v.appoint.length > 0 ? v.appoint.join(',') : '*'
  298. } else {
  299. return '*'
  300. }
  301. })
  302. const value_week = computed(() => {
  303. let v = cronValue.week
  304. if (v.type == '0') {
  305. return '*'
  306. } else if (v.type == '1') {
  307. return v.range.start + '-' + v.range.end
  308. } else if (v.type == '2') {
  309. return v.loop.end + '#' + v.loop.start
  310. } else if (v.type == '3') {
  311. return v.appoint.length > 0 ? v.appoint.join(',') : '*'
  312. } else if (v.type == '4') {
  313. return v.last + 'L'
  314. } else if (v.type == '5') {
  315. return '?'
  316. } else {
  317. return '*'
  318. }
  319. })
  320. const value_year = computed(() => {
  321. let v = cronValue.year
  322. if (v.type == '-1') {
  323. return ''
  324. } else if (v.type == '0') {
  325. return '*'
  326. } else if (v.type == '1') {
  327. return v.range.start + '-' + v.range.end
  328. } else if (v.type == '2') {
  329. return v.loop.start + '/' + v.loop.end
  330. } else if (v.type == '3') {
  331. return v.appoint.length > 0 ? v.appoint.join(',') : ''
  332. } else {
  333. return ''
  334. }
  335. })
  336. watch(
  337. () => cronValue.week.type,
  338. (val) => {
  339. if (val != '5') {
  340. cronValue.day.type = '5'
  341. }
  342. }
  343. )
  344. watch(
  345. () => cronValue.day.type,
  346. (val) => {
  347. if (val != '5') {
  348. cronValue.week.type = '5'
  349. }
  350. }
  351. )
  352. watch(
  353. () => props.modelValue,
  354. () => {
  355. defaultValue.value = props.modelValue
  356. }
  357. )
  358. onMounted(() => {
  359. defaultValue.value = props.modelValue
  360. })
  361. const emit = defineEmits(['update:modelValue'])
  362. const handleShortcuts = (command) => {
  363. if (command == 'custom') {
  364. open()
  365. } else {
  366. defaultValue.value = command
  367. emit('update:modelValue', defaultValue.value)
  368. }
  369. }
  370. const open = () => {
  371. set()
  372. dialogVisible.value = true
  373. }
  374. const set = () => {
  375. defaultValue.value = props.modelValue
  376. let arr = (props.modelValue || '* * * * * ?').split(' ')
  377. //简单检查
  378. if (arr.length < 6) {
  379. ElMessage.warning('cron表达式错误,已转换为默认表达式')
  380. arr = '* * * * * ?'.split(' ')
  381. }
  382. //秒
  383. if (arr[0] == '*') {
  384. cronValue.second.type = '0'
  385. } else if (arr[0].includes('-')) {
  386. cronValue.second.type = '1'
  387. cronValue.second.range.start = Number(arr[0].split('-')[0])
  388. cronValue.second.range.end = Number(arr[0].split('-')[1])
  389. } else if (arr[0].includes('/')) {
  390. cronValue.second.type = '2'
  391. cronValue.second.loop.start = Number(arr[0].split('/')[0])
  392. cronValue.second.loop.end = Number(arr[0].split('/')[1])
  393. } else {
  394. cronValue.second.type = '3'
  395. cronValue.second.appoint = arr[0].split(',')
  396. }
  397. //分
  398. if (arr[1] == '*') {
  399. cronValue.minute.type = '0'
  400. } else if (arr[1].includes('-')) {
  401. cronValue.minute.type = '1'
  402. cronValue.minute.range.start = Number(arr[1].split('-')[0])
  403. cronValue.minute.range.end = Number(arr[1].split('-')[1])
  404. } else if (arr[1].includes('/')) {
  405. cronValue.minute.type = '2'
  406. cronValue.minute.loop.start = Number(arr[1].split('/')[0])
  407. cronValue.minute.loop.end = Number(arr[1].split('/')[1])
  408. } else {
  409. cronValue.minute.type = '3'
  410. cronValue.minute.appoint = arr[1].split(',')
  411. }
  412. //小时
  413. if (arr[2] == '*') {
  414. cronValue.hour.type = '0'
  415. } else if (arr[2].includes('-')) {
  416. cronValue.hour.type = '1'
  417. cronValue.hour.range.start = Number(arr[2].split('-')[0])
  418. cronValue.hour.range.end = Number(arr[2].split('-')[1])
  419. } else if (arr[2].includes('/')) {
  420. cronValue.hour.type = '2'
  421. cronValue.hour.loop.start = Number(arr[2].split('/')[0])
  422. cronValue.hour.loop.end = Number(arr[2].split('/')[1])
  423. } else {
  424. cronValue.hour.type = '3'
  425. cronValue.hour.appoint = arr[2].split(',')
  426. }
  427. //日
  428. if (arr[3] == '*') {
  429. cronValue.day.type = '0'
  430. } else if (arr[3] == 'L') {
  431. cronValue.day.type = '4'
  432. } else if (arr[3] == '?') {
  433. cronValue.day.type = '5'
  434. } else if (arr[3].includes('-')) {
  435. cronValue.day.type = '1'
  436. cronValue.day.range.start = Number(arr[3].split('-')[0])
  437. cronValue.day.range.end = Number(arr[3].split('-')[1])
  438. } else if (arr[3].includes('/')) {
  439. cronValue.day.type = '2'
  440. cronValue.day.loop.start = Number(arr[3].split('/')[0])
  441. cronValue.day.loop.end = Number(arr[3].split('/')[1])
  442. } else {
  443. cronValue.day.type = '3'
  444. cronValue.day.appoint = arr[3].split(',')
  445. }
  446. //月
  447. if (arr[4] == '*') {
  448. cronValue.month.type = '0'
  449. } else if (arr[4].includes('-')) {
  450. cronValue.month.type = '1'
  451. cronValue.month.range.start = Number(arr[4].split('-')[0])
  452. cronValue.month.range.end = Number(arr[4].split('-')[1])
  453. } else if (arr[4].includes('/')) {
  454. cronValue.month.type = '2'
  455. cronValue.month.loop.start = Number(arr[4].split('/')[0])
  456. cronValue.month.loop.end = Number(arr[4].split('/')[1])
  457. } else {
  458. cronValue.month.type = '3'
  459. cronValue.month.appoint = arr[4].split(',')
  460. }
  461. //周
  462. if (arr[5] == '*') {
  463. cronValue.week.type = '0'
  464. } else if (arr[5] == '?') {
  465. cronValue.week.type = '5'
  466. } else if (arr[5].includes('-')) {
  467. cronValue.week.type = '1'
  468. cronValue.week.range.start = arr[5].split('-')[0]
  469. cronValue.week.range.end = arr[5].split('-')[1]
  470. } else if (arr[5].includes('#')) {
  471. cronValue.week.type = '2'
  472. cronValue.week.loop.start = Number(arr[5].split('#')[1])
  473. cronValue.week.loop.end = arr[5].split('#')[0]
  474. } else if (arr[5].includes('L')) {
  475. cronValue.week.type = '4'
  476. cronValue.week.last = arr[5].split('L')[0]
  477. } else {
  478. cronValue.week.type = '3'
  479. cronValue.week.appoint = arr[5].split(',')
  480. }
  481. //年
  482. if (!arr[6]) {
  483. cronValue.year.type = '-1'
  484. } else if (arr[6] == '*') {
  485. cronValue.year.type = '0'
  486. } else if (arr[6].includes('-')) {
  487. cronValue.year.type = '1'
  488. cronValue.year.range.start = Number(arr[6].split('-')[0])
  489. cronValue.year.range.end = Number(arr[6].split('-')[1])
  490. } else if (arr[6].includes('/')) {
  491. cronValue.year.type = '2'
  492. cronValue.year.loop.start = Number(arr[6].split('/')[1])
  493. cronValue.year.loop.end = Number(arr[6].split('/')[0])
  494. } else {
  495. cronValue.year.type = '3'
  496. cronValue.year.appoint = arr[6].split(',')
  497. }
  498. }
  499. const submit = () => {
  500. let year = value_year.value ? ' ' + value_year.value : ''
  501. defaultValue.value =
  502. value_second.value +
  503. ' ' +
  504. value_minute.value +
  505. ' ' +
  506. value_hour.value +
  507. ' ' +
  508. value_day.value +
  509. ' ' +
  510. value_month.value +
  511. ' ' +
  512. value_week.value +
  513. year
  514. emit('update:modelValue', defaultValue.value)
  515. dialogVisible.value = false
  516. }
  517. </script>
  518. <template>
  519. <el-input v-model="defaultValue" v-bind="$attrs">
  520. <template #append>
  521. <el-dropdown split-button trigger="click" @command="handleShortcuts">
  522. 生成器
  523. <template #dropdown>
  524. <el-dropdown-menu>
  525. <el-dropdown-item command="0 * * * * ?">每分钟</el-dropdown-item>
  526. <el-dropdown-item command="0 0 * * * ?">每小时</el-dropdown-item>
  527. <el-dropdown-item command="0 0 0 * * ?">每天零点</el-dropdown-item>
  528. <el-dropdown-item command="0 0 0 1 * ?">每月一号零点</el-dropdown-item>
  529. <el-dropdown-item command="0 0 0 L * ?">每月最后一天零点</el-dropdown-item>
  530. <el-dropdown-item command="0 0 0 ? * 1">每周星期日零点</el-dropdown-item>
  531. <el-dropdown-item
  532. v-for="(item, index) in shortcuts"
  533. :key="item.value"
  534. :divided="index == 0"
  535. :command="item.value"
  536. >
  537. {{ item.text }}
  538. </el-dropdown-item>
  539. <el-dropdown-item divided command="custom">
  540. <Icon icon="ep:menu" />自定义
  541. </el-dropdown-item>
  542. </el-dropdown-menu>
  543. </template>
  544. </el-dropdown>
  545. </template>
  546. </el-input>
  547. <el-dialog
  548. title="cron规则生成器"
  549. v-model="dialogVisible"
  550. :width="580"
  551. destroy-on-close
  552. append-to-body
  553. >
  554. <div class="sc-cron">
  555. <el-tabs>
  556. <el-tab-pane>
  557. <template #label>
  558. <div class="sc-cron-num">
  559. <h2>秒</h2>
  560. <h4>{{ value_second }}</h4>
  561. </div>
  562. </template>
  563. <el-form>
  564. <el-form-item label="类型">
  565. <el-radio-group v-model="cronValue.second.type">
  566. <el-radio-button label="0">任意值</el-radio-button>
  567. <el-radio-button label="1">范围</el-radio-button>
  568. <el-radio-button label="2">间隔</el-radio-button>
  569. <el-radio-button label="3">指定</el-radio-button>
  570. </el-radio-group>
  571. </el-form-item>
  572. <el-form-item label="范围" v-if="cronValue.second.type == '1'">
  573. <el-input-number
  574. v-model="cronValue.second.range.start"
  575. :min="0"
  576. :max="59"
  577. controls-position="right"
  578. />
  579. <span style="padding: 0 15px">-</span>
  580. <el-input-number
  581. v-model="cronValue.second.range.end"
  582. :min="0"
  583. :max="59"
  584. controls-position="right"
  585. />
  586. </el-form-item>
  587. <el-form-item label="间隔" v-if="cronValue.second.type == '2'">
  588. <el-input-number
  589. v-model="cronValue.second.loop.start"
  590. :min="0"
  591. :max="59"
  592. controls-position="right"
  593. />
  594. 秒开始,每
  595. <el-input-number
  596. v-model="cronValue.second.loop.end"
  597. :min="0"
  598. :max="59"
  599. controls-position="right"
  600. />
  601. 秒执行一次
  602. </el-form-item>
  603. <el-form-item label="指定" v-if="cronValue.second.type == '3'">
  604. <el-select v-model="cronValue.second.appoint" multiple style="width: 100%">
  605. <el-option
  606. v-for="(item, index) in data.second"
  607. :key="index"
  608. :label="item"
  609. :value="item"
  610. />
  611. </el-select>
  612. </el-form-item>
  613. </el-form>
  614. </el-tab-pane>
  615. <el-tab-pane>
  616. <template #label>
  617. <div class="sc-cron-num">
  618. <h2>分钟</h2>
  619. <h4>{{ value_minute }}</h4>
  620. </div>
  621. </template>
  622. <el-form>
  623. <el-form-item label="类型">
  624. <el-radio-group v-model="cronValue.minute.type">
  625. <el-radio-button label="0">任意值</el-radio-button>
  626. <el-radio-button label="1">范围</el-radio-button>
  627. <el-radio-button label="2">间隔</el-radio-button>
  628. <el-radio-button label="3">指定</el-radio-button>
  629. </el-radio-group>
  630. </el-form-item>
  631. <el-form-item label="范围" v-if="cronValue.minute.type == '1'">
  632. <el-input-number
  633. v-model="cronValue.minute.range.start"
  634. :min="0"
  635. :max="59"
  636. controls-position="right"
  637. />
  638. <span style="padding: 0 15px">-</span>
  639. <el-input-number
  640. v-model="cronValue.minute.range.end"
  641. :min="0"
  642. :max="59"
  643. controls-position="right"
  644. />
  645. </el-form-item>
  646. <el-form-item label="间隔" v-if="cronValue.minute.type == '2'">
  647. <el-input-number
  648. v-model="cronValue.minute.loop.start"
  649. :min="0"
  650. :max="59"
  651. controls-position="right"
  652. />
  653. 分钟开始,每
  654. <el-input-number
  655. v-model="cronValue.minute.loop.end"
  656. :min="0"
  657. :max="59"
  658. controls-position="right"
  659. />
  660. 分钟执行一次
  661. </el-form-item>
  662. <el-form-item label="指定" v-if="cronValue.minute.type == '3'">
  663. <el-select v-model="cronValue.minute.appoint" multiple style="width: 100%">
  664. <el-option
  665. v-for="(item, index) in data.minute"
  666. :key="index"
  667. :label="item"
  668. :value="item"
  669. />
  670. </el-select>
  671. </el-form-item>
  672. </el-form>
  673. </el-tab-pane>
  674. <el-tab-pane>
  675. <template #label>
  676. <div class="sc-cron-num">
  677. <h2>小时</h2>
  678. <h4>{{ value_hour }}</h4>
  679. </div>
  680. </template>
  681. <el-form>
  682. <el-form-item label="类型">
  683. <el-radio-group v-model="cronValue.hour.type">
  684. <el-radio-button label="0">任意值</el-radio-button>
  685. <el-radio-button label="1">范围</el-radio-button>
  686. <el-radio-button label="2">间隔</el-radio-button>
  687. <el-radio-button label="3">指定</el-radio-button>
  688. </el-radio-group>
  689. </el-form-item>
  690. <el-form-item label="范围" v-if="cronValue.hour.type == '1'">
  691. <el-input-number
  692. v-model="cronValue.hour.range.start"
  693. :min="0"
  694. :max="23"
  695. controls-position="right"
  696. />
  697. <span style="padding: 0 15px">-</span>
  698. <el-input-number
  699. v-model="cronValue.hour.range.end"
  700. :min="0"
  701. :max="23"
  702. controls-position="right"
  703. />
  704. </el-form-item>
  705. <el-form-item label="间隔" v-if="cronValue.hour.type == '2'">
  706. <el-input-number
  707. v-model="cronValue.hour.loop.start"
  708. :min="0"
  709. :max="23"
  710. controls-position="right"
  711. />
  712. 小时开始,每
  713. <el-input-number
  714. v-model="cronValue.hour.loop.end"
  715. :min="0"
  716. :max="23"
  717. controls-position="right"
  718. />
  719. 小时执行一次
  720. </el-form-item>
  721. <el-form-item label="指定" v-if="cronValue.hour.type == '3'">
  722. <el-select v-model="cronValue.hour.appoint" multiple style="width: 100%">
  723. <el-option
  724. v-for="(item, index) in data.hour"
  725. :key="index"
  726. :label="item"
  727. :value="item"
  728. />
  729. </el-select>
  730. </el-form-item>
  731. </el-form>
  732. </el-tab-pane>
  733. <el-tab-pane>
  734. <template #label>
  735. <div class="sc-cron-num">
  736. <h2>日</h2>
  737. <h4>{{ value_day }}</h4>
  738. </div>
  739. </template>
  740. <el-form>
  741. <el-form-item label="类型">
  742. <el-radio-group v-model="cronValue.day.type">
  743. <el-radio-button label="0">任意值</el-radio-button>
  744. <el-radio-button label="1">范围</el-radio-button>
  745. <el-radio-button label="2">间隔</el-radio-button>
  746. <el-radio-button label="3">指定</el-radio-button>
  747. <el-radio-button label="4">本月最后一天</el-radio-button>
  748. <el-radio-button label="5">不指定</el-radio-button>
  749. </el-radio-group>
  750. </el-form-item>
  751. <el-form-item label="范围" v-if="cronValue.day.type == '1'">
  752. <el-input-number
  753. v-model="cronValue.day.range.start"
  754. :min="1"
  755. :max="31"
  756. controls-position="right"
  757. />
  758. <span style="padding: 0 15px">-</span>
  759. <el-input-number
  760. v-model="cronValue.day.range.end"
  761. :min="1"
  762. :max="31"
  763. controls-position="right"
  764. />
  765. </el-form-item>
  766. <el-form-item label="间隔" v-if="cronValue.day.type == '2'">
  767. <el-input-number
  768. v-model="cronValue.day.loop.start"
  769. :min="1"
  770. :max="31"
  771. controls-position="right"
  772. />
  773. 号开始,每
  774. <el-input-number
  775. v-model="cronValue.day.loop.end"
  776. :min="1"
  777. :max="31"
  778. controls-position="right"
  779. />
  780. 天执行一次
  781. </el-form-item>
  782. <el-form-item label="指定" v-if="cronValue.day.type == '3'">
  783. <el-select v-model="cronValue.day.appoint" multiple style="width: 100%">
  784. <el-option
  785. v-for="(item, index) in data.day"
  786. :key="index"
  787. :label="item"
  788. :value="item"
  789. />
  790. </el-select>
  791. </el-form-item>
  792. </el-form>
  793. </el-tab-pane>
  794. <el-tab-pane>
  795. <template #label>
  796. <div class="sc-cron-num">
  797. <h2>月</h2>
  798. <h4>{{ value_month }}</h4>
  799. </div>
  800. </template>
  801. <el-form>
  802. <el-form-item label="类型">
  803. <el-radio-group v-model="cronValue.month.type">
  804. <el-radio-button label="0">任意值</el-radio-button>
  805. <el-radio-button label="1">范围</el-radio-button>
  806. <el-radio-button label="2">间隔</el-radio-button>
  807. <el-radio-button label="3">指定</el-radio-button>
  808. </el-radio-group>
  809. </el-form-item>
  810. <el-form-item label="范围" v-if="cronValue.month.type == '1'">
  811. <el-input-number
  812. v-model="cronValue.month.range.start"
  813. :min="1"
  814. :max="12"
  815. controls-position="right"
  816. />
  817. <span style="padding: 0 15px">-</span>
  818. <el-input-number
  819. v-model="cronValue.month.range.end"
  820. :min="1"
  821. :max="12"
  822. controls-position="right"
  823. />
  824. </el-form-item>
  825. <el-form-item label="间隔" v-if="cronValue.month.type == '2'">
  826. <el-input-number
  827. v-model="cronValue.month.loop.start"
  828. :min="1"
  829. :max="12"
  830. controls-position="right"
  831. />
  832. 月开始,每
  833. <el-input-number
  834. v-model="cronValue.month.loop.end"
  835. :min="1"
  836. :max="12"
  837. controls-position="right"
  838. />
  839. 月执行一次
  840. </el-form-item>
  841. <el-form-item label="指定" v-if="cronValue.month.type == '3'">
  842. <el-select v-model="cronValue.month.appoint" multiple style="width: 100%">
  843. <el-option
  844. v-for="(item, index) in data.month"
  845. :key="index"
  846. :label="item"
  847. :value="item"
  848. />
  849. </el-select>
  850. </el-form-item>
  851. </el-form>
  852. </el-tab-pane>
  853. <el-tab-pane>
  854. <template #label>
  855. <div class="sc-cron-num">
  856. <h2>周</h2>
  857. <h4>{{ value_week }}</h4>
  858. </div>
  859. </template>
  860. <el-form>
  861. <el-form>
  862. <el-form-item label="类型">
  863. <el-radio-group v-model="cronValue.week.type">
  864. <el-radio-button label="0">任意值</el-radio-button>
  865. <el-radio-button label="1">范围</el-radio-button>
  866. <el-radio-button label="2">间隔</el-radio-button>
  867. <el-radio-button label="3">指定</el-radio-button>
  868. <el-radio-button label="4">本月最后一周</el-radio-button>
  869. <el-radio-button label="5">不指定</el-radio-button>
  870. </el-radio-group>
  871. </el-form-item>
  872. <el-form-item label="范围" v-if="cronValue.week.type == '1'">
  873. <el-select v-model="cronValue.week.range.start">
  874. <el-option
  875. v-for="(item, index) in data.week"
  876. :key="index"
  877. :label="item.label"
  878. :value="item.value"
  879. />
  880. </el-select>
  881. <span style="padding: 0 15px">-</span>
  882. <el-select v-model="cronValue.week.range.end">
  883. <el-option
  884. v-for="(item, index) in data.week"
  885. :key="index"
  886. :label="item.label"
  887. :value="item.value"
  888. />
  889. </el-select>
  890. </el-form-item>
  891. <el-form-item label="间隔" v-if="cronValue.week.type == '2'">
  892. 第
  893. <el-input-number
  894. v-model="cronValue.week.loop.start"
  895. :min="1"
  896. :max="4"
  897. controls-position="right"
  898. />
  899. 周的星期
  900. <el-select v-model="cronValue.week.loop.end">
  901. <el-option
  902. v-for="(item, index) in data.week"
  903. :key="index"
  904. :label="item.label"
  905. :value="item.value"
  906. />
  907. </el-select>
  908. 执行一次
  909. </el-form-item>
  910. <el-form-item label="指定" v-if="cronValue.week.type == '3'">
  911. <el-select v-model="cronValue.week.appoint" multiple style="width: 100%">
  912. <el-option
  913. v-for="(item, index) in data.week"
  914. :key="index"
  915. :label="item.label"
  916. :value="item.value"
  917. />
  918. </el-select>
  919. </el-form-item>
  920. <el-form-item label="最后一周" v-if="cronValue.week.type == '4'">
  921. <el-select v-model="cronValue.week.last">
  922. <el-option
  923. v-for="(item, index) in data.week"
  924. :key="index"
  925. :label="item.label"
  926. :value="item.value"
  927. />
  928. </el-select>
  929. </el-form-item>
  930. </el-form>
  931. </el-form>
  932. </el-tab-pane>
  933. <el-tab-pane>
  934. <template #label>
  935. <div class="sc-cron-num">
  936. <h2>年</h2>
  937. <h4>{{ value_year }}</h4>
  938. </div>
  939. </template>
  940. <el-form>
  941. <el-form-item label="类型">
  942. <el-radio-group v-model="cronValue.year.type">
  943. <el-radio-button label="-1">忽略</el-radio-button>
  944. <el-radio-button label="0">任意值</el-radio-button>
  945. <el-radio-button label="1">范围</el-radio-button>
  946. <el-radio-button label="2">间隔</el-radio-button>
  947. <el-radio-button label="3">指定</el-radio-button>
  948. </el-radio-group>
  949. </el-form-item>
  950. <el-form-item label="范围" v-if="cronValue.year.type == '1'">
  951. <el-input-number v-model="cronValue.year.range.start" controls-position="right" />
  952. <span style="padding: 0 15px">-</span>
  953. <el-input-number v-model="cronValue.year.range.end" controls-position="right" />
  954. </el-form-item>
  955. <el-form-item label="间隔" v-if="cronValue.year.type == '2'">
  956. <el-input-number v-model="cronValue.year.loop.start" controls-position="right" />
  957. 年开始,每
  958. <el-input-number
  959. v-model="cronValue.year.loop.end"
  960. :min="1"
  961. controls-position="right"
  962. />
  963. 年执行一次
  964. </el-form-item>
  965. <el-form-item label="指定" v-if="cronValue.year.type == '3'">
  966. <el-select v-model="cronValue.year.appoint" multiple style="width: 100%">
  967. <el-option
  968. v-for="(item, index) in data.year"
  969. :key="index"
  970. :label="item"
  971. :value="item"
  972. />
  973. </el-select>
  974. </el-form-item>
  975. </el-form>
  976. </el-tab-pane>
  977. </el-tabs>
  978. </div>
  979. <template #footer>
  980. <el-button @click="dialogVisible = false">取 消</el-button>
  981. <el-button type="primary" @click="submit()">确 认</el-button>
  982. </template>
  983. </el-dialog>
  984. </template>
  985. <style scoped>
  986. .sc-cron:deep(.el-tabs__item) {
  987. height: auto;
  988. line-height: 1;
  989. padding: 0 7px;
  990. vertical-align: bottom;
  991. }
  992. .sc-cron-num {
  993. text-align: center;
  994. margin-bottom: 15px;
  995. width: 100%;
  996. }
  997. .sc-cron-num h2 {
  998. font-size: 12px;
  999. margin-bottom: 15px;
  1000. font-weight: normal;
  1001. }
  1002. .sc-cron-num h4 {
  1003. display: block;
  1004. height: 32px;
  1005. line-height: 30px;
  1006. width: 100%;
  1007. font-size: 12px;
  1008. padding: 0 15px;
  1009. background: var(--el-color-primary-light-9);
  1010. border-radius: 4px;
  1011. }
  1012. .sc-cron:deep(.el-tabs__item.is-active) .sc-cron-num h4 {
  1013. background: var(--el-color-primary);
  1014. color: #fff;
  1015. }
  1016. [data-theme='dark'] .sc-cron-num h4 {
  1017. background: var(--el-color-white);
  1018. }
  1019. </style>