From 1c4222de352418f8e08f46ec9c5a4667618afacc Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 15 Aug 2025 11:55:30 +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=E4=BC=98=E5=8C=96=E5=9C=BA=E6=99=AF=E8=81=94?= =?UTF-8?q?=E5=8A=A8=20review=20=E6=8F=90=E5=88=B0=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scene/form/configs/ConditionConfig.vue | 31 ++- .../form/configs/MainConditionInnerConfig.vue | 16 +- .../scene/form/inputs/JsonParamsInput.vue | 260 ++++++++---------- .../scene/form/sections/ActionSection.vue | 59 ++-- .../scene/form/sections/TriggerSection.vue | 15 +- .../scene/form/selectors/DeviceSelector.vue | 15 +- src/views/iot/utils/constants.ts | 161 +---------- 7 files changed, 223 insertions(+), 334 deletions(-) diff --git a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue index 36dc2f5aa..7cb9bdb26 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue @@ -63,7 +63,7 @@ class="w-full" > () +/** 获取设备状态选项 */ +const deviceStatusOptions = [ + { + value: IoTDeviceStatusEnum.ONLINE.value, + label: IoTDeviceStatusEnum.ONLINE.label + }, + { + value: IoTDeviceStatusEnum.OFFLINE.value, + label: IoTDeviceStatusEnum.OFFLINE.label + } +] + +/** 获取状态操作符选项 */ +const statusOperatorOptions = [ + { + value: IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.value, + label: IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.name + }, + { + value: IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_EQUALS.value, + label: IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_EQUALS.name + } +] + const condition = useVModel(props, 'modelValue', emit) const propertyType = ref('string') // 属性类型 diff --git a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue index 0b7c8f4a2..4c61d31e4 100644 --- a/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue +++ b/src/views/iot/rule/scene/form/configs/MainConditionInnerConfig.vue @@ -187,8 +187,8 @@ import { IotRuleSceneTriggerTypeEnum, triggerTypeOptions, getTriggerTypeLabel, - deviceStatusChangeOptions, - IotRuleSceneTriggerConditionParameterOperatorEnum + IotRuleSceneTriggerConditionParameterOperatorEnum, + IoTDeviceStatusEnum } from '@/views/iot/utils/constants' import { useVModel } from '@vueuse/core' @@ -205,6 +205,18 @@ const emit = defineEmits<{ (e: 'trigger-type-change', value: number): void }>() +/** 获取设备状态变更选项(用于触发器配置) */ +const deviceStatusChangeOptions = [ + { + label: IoTDeviceStatusEnum.ONLINE.label, + value: IoTDeviceStatusEnum.ONLINE.value + }, + { + label: IoTDeviceStatusEnum.OFFLINE.label, + value: IoTDeviceStatusEnum.OFFLINE.value + } +] + const condition = useVModel(props, 'modelValue', emit) const propertyType = ref('') // 属性类型 const propertyConfig = ref(null) // 属性配置 diff --git a/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue b/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue index ae93feed1..5bfa970d5 100644 --- a/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue +++ b/src/views/iot/rule/scene/form/inputs/JsonParamsInput.vue @@ -1,148 +1,139 @@ @@ -162,7 +153,7 @@ import { /** JSON参数输入组件 - 通用版本 */ defineOptions({ name: 'JsonParamsInput' }) -export interface JsonParamsConfig { +interface JsonParamsConfig { // 服务配置 service?: { name: string @@ -207,19 +198,6 @@ const localValue = useVModel(props, 'modelValue', emit, { const paramsJson = ref('') // JSON参数字符串 const jsonError = ref('') // JSON验证错误信息 -// 计算属性:是否有配置 -const hasConfig = computed(() => { - // TODO @puhui999: 后续统一处理 - console.log(props.config) - // return !!( - // props.config?.service || - // props.config?.event || - // props.config?.properties || - // props.config?.custom - // ) - return true -}) - // 计算属性:参数列表 const paramsList = computed(() => { switch (props.type) { diff --git a/src/views/iot/rule/scene/form/sections/ActionSection.vue b/src/views/iot/rule/scene/form/sections/ActionSection.vue index 416e803ef..b41e8cf77 100644 --- a/src/views/iot/rule/scene/form/sections/ActionSection.vue +++ b/src/views/iot/rule/scene/form/sections/ActionSection.vue @@ -6,15 +6,10 @@
执行器配置 - {{ actions.length }}/{{ maxActions }} + {{ actions.length }} 个执行器
- + 添加执行器 @@ -103,14 +98,14 @@
@@ -127,14 +122,11 @@
-
+
继续添加执行器 - - 最多可添加 {{ maxActions }} 个执行器 -
@@ -146,13 +138,9 @@ import DeviceControlConfig from '../configs/DeviceControlConfig.vue' import AlertConfig from '../configs/AlertConfig.vue' import type { Action } from '@/api/iot/rule/scene' import { - IotRuleSceneActionTypeEnum as ActionTypeEnum, - isDeviceAction, - isAlertAction, getActionTypeLabel, getActionTypeOptions, - getActionTypeTag, - SCENE_RULE_CONFIG + IotRuleSceneActionTypeEnum } from '@/views/iot/utils/constants' /** 执行器配置组件 */ @@ -168,7 +156,34 @@ const emit = defineEmits<{ const actions = useVModel(props, 'actions', emit) -const maxActions = SCENE_RULE_CONFIG.MAX_ACTIONS // 最大执行器数量 +/** 获取执行器标签类型(用于 el-tag 的 type 属性) */ +const getActionTypeTag = (type: number): 'primary' | 'success' | 'info' | 'warning' | 'danger' => { + const actionTypeTags = { + [IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET]: 'primary', + [IotRuleSceneActionTypeEnum.DEVICE_SERVICE_INVOKE]: 'success', + [IotRuleSceneActionTypeEnum.ALERT_TRIGGER]: 'danger', + [IotRuleSceneActionTypeEnum.ALERT_RECOVER]: 'warning' + } as const + return actionTypeTags[type] || 'info' +} + +/** 判断是否为设备执行器类型 */ +const isDeviceAction = (type: number): boolean => { + const deviceActionTypes = [ + IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET, + IotRuleSceneActionTypeEnum.DEVICE_SERVICE_INVOKE + ] as number[] + return deviceActionTypes.includes(type) +} + +/** 判断是否为告警执行器类型 */ +const isAlertAction = (type: number): boolean => { + const alertActionTypes = [ + IotRuleSceneActionTypeEnum.ALERT_TRIGGER, + IotRuleSceneActionTypeEnum.ALERT_RECOVER + ] as number[] + return alertActionTypes.includes(type) +} /** * 创建默认的执行器数据 @@ -176,7 +191,7 @@ const maxActions = SCENE_RULE_CONFIG.MAX_ACTIONS // 最大执行器数量 */ const createDefaultActionData = (): Action => { return { - type: ActionTypeEnum.DEVICE_PROPERTY_SET, // 默认为设备属性设置 + type: IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET, // 默认为设备属性设置 productId: undefined, deviceId: undefined, identifier: undefined, // 物模型标识符(服务调用时使用) @@ -189,10 +204,6 @@ const createDefaultActionData = (): Action => { * 添加执行器 */ const addAction = () => { - if (actions.value.length >= maxActions) { - return - } - const newAction = createDefaultActionData() actions.value.push(newAction) } diff --git a/src/views/iot/rule/scene/form/sections/TriggerSection.vue b/src/views/iot/rule/scene/form/sections/TriggerSection.vue index ce5438c69..144d53c66 100644 --- a/src/views/iot/rule/scene/form/sections/TriggerSection.vue +++ b/src/views/iot/rule/scene/form/sections/TriggerSection.vue @@ -67,7 +67,7 @@
{ + if (type === IotRuleSceneTriggerTypeEnum.TIMER) { + return 'warning' + } + return isDeviceTrigger(type) ? 'success' : 'info' +} + /** 添加触发器 */ const addTrigger = () => { const newTrigger: Trigger = { - type: TriggerTypeEnum.DEVICE_STATE_UPDATE, + type: IotRuleSceneTriggerTypeEnum.DEVICE_STATE_UPDATE, productId: undefined, deviceId: undefined, identifier: undefined, diff --git a/src/views/iot/rule/scene/form/selectors/DeviceSelector.vue b/src/views/iot/rule/scene/form/selectors/DeviceSelector.vue index 0f347acd4..0aa9cdd98 100644 --- a/src/views/iot/rule/scene/form/selectors/DeviceSelector.vue +++ b/src/views/iot/rule/scene/form/selectors/DeviceSelector.vue @@ -24,12 +24,7 @@
{{ device.deviceKey }}
- - {{ getDeviceEnableStatusText(device.status) }} - - - {{ getDeviceActiveStatus(device.activeTime).text }} - +
@@ -38,12 +33,8 @@