diff --git a/apps/web-antd/src/views/iot/rule/data/rule/modules/form.vue b/apps/web-antd/src/views/iot/rule/data/rule/modules/form.vue index 0fbc31114..3faafe325 100644 --- a/apps/web-antd/src/views/iot/rule/data/rule/modules/form.vue +++ b/apps/web-antd/src/views/iot/rule/data/rule/modules/form.vue @@ -47,7 +47,11 @@ const [Modal, modalApi] = useVbenModal({ return; } // 校验数据源配置 - await sourceConfigRef.value?.validate(); + try { + await sourceConfigRef.value?.validate(); + } catch { + return; + } modalApi.lock(); // 提交表单 const data = (await formApi.getValues()) as DataRuleApi.DataRule; @@ -65,6 +69,7 @@ const [Modal, modalApi] = useVbenModal({ async onOpenChange(isOpen: boolean) { if (!isOpen) { formData.value = undefined; + await formApi.resetForm(); sourceConfigRef.value?.setData([]); return; } diff --git a/apps/web-antd/src/views/iot/rule/data/rule/modules/source-config-form.vue b/apps/web-antd/src/views/iot/rule/data/rule/modules/source-config-form.vue index 0424effb8..533dc9ec1 100644 --- a/apps/web-antd/src/views/iot/rule/data/rule/modules/source-config-form.vue +++ b/apps/web-antd/src/views/iot/rule/data/rule/modules/source-config-form.vue @@ -154,6 +154,10 @@ async function handleDelete(rowIndex: number) { /** 校验全部行;返回 Promise,失败时 reject 第一条错误信息 */ function validate() { + if (formData.value.length === 0) { + message.error('请至少添加一条数据源配置'); + return Promise.reject(new Error('数据源配置不能为空')); + } for (let i = 0; i < formData.value.length; i++) { const row = formData.value[i]; if (!row.productId) { diff --git a/apps/web-antd/src/views/iot/rule/scene/form/sections/action-section.vue b/apps/web-antd/src/views/iot/rule/scene/form/sections/action-section.vue index 51668f344..a9d149abf 100644 --- a/apps/web-antd/src/views/iot/rule/scene/form/sections/action-section.vue +++ b/apps/web-antd/src/views/iot/rule/scene/form/sections/action-section.vue @@ -99,8 +99,9 @@ function removeAction(index: number) { * @param type 执行器类型 */ function updateActionType(index: number, type: number) { - actions.value[index]!.type = type; - onActionTypeChange(actions.value[index] as RuleSceneApi.Action, type); + const action = actions.value[index] as RuleSceneApi.Action; + onActionTypeChange(action, type); // 须在赋新值前调用 ,内部依赖 action.type 旧值 + action.type = type; } /** @@ -134,7 +135,7 @@ function onActionTypeChange(action: RuleSceneApi.Action, type: number) { action.params = ''; } // 切换到设备控制类型时清空 identifier,让用户重新选择 - if (action.identifier && type !== action.type) { + if (action.identifier) { action.identifier = undefined; } } else if (isAlertAction(type)) { diff --git a/apps/web-ele/src/views/iot/rule/data/rule/modules/form.vue b/apps/web-ele/src/views/iot/rule/data/rule/modules/form.vue index a46844ad3..7f4adf27e 100644 --- a/apps/web-ele/src/views/iot/rule/data/rule/modules/form.vue +++ b/apps/web-ele/src/views/iot/rule/data/rule/modules/form.vue @@ -47,7 +47,11 @@ const [Modal, modalApi] = useVbenModal({ return; } // 校验数据源配置 - await sourceConfigRef.value?.validate(); + try { + await sourceConfigRef.value?.validate(); + } catch { + return; + } modalApi.lock(); // 提交表单 const data = (await formApi.getValues()) as DataRuleApi.DataRule; @@ -65,6 +69,7 @@ const [Modal, modalApi] = useVbenModal({ async onOpenChange(isOpen: boolean) { if (!isOpen) { formData.value = undefined; + await formApi.resetForm(); sourceConfigRef.value?.setData([]); return; } diff --git a/apps/web-ele/src/views/iot/rule/data/rule/modules/source-config-form.vue b/apps/web-ele/src/views/iot/rule/data/rule/modules/source-config-form.vue index 0733a212d..7015b9ba6 100644 --- a/apps/web-ele/src/views/iot/rule/data/rule/modules/source-config-form.vue +++ b/apps/web-ele/src/views/iot/rule/data/rule/modules/source-config-form.vue @@ -154,6 +154,10 @@ async function handleDelete(rowIndex: number) { /** 校验全部行;返回 Promise,失败时 reject 第一条错误信息 */ function validate() { + if (formData.value.length === 0) { + ElMessage.error('请至少添加一条数据源配置'); + return Promise.reject(new Error('数据源配置不能为空')); + } for (let i = 0; i < formData.value.length; i++) { const row = formData.value[i]; if (!row.productId) { diff --git a/apps/web-ele/src/views/iot/rule/scene/form/sections/action-section.vue b/apps/web-ele/src/views/iot/rule/scene/form/sections/action-section.vue index c92e1b82b..b100b0211 100644 --- a/apps/web-ele/src/views/iot/rule/scene/form/sections/action-section.vue +++ b/apps/web-ele/src/views/iot/rule/scene/form/sections/action-section.vue @@ -107,8 +107,9 @@ function removeAction(index: number) { * @param type 执行器类型 */ function updateActionType(index: number, type: number) { - actions.value[index]!.type = type; - onActionTypeChange(actions.value[index] as RuleSceneApi.Action, type); + const action = actions.value[index] as RuleSceneApi.Action; + onActionTypeChange(action, type); // 须在赋新值前调用 ,内部依赖 action.type 旧值 + action.type = type; } /** @@ -142,7 +143,7 @@ function onActionTypeChange(action: RuleSceneApi.Action, type: number) { action.params = ''; } // 切换到设备控制类型时清空 identifier,让用户重新选择 - if (action.identifier && type !== action.type) { + if (action.identifier) { action.identifier = undefined; } } else if (isAlertAction(type)) {