From 04cfded36faad82a96423fefe25222b339cac1a4 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 29 Mar 2025 14:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91IoT:=20=E5=9C=BA=E6=99=AF=E8=81=94=E5=8A=A8=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=99=A8=E8=AE=BE=E5=A4=87=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/action/ActionExecutor.vue | 1 + .../components/action/DeviceControlAction.vue | 23 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/views/iot/rule/scene/components/action/ActionExecutor.vue b/src/views/iot/rule/scene/components/action/ActionExecutor.vue index 83cc99f1b..3fa708190 100644 --- a/src/views/iot/rule/scene/components/action/ActionExecutor.vue +++ b/src/views/iot/rule/scene/components/action/ActionExecutor.vue @@ -49,6 +49,7 @@ v-if="actionConfig.type === IotRuleSceneActionTypeEnum.DEVICE_CONTROL" :model-value="actionConfig.deviceControl" :product-id="product?.id" + :product-key="product?.productKey" @update:model-value="(val) => (actionConfig.deviceControl = val)" /> diff --git a/src/views/iot/rule/scene/components/action/DeviceControlAction.vue b/src/views/iot/rule/scene/components/action/DeviceControlAction.vue index 4b4fe84aa..6bd1528fe 100644 --- a/src/views/iot/rule/scene/components/action/DeviceControlAction.vue +++ b/src/views/iot/rule/scene/components/action/DeviceControlAction.vue @@ -80,6 +80,7 @@ defineOptions({ name: 'DeviceControlAction' }) const props = defineProps<{ modelValue: any productId?: number + productKey?: string }>() const emits = defineEmits(['update:modelValue']) const deviceControlConfig = useVModel(props, 'modelValue', emits) as Ref @@ -169,11 +170,7 @@ const getThingModelTSL = async () => { if (!props.productId) { return } - try { - thingModelTSL.value = await ThingModelApi.getThingModelTSLByProductId(props.productId) - } catch (error) { - console.error('获取物模型失败', error) - } + thingModelTSL.value = await ThingModelApi.getThingModelTSLByProductId(props.productId) } const thingModels = computed(() => (identifier?: string): any[] => { if (isEmpty(thingModelTSL.value)) { @@ -183,8 +180,7 @@ const thingModels = computed(() => (identifier?: string): any[] => { case IotDeviceMessageTypeEnum.PROPERTY: return thingModelTSL.value?.properties || [] case IotDeviceMessageTypeEnum.SERVICE: - // TODO puhui999: 要限制只过滤出 set 类型的 service 吗? - const service = thingModelTSL.value.services.find( + const service = thingModelTSL.value.services?.find( (item: any) => item.identifier === identifier ) return service?.inputParams || [] @@ -200,23 +196,22 @@ const getUnitName = computed(() => (identifier: string) => { if (model?.dataSpecs) { return model.dataSpecs.unitName } + // TODO puhui999: enum、bool、struct 类型数据处理 return '' }) /** 监听 productId 变化 */ watch( () => props.productId, - (newVal) => { - if (!newVal) { - thingModelTSL.value = undefined - parameters.value = [] + () => { + getThingModelTSL() + if (deviceControlConfig.value && deviceControlConfig.value.productKey === props.productKey) { return } - getThingModelTSL() // 当产品ID变化时,清空原有数据 deviceControlConfig.value.data = {} - }, - { immediate: true } + parameters.value = [] + } ) /** 监听消息类型变化 */