From 769a20e98698ef6769c82c88ee31a93f5717743c Mon Sep 17 00:00:00 2001 From: Devosend Date: Fri, 26 Aug 2022 23:04:29 +0800 Subject: [PATCH] [Fix][UI] Fix bug where crontab special of month and year (#11661) --- .../src/components/crontab/common.ts | 39 ++++++++++- .../src/components/crontab/index.tsx | 19 +++++ .../src/components/crontab/modules/day.tsx | 17 ++--- .../src/components/crontab/modules/time.tsx | 70 +++++++++++++------ .../src/components/crontab/types.ts | 9 ++- 5 files changed, 124 insertions(+), 30 deletions(-) diff --git a/dolphinscheduler-ui/src/components/crontab/common.ts b/dolphinscheduler-ui/src/components/crontab/common.ts index 5069801d5d..af4168f1ae 100644 --- a/dolphinscheduler-ui/src/components/crontab/common.ts +++ b/dolphinscheduler-ui/src/components/crontab/common.ts @@ -16,6 +16,7 @@ */ import _ from 'lodash' +import type { ISpecialSelect } from './types' const timeI18n = { second: { @@ -190,4 +191,40 @@ const isWeek = (str: string) => { return flag } -export { isStr, isWeek, timeI18n, week, specificWeek, lastWeeks } +const range = (start: number, stop: number, step = 1) => + Array.from({ length: (stop - start) / step + 1 }, (_, i) => start + i * step) + +const specificList: ISpecialSelect = { + 60: _.map(range(0, 59), (v) => { + return { + value: v + '', + label: v + '' + } + }), + 24: _.map(range(0, 23), (v) => { + return { + value: v + '', + label: v + '' + } + }), + 12: _.map(range(1, 12), (v) => { + return { + value: v + '', + label: v + '' + } + }), + year: _.map(range(2018, 2030), (v) => { + return { + value: v + '', + label: v + '' + } + }), + day: _.map(range(1, 31), (v) => { + return { + value: v + '', + label: v + '' + } + }) +} + +export { isStr, isWeek, timeI18n, week, specificWeek, lastWeeks, specificList } diff --git a/dolphinscheduler-ui/src/components/crontab/index.tsx b/dolphinscheduler-ui/src/components/crontab/index.tsx index d74623f841..c0bc835f70 100644 --- a/dolphinscheduler-ui/src/components/crontab/index.tsx +++ b/dolphinscheduler-ui/src/components/crontab/index.tsx @@ -93,18 +93,27 @@ export default defineComponent({ @@ -117,12 +126,22 @@ export default defineComponent({ diff --git a/dolphinscheduler-ui/src/components/crontab/modules/day.tsx b/dolphinscheduler-ui/src/components/crontab/modules/day.tsx index 9c67ff9db3..201e9b777a 100644 --- a/dolphinscheduler-ui/src/components/crontab/modules/day.tsx +++ b/dolphinscheduler-ui/src/components/crontab/modules/day.tsx @@ -18,7 +18,14 @@ import { defineComponent, onMounted, PropType, ref, watch } from 'vue' import { NInputNumber, NRadio, NRadioGroup, NSelect } from 'naive-ui' import { useI18n } from 'vue-i18n' -import { isStr, isWeek, week, specificWeek, lastWeeks } from '../common' +import { + isStr, + isWeek, + week, + specificWeek, + lastWeeks, + specificList +} from '../common' import styles from '../index.module.scss' const props = { @@ -39,11 +46,6 @@ export default defineComponent({ setup(props, ctx) { const { t } = useI18n() - const options = Array.from({ length: 60 }, (x, i) => ({ - label: i.toString(), - value: i - })) - const weekOptions = week.map((v) => ({ label: t(v.label), value: v.value @@ -430,7 +432,6 @@ export default defineComponent({ onMounted(() => analyticalValue()) return { - options, weekOptions, lastWeekOptions, radioRef, @@ -551,7 +552,7 @@ export default defineComponent({ , + default: 0 + }, + timeMax: { + type: Number as PropType, + default: 60 + }, + intervalPerform: { + type: Number as PropType, + default: 5 + }, + intervalStart: { + type: Number as PropType, + default: 3 + }, + cycleStart: { + type: Number as PropType, + default: 1 + }, + cycleEnd: { + type: Number as PropType, + default: 1 + }, + timeSpecial: { + type: Number as PropType, + default: 60 + }, timeValue: { type: String as PropType, default: '*' @@ -46,11 +74,11 @@ export default defineComponent({ const timeRef = ref() const radioRef = ref() - const intervalStartRef = ref(0) - const intervalPerformRef = ref(0) + const intervalStartRef = ref(props.intervalStart) + const intervalPerformRef = ref(props.intervalPerform) const specificTimesRef = ref>([]) - const cycleStartRef = ref(0) - const cycleEndRef = ref(0) + const cycleStartRef = ref(props.cycleStart) + const cycleEndRef = ref(props.cycleEnd) /** * Parse parameter value @@ -73,8 +101,10 @@ export default defineComponent({ // Positive integer (times) if ( - ($timeVal.length === 1 && _.isInteger(parseInt($timeVal))) || - ($timeVal.length === 2 && _.isInteger(parseInt($timeVal))) + ($timeVal.length === 1 || + $timeVal.length === 2 || + $timeVal.length === 4) && + _.isInteger(parseInt($timeVal)) ) { radioRef.value = 'specificTime' specificTimesRef.value = [parseInt($timeVal)] @@ -232,9 +262,9 @@ export default defineComponent({
{t(this.timeI18n!.every)}
@@ -244,9 +274,9 @@ export default defineComponent({
@@ -261,7 +291,7 @@ export default defineComponent({
{t(this.timeI18n!.cycleFrom)}
@@ -285,9 +315,9 @@ export default defineComponent({
{t(this.timeI18n!.to)}
diff --git a/dolphinscheduler-ui/src/components/crontab/types.ts b/dolphinscheduler-ui/src/components/crontab/types.ts index 77d28676d5..99177ceadd 100644 --- a/dolphinscheduler-ui/src/components/crontab/types.ts +++ b/dolphinscheduler-ui/src/components/crontab/types.ts @@ -27,4 +27,11 @@ interface ICrontabI18n { time: string } -export { ICrontabI18n } +interface ISpecialSelect { + [key: number | string]: { + label: string + value: string + }[] +} + +export { ICrontabI18n, ISpecialSelect }