From 152964395dcda019fae67cfce6152f32311bf6cf Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 22 May 2026 20:24:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(iot):=20=E4=BF=AE=E5=A4=8D=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E8=81=94=E5=8A=A8=E5=8A=A8=E4=BD=9C=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=88=87=E6=8D=A2=20+=20=E6=95=B0=E6=8D=AE=E8=A7=84=E5=88=99?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=204=20=E5=A4=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - B50 动作类型切换清理失效:updateActionType 先调 onActionTypeChange (此时 action.type 仍是旧值)再赋新值;onActionTypeChange 内恒真的 type !== action.type 简化为 if (action.identifier) - B16 新增弹窗不重置主表单:onOpenChange 关闭分支补 formApi.resetForm() - B17 允许空数据源提交:source-config-form.validate() 补空数组校验 - B18 子表单校验 reject 未处理(弹窗关闭不掉):onConfirm 内 try/catch 包子表单校验,失败 return 中止提交 --- .../web-antd/src/views/iot/rule/data/rule/modules/form.vue | 7 ++++++- .../iot/rule/data/rule/modules/source-config-form.vue | 4 ++++ .../views/iot/rule/scene/form/sections/action-section.vue | 7 ++++--- apps/web-ele/src/views/iot/rule/data/rule/modules/form.vue | 7 ++++++- .../iot/rule/data/rule/modules/source-config-form.vue | 4 ++++ .../views/iot/rule/scene/form/sections/action-section.vue | 7 ++++--- 6 files changed, 28 insertions(+), 8 deletions(-) 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)) {