From d06835ae7f3c9c9c2b459681cae17796fa3c96cc Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 1 Aug 2025 23:15:38 +0800 Subject: [PATCH] =?UTF-8?q?perf=EF=BC=9A=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=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/rule/scene/form/RuleSceneForm.vue | 64 +++++++---------- .../scene/form/configs/ConditionConfig.vue | 10 +-- .../configs/ConditionGroupContainerConfig.vue | 46 +++++------- .../configs/DeviceStatusConditionConfig.vue | 12 ++-- .../form/configs/DeviceTriggerConfig.vue | 72 +++++-------------- .../form/configs/SubConditionGroupConfig.vue | 49 +++++-------- .../scene/form/sections/TriggerSection.vue | 41 +++-------- src/views/iot/rule/scene/index.vue | 2 +- 8 files changed, 104 insertions(+), 192 deletions(-) diff --git a/src/views/iot/rule/scene/form/RuleSceneForm.vue b/src/views/iot/rule/scene/form/RuleSceneForm.vue index 5f565024f..b765f230d 100644 --- a/src/views/iot/rule/scene/form/RuleSceneForm.vue +++ b/src/views/iot/rule/scene/form/RuleSceneForm.vue @@ -39,14 +39,7 @@ import { useVModel } from '@vueuse/core' import BasicInfoSection from './sections/BasicInfoSection.vue' import TriggerSection from './sections/TriggerSection.vue' import ActionSection from './sections/ActionSection.vue' -import { - IotRuleScene, - IotRuleSceneDO, - IotRuleSceneActionTypeEnum, - RuleSceneFormData, - TriggerFormData, - TriggerConditionFormData -} from '@/api/iot/rule/scene/scene.types' +import { IotRuleSceneDO, RuleSceneFormData } from '@/api/iot/rule/scene/scene.types' import { IotRuleSceneTriggerTypeEnum } from '@/views/iot/utils/constants' import { ElMessage } from 'element-plus' import { generateUUID } from '@/utils' @@ -64,16 +57,12 @@ defineOptions({ name: 'RuleSceneForm' }) const props = defineProps<{ /** 抽屉显示状态 */ modelValue: boolean - /** 编辑的规则数据(新增时为空) */ - ruleScene?: IotRuleScene }>() /** 组件事件定义 */ const emit = defineEmits<{ - /** 更新抽屉显示状态 */ - 'update:modelValue': [value: boolean] - /** 操作成功事件 */ - success: [] + (e: 'update:modelValue', value: boolean): void + (e: 'success'): void }>() const drawerVisible = useVModel(props, 'modelValue', emit) // 是否可见 @@ -120,13 +109,14 @@ const convertFormToVO = (formData: RuleSceneFormData): IotRuleSceneDO => { cronExpression: trigger.cronExpression, conditionGroups: trigger.conditionGroups || [] })), - actions: formData.actions?.map((action) => ({ - type: action.type, - productId: action.productId, - deviceId: action.deviceId, - params: action.params, - alertConfigId: action.alertConfigId - })) || [] + actions: + formData.actions?.map((action) => ({ + type: action.type, + productId: action.productId, + deviceId: action.deviceId, + params: action.params, + alertConfigId: action.alertConfigId + })) || [] } } @@ -216,7 +206,7 @@ const triggerValidation = ref({ valid: true, message: '' }) const actionValidation = ref({ valid: true, message: '' }) // 计算属性 -const isEdit = computed(() => !!props.ruleScene?.id) +const isEdit = ref(false) const drawerTitle = computed(() => (isEdit.value ? '编辑场景联动规则' : '新增场景联动规则')) // 事件处理 @@ -284,30 +274,28 @@ const handleClose = () => { /** 初始化表单数据 */ const initFormData = () => { - if (props.ruleScene) { - formData.value = convertVOToForm(props.ruleScene) - } else { - formData.value = createDefaultFormData() - } + // TODO @puhui999: 编辑的情况后面实现 + formData.value = createDefaultFormData() } // 监听抽屉显示 watch(drawerVisible, (visible) => { if (visible) { initFormData() - nextTick(() => { - formRef.value?.clearValidate() - }) + // TODO @puhui999: 重置表单的情况 + // nextTick(() => { + // formRef.value?.clearValidate() + // }) } }) // 监听 props 变化 -watch( - () => props.ruleScene, - () => { - if (drawerVisible.value) { - initFormData() - } - } -) +// watch( +// () => props.ruleScene, +// () => { +// if (drawerVisible.value) { +// initFormData() +// } +// } +// ) diff --git a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue index 79c580b7c..95bf1ab50 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue @@ -122,7 +122,7 @@ import PropertySelector from '../selectors/PropertySelector.vue' import OperatorSelector from '../selectors/OperatorSelector.vue' import ValueInput from '../inputs/ValueInput.vue' import { - ConditionFormData, + TriggerConditionFormData, IotRuleSceneTriggerConditionTypeEnum } from '@/api/iot/rule/scene/scene.types' @@ -130,12 +130,12 @@ import { defineOptions({ name: 'ConditionConfig' }) const props = defineProps<{ - modelValue: ConditionFormData + modelValue: TriggerConditionFormData triggerType: number }>() const emit = defineEmits<{ - (e: 'update:modelValue', value: ConditionFormData): void + (e: 'update:modelValue', value: TriggerConditionFormData): void (e: 'validate', result: { valid: boolean; message: string }): void }>() @@ -152,12 +152,12 @@ const isValid = ref(true) const valueValidation = ref({ valid: true, message: '' }) // 事件处理 -const updateConditionField = (field: keyof ConditionFormData, value: any) => { +const updateConditionField = (field: keyof TriggerConditionFormData, value: any) => { ;(condition.value as any)[field] = value emit('update:modelValue', condition.value) } -const updateCondition = (newCondition: ConditionFormData) => { +const updateCondition = (newCondition: TriggerConditionFormData) => { condition.value = newCondition emit('update:modelValue', condition.value) } diff --git a/src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue index 8ad0b1144..caa2ec9b2 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionGroupContainerConfig.vue @@ -14,16 +14,14 @@ 附加条件组 与主条件为且关系 - - {{ modelValue.subGroups?.length || 0 }}个子条件组 - + {{ modelValue?.length || 0 }}个子条件组
添加子条件组 @@ -36,11 +34,11 @@
-
+
@@ -88,7 +86,7 @@
@@ -125,21 +123,17 @@