142142 </el-tooltip >
143143 </div >
144144
145- <el-cascader
145+ <el-form-item
146146 v-if =" form.trigger_setting.schedule_type !== 'cron'"
147- v-model =" scheduled"
148- :options =" triggerCycleOptions"
149- @change =" handleChangeScheduled"
150- style =" width : 100% "
151- />
152- <el-input
153- v-else
154- v-model =" form.trigger_setting.cron_expression"
155- :placeholder =" t('views.trigger.triggerCycle.placeholder')"
156- clearable
157- @blur =" validateCron"
158- @input =" validateCron"
159- />
160- <div v-if =" cronError" class =" el-form-item__error" >{{ cronError }}</div >
147+ prop =" trigger_setting.schedule_type"
148+ :rules =" scheduledRules"
149+ >
150+ <el-cascader
151+ v-model =" scheduled"
152+ :options =" triggerCycleOptions"
153+ @change =" handleChangeScheduled"
154+ style =" width : 100% "
155+ />
156+ </el-form-item >
157+ <el-form-item v-else prop =" trigger_setting.cron_expression" :rules =" cronRules" >
158+ <el-input
159+ v-model =" form.trigger_setting.cron_expression"
160+ :placeholder =" t('views.trigger.triggerCycle.placeholder')"
161+ clearable
162+ />
163+ </el-form-item >
161164 </el-card >
162165 </el-card >
163166 </el-form-item >
180183</template >
181184
182185<script setup lang="ts">
183- import { computed , ref } from ' vue'
186+ import { computed , nextTick , ref } from ' vue'
184187import { triggerCycleOptions } from ' @/utils/trigger.ts'
185188import { t } from ' @/locales'
186189import { cloneDeep , groupBy } from ' lodash'
@@ -216,7 +219,6 @@ const form = ref<any>({
216219})
217220
218221const lastPresetSetting = ref <any >(null )
219- const cronError = ref (' ' )
220222
221223const changeTriggerType = (type : string ) => {
222224 form .value .trigger_type = type
@@ -274,18 +276,40 @@ function openLongTermParamSettingDialog() {
274276 }
275277}
276278
277- const validateCron = () => {
278- const cron = form .value .trigger_setting .cron_expression ?.trim ()
279- if (! cron ) {
280- cronError .value = ' '
281- return
282- }
283- const fields = cron .split (/ \s + / )
284- if (fields .length !== 5 || ! isValidCron (cron )) {
285- cronError .value = t (' views.application.longTermMemory.cronExpressionInvalid' )
286- } else {
287- cronError .value = ' '
288- }
279+ const scheduledRules = {
280+ validator : (rule : any , value : any , callback : any ) => {
281+ const { schedule_type, interval_unit, interval_value, days, time } = form .value .trigger_setting
282+ let valid = false
283+ if (schedule_type === ' interval' ) {
284+ valid = !! interval_unit && !! interval_value
285+ } else if (schedule_type === ' daily' ) {
286+ valid = !! time ?.[0 ]
287+ } else if (schedule_type === ' weekly' || schedule_type === ' monthly' ) {
288+ valid = !! days ?.[0 ] && !! time ?.[0 ]
289+ }
290+ if (valid ) {
291+ callback ()
292+ } else {
293+ callback (new Error (t (' common.selectPlaceholder' ) + t (' views.trigger.triggerCycle.title' )))
294+ }
295+ },
296+ trigger: ' change' ,
297+ }
298+
299+ const cronRules = {
300+ validator : (rule : any , value : any , callback : any ) => {
301+ const cron = value ?.trim ()
302+ if (! cron ) {
303+ callback (
304+ new Error (t (' common.inputPlaceholder' ) + t (' views.trigger.triggerCycle.cronExpression' )),
305+ )
306+ } else if (cron .split (/ \s + / ).length !== 5 || ! isValidCron (cron )) {
307+ callback (new Error (t (' views.application.longTermMemory.cronExpressionInvalid' )))
308+ } else {
309+ callback ()
310+ }
311+ },
312+ trigger: [' blur' , ' change' ],
289313}
290314
291315function switchScheduleType() {
@@ -308,7 +332,6 @@ function switchScheduleType() {
308332 form .value .trigger_setting .time = undefined
309333 return
310334 }
311- cronError .value = ' '
312335 const backup = lastPresetSetting .value
313336 form .value .trigger_setting .schedule_type = backup ?.schedule_type || ' daily'
314337 form .value .trigger_setting .interval_unit = backup ?.interval_unit
@@ -388,6 +411,7 @@ const open = (data: any) => {
388411 if (modelSettingEnable .value ) {
389412 getSelectModel ()
390413 }
414+ nextTick (() => paramFormRef .value ?.clearValidate ())
391415}
392416
393417const submit = () => {
0 commit comments