-
+
@@ -74,7 +80,8 @@ import { ThingModelApi } from '@/api/iot/thingmodel'
import {
ActionDeviceControl,
IotDeviceMessageIdentifierEnum,
- IotDeviceMessageTypeEnum
+ IotDeviceMessageTypeEnum,
+ IotRuleSceneActionTypeEnum
} from '@/api/iot/rule/scene/scene.types'
import ThingModelParamInput from '../ThingModelParamInput.vue'
@@ -83,6 +90,7 @@ defineOptions({ name: 'DeviceControlAction' })
const props = defineProps<{
modelValue: any
+ actionType: number
productId?: number
productKey?: string
}>()
@@ -98,10 +106,6 @@ const addParameter = () => {
message.warning('请先选择一个产品')
return
}
- if (parameters.value.length >= thingModels.value().length) {
- message.warning(`该产品只有${thingModels.value().length}个物模型!!!`)
- return
- }
parameters.value.push({ identifier: '', value: undefined })
}
const removeParameter = (index: number) => {
@@ -140,8 +144,14 @@ const initDeviceControlConfig = () => {
deviceControlConfig.value = {
productKey: '',
deviceNames: [],
- type: IotDeviceMessageTypeEnum.PROPERTY,
- identifier: IotDeviceMessageIdentifierEnum.PROPERTY_SET,
+ type:
+ props.actionType === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET
+ ? IotDeviceMessageTypeEnum.PROPERTY
+ : IotDeviceMessageTypeEnum.SERVICE,
+ identifier:
+ props.actionType === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET
+ ? IotDeviceMessageIdentifierEnum.PROPERTY_SET
+ : IotDeviceMessageIdentifierEnum.SERVICE_INVOKE,
data: {}
} as ActionDeviceControl
} else {
@@ -208,6 +218,26 @@ watch(
}
)
+/** 监听执行类型变化 */
+watch(
+ () => props.actionType,
+ (val: any) => {
+ if (!val) {
+ return
+ }
+ // 切换执行类型时清空参数
+ deviceControlConfig.value.data = {}
+ parameters.value = []
+ if (val === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET) {
+ deviceControlConfig.value.type = IotDeviceMessageTypeEnum.PROPERTY
+ deviceControlConfig.value.identifier = IotDeviceMessageIdentifierEnum.PROPERTY_SET
+ } else if (val === IotRuleSceneActionTypeEnum.DEVICE_SERVICE_INVOKE) {
+ deviceControlConfig.value.type = IotDeviceMessageTypeEnum.SERVICE
+ deviceControlConfig.value.identifier = IotDeviceMessageIdentifierEnum.SERVICE_INVOKE
+ }
+ }
+)
+
/** 监听消息类型变化 */
watch(
() => deviceControlConfig.value.type,