From 416411732f1b3283f7e73aef50dd8f9d5e5798c2 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 7 Aug 2025 14:50:14 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E3=80=90IoT=20=E7=89=A9=E8=81=94?= =?UTF-8?q?=E7=BD=91=E3=80=91=E5=9C=BA=E6=99=AF=E8=81=94=E5=8A=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20ConditionGroupContainerConfig=20=E7=9A=84=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E7=9B=B4=E6=8E=A5=E5=86=85=E8=81=94=E5=9C=A8=E4=B8=BB?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scene/form/configs/ConditionConfig.vue | 1 - .../configs/ConditionGroupContainerConfig.vue | 233 ------------------ .../form/configs/DeviceTriggerConfig.vue | 213 +++++++++++++++- 3 files changed, 207 insertions(+), 240 deletions(-) delete mode 100644 src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue diff --git a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue index 8a9fcee99..98644b98a 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue @@ -77,7 +77,6 @@ - -
- -
-
-
-
- 组 -
- 附加条件组 -
- 与“主条件”为且关系 - {{ modelValue?.length || 0 }} 个子条件组 -
-
- - - 添加子条件组 - - - - 删除条件组 - -
-
- - -
- -
-
- -
-
-
-
-
- {{ subGroupIndex + 1 }} -
- 子条件组 {{ subGroupIndex + 1 }} -
- 组内条件为"且"关系 - - {{ subGroup.conditions?.length || 0 }}个条件 - -
- - - 删除组 - -
- - -
- - -
-
- -
- -
- -
- -
-
-
-
-
-
- - -
-
- -
-

暂无子条件组

-

点击上方"添加子条件组"按钮开始配置

-
-
-
-
- - - diff --git a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue index aa94efd2f..d3f39ee66 100644 --- a/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/DeviceTriggerConfig.vue @@ -39,11 +39,128 @@
- +
+ +
+
+
+
+ 组 +
+ 附加条件组 +
+ 与"主条件"为且关系 + + {{ trigger.conditionGroups?.length || 0 }} 个子条件组 + +
+
+ + + 添加子条件组 + + + + 删除条件组 + +
+
+ + +
+ +
+
+ +
+
+
+
+
+ {{ subGroupIndex + 1 }} +
+ 子条件组 {{ subGroupIndex + 1 }} +
+ 组内条件为"且"关系 + {{ subGroup?.length || 0 }}个条件 +
+ + + 删除组 + +
+ + +
+ + +
+
+ +
+ +
+ +
+ +
+
+
+
+
+
+ + +
+
+ +
+

暂无子条件组

+

点击上方"添加子条件组"按钮开始配置

+
+
+
+
@@ -52,7 +169,7 @@ import { useVModel } from '@vueuse/core' import MainConditionInnerConfig from './MainConditionInnerConfig.vue' -import ConditionGroupContainerConfig from './ConditionGroupContainerConfig.vue' +import SubConditionGroupConfig from './SubConditionGroupConfig.vue' import type { Trigger } from '@/api/iot/rule/scene' /** 设备触发配置组件 */ @@ -71,6 +188,13 @@ const emit = defineEmits<{ const trigger = useVModel(props, 'modelValue', emit) +// 配置常量 +const maxSubGroups = 3 // 最多 3 个子条件组 +const maxConditionsPerGroup = 3 // 每组最多 3 个条件 + +// 验证状态 +const subGroupValidations = ref<{ [key: number]: { valid: boolean; message: string } }>({}) + // 事件处理 const updateCondition = (condition: Trigger) => { trigger.value = condition @@ -85,7 +209,84 @@ const handleTriggerTypeChange = (type: number) => { emit('trigger-type-change', type) } +// 条件组相关方法 +const addSubGroup = () => { + if (!trigger.value.conditionGroups) { + trigger.value.conditionGroups = [] + } + + // 检查是否达到最大子组数量限制 + if (trigger.value.conditionGroups?.length >= maxSubGroups) { + return + } + + // 使用 nextTick 确保响应式更新完成后再添加新的子组 + nextTick(() => { + if (trigger.value.conditionGroups) { + trigger.value.conditionGroups.push([]) + } + }) +} + +const removeSubGroup = (index: number) => { + if (trigger.value.conditionGroups) { + trigger.value.conditionGroups.splice(index, 1) + delete subGroupValidations.value[index] + + // 重新索引验证结果 + const newValidations: { [key: number]: { valid: boolean; message: string } } = {} + Object.keys(subGroupValidations.value).forEach((key) => { + const numKey = parseInt(key) + if (numKey > index) { + newValidations[numKey - 1] = subGroupValidations.value[numKey] + } else if (numKey < index) { + newValidations[numKey] = subGroupValidations.value[numKey] + } + }) + subGroupValidations.value = newValidations + + updateValidationResult() + } +} + +const updateSubGroup = (index: number, subGroup: any) => { + if (trigger.value.conditionGroups) { + trigger.value.conditionGroups[index] = subGroup + } +} + const removeConditionGroup = () => { trigger.value.conditionGroups = undefined } + +const handleSubGroupValidate = (index: number, result: { valid: boolean; message: string }) => { + subGroupValidations.value[index] = result + updateValidationResult() +} + +const updateValidationResult = () => { + if (!trigger.value.conditionGroups || trigger.value.conditionGroups.length === 0) { + emit('validate', { valid: true, message: '条件组容器为空,验证通过' }) + return + } + + const validations = Object.values(subGroupValidations.value) + const allValid = validations.every((v: any) => v.valid) + + if (allValid) { + emit('validate', { valid: true, message: '条件组容器配置验证通过' }) + } else { + const errorMessages = validations.filter((v: any) => !v.valid).map((v: any) => v.message) + emit('validate', { valid: false, message: `子条件组配置错误: ${errorMessages.join('; ')}` }) + } +} + +// 监听变化 +watch( + () => trigger.value.conditionGroups, + () => { + updateValidationResult() + }, + { deep: true, immediate: true } +)