feat:【IoT 物联网】场景联动执行器优化对齐后端

This commit is contained in:
puhui999
2025-07-01 21:04:40 +08:00
parent 508de312b3
commit 18758628f1
3 changed files with 90 additions and 28 deletions

View File

@ -19,19 +19,13 @@
/> />
</el-select> </el-select>
</div> </div>
<div <div v-if="isDeviceAction" class="flex items-center mr-60px">
v-if="actionConfig.type === IotRuleSceneActionTypeEnum.DEVICE_CONTROL"
class="flex items-center mr-60px"
>
<span class="mr-10px">产品</span> <span class="mr-10px">产品</span>
<el-button type="primary" @click="handleSelectProduct" size="small" plain> <el-button type="primary" @click="handleSelectProduct" size="small" plain>
{{ product ? product.name : '选择产品' }} {{ product ? product.name : '选择产品' }}
</el-button> </el-button>
</div> </div>
<div <div v-if="isDeviceAction" class="flex items-center mr-60px">
v-if="actionConfig.type === IotRuleSceneActionTypeEnum.DEVICE_CONTROL"
class="flex items-center mr-60px"
>
<span class="mr-10px">设备</span> <span class="mr-10px">设备</span>
<el-button type="primary" @click="handleSelectDevice" size="small" plain> <el-button type="primary" @click="handleSelectDevice" size="small" plain>
{{ isEmpty(deviceList) ? '选择设备' : deviceList.map((d) => d.deviceName).join(',') }} {{ isEmpty(deviceList) ? '选择设备' : deviceList.map((d) => d.deviceName).join(',') }}
@ -47,7 +41,8 @@
<!-- 设备控制执行器 --> <!-- 设备控制执行器 -->
<DeviceControlAction <DeviceControlAction
v-if="actionConfig.type === IotRuleSceneActionTypeEnum.DEVICE_CONTROL" v-if="isDeviceAction"
:action-type="actionConfig.type"
:model-value="actionConfig.deviceControl" :model-value="actionConfig.deviceControl"
:product-id="product?.id" :product-id="product?.id"
:product-key="product?.productKey" :product-key="product?.productKey"
@ -56,7 +51,8 @@
<!-- 告警执行器 --> <!-- 告警执行器 -->
<AlertAction <AlertAction
v-else-if="actionConfig.type === IotRuleSceneActionTypeEnum.ALERT" v-else-if="isAlertAction"
:action-type="actionConfig.type"
:model-value="actionConfig.alert" :model-value="actionConfig.alert"
@update:model-value="(val) => (actionConfig.alert = val)" @update:model-value="(val) => (actionConfig.alert = val)"
/> />
@ -101,28 +97,47 @@ const actionConfig = useVModel(props, 'modelValue', emits) as Ref<ActionConfig>
const message = useMessage() const message = useMessage()
/** 计算属性:判断是否为设备相关执行类型 */
const isDeviceAction = computed(() => {
return [
IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET,
IotRuleSceneActionTypeEnum.DEVICE_SERVICE_INVOKE
].includes(actionConfig.value.type as any)
})
/** 计算属性:判断是否为告警相关执行类型 */
const isAlertAction = computed(() => {
return [
IotRuleSceneActionTypeEnum.ALERT_TRIGGER,
IotRuleSceneActionTypeEnum.ALERT_RECOVER
].includes(actionConfig.value.type as any)
})
/** 初始化执行器结构 */ /** 初始化执行器结构 */
const initActionConfig = () => { const initActionConfig = () => {
if (!actionConfig.value) { if (!actionConfig.value) {
actionConfig.value = { type: IotRuleSceneActionTypeEnum.DEVICE_CONTROL } as ActionConfig actionConfig.value = { type: IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET } as ActionConfig
} }
// 设备控制执行器初始化 // 设备控制执行器初始化
if ( if (isDeviceAction.value && !actionConfig.value.deviceControl) {
actionConfig.value.type === IotRuleSceneActionTypeEnum.DEVICE_CONTROL &&
!actionConfig.value.deviceControl
) {
actionConfig.value.deviceControl = { actionConfig.value.deviceControl = {
productKey: '', productKey: '',
deviceNames: [], deviceNames: [],
type: IotDeviceMessageTypeEnum.PROPERTY, type:
identifier: IotDeviceMessageIdentifierEnum.PROPERTY_SET, actionConfig.value.type === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET
? IotDeviceMessageTypeEnum.PROPERTY
: IotDeviceMessageTypeEnum.SERVICE,
identifier:
actionConfig.value.type === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET
? IotDeviceMessageIdentifierEnum.PROPERTY_SET
: IotDeviceMessageIdentifierEnum.SERVICE_INVOKE,
data: {} data: {}
} as ActionDeviceControl } as ActionDeviceControl
} }
// 告警执行器初始化 // 告警执行器初始化
if (actionConfig.value.type === IotRuleSceneActionTypeEnum.ALERT && !actionConfig.value.alert) { if (isAlertAction.value && !actionConfig.value.alert) {
actionConfig.value.alert = {} as ActionAlert actionConfig.value.alert = {} as ActionAlert
} }
} }

View File

@ -1,5 +1,15 @@
<template> <template>
<div class="bg-[#dbe5f6] p-10px"> <div class="bg-[#dbe5f6] p-10px">
<!-- 告警类型说明 -->
<div class="flex items-center mb-10px" v-if="actionType">
<el-icon class="mr-5px text-orange-500"><Icon icon="ep:warning-filled" /></el-icon>
<span class="text-gray-600">
{{
actionType === IotRuleSceneActionTypeEnum.ALERT_TRIGGER ? '触发告警通知' : '告警恢复通知'
}}
</span>
</div>
<div class="flex items-center mb-10px"> <div class="flex items-center mb-10px">
<span class="mr-10px w-80px">接收方式</span> <span class="mr-10px w-80px">接收方式</span>
<el-select <el-select
@ -63,12 +73,19 @@
<script setup lang="ts"> <script setup lang="ts">
import { useVModel } from '@vueuse/core' import { useVModel } from '@vueuse/core'
import { ActionAlert, IotAlertConfigReceiveTypeEnum } from '@/api/iot/rule/scene/scene.types' import {
ActionAlert,
IotAlertConfigReceiveTypeEnum,
IotRuleSceneActionTypeEnum
} from '@/api/iot/rule/scene/scene.types'
/** 告警执行器组件 */ /** 告警执行器组件 */
defineOptions({ name: 'AlertAction' }) defineOptions({ name: 'AlertAction' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{
modelValue: any
actionType?: number
}>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])
const alertConfig = useVModel(props, 'modelValue', emits) as Ref<ActionAlert> const alertConfig = useVModel(props, 'modelValue', emits) as Ref<ActionAlert>

View File

@ -1,7 +1,13 @@
<template> <template>
<div class="bg-[#dbe5f6] flex p-10px"> <div class="bg-[#dbe5f6] flex p-10px">
<div class="flex flex-col items-center justify-center mr-10px h-a"> <div class="flex flex-col items-center justify-center mr-10px h-a">
<el-select v-model="deviceControlConfig.type" class="!w-160px" clearable placeholder=""> <el-select
v-model="deviceControlConfig.type"
disabled
class="!w-160px"
clearable
placeholder=""
>
<el-option label="属性" :value="IotDeviceMessageTypeEnum.PROPERTY" /> <el-option label="属性" :value="IotDeviceMessageTypeEnum.PROPERTY" />
<el-option label="服务" :value="IotDeviceMessageTypeEnum.SERVICE" /> <el-option label="服务" :value="IotDeviceMessageTypeEnum.SERVICE" />
</el-select> </el-select>
@ -74,7 +80,8 @@ import { ThingModelApi } from '@/api/iot/thingmodel'
import { import {
ActionDeviceControl, ActionDeviceControl,
IotDeviceMessageIdentifierEnum, IotDeviceMessageIdentifierEnum,
IotDeviceMessageTypeEnum IotDeviceMessageTypeEnum,
IotRuleSceneActionTypeEnum
} from '@/api/iot/rule/scene/scene.types' } from '@/api/iot/rule/scene/scene.types'
import ThingModelParamInput from '../ThingModelParamInput.vue' import ThingModelParamInput from '../ThingModelParamInput.vue'
@ -83,6 +90,7 @@ defineOptions({ name: 'DeviceControlAction' })
const props = defineProps<{ const props = defineProps<{
modelValue: any modelValue: any
actionType: number
productId?: number productId?: number
productKey?: string productKey?: string
}>() }>()
@ -98,10 +106,6 @@ const addParameter = () => {
message.warning('请先选择一个产品') message.warning('请先选择一个产品')
return return
} }
if (parameters.value.length >= thingModels.value().length) {
message.warning(`该产品只有${thingModels.value().length}个物模型!!!`)
return
}
parameters.value.push({ identifier: '', value: undefined }) parameters.value.push({ identifier: '', value: undefined })
} }
const removeParameter = (index: number) => { const removeParameter = (index: number) => {
@ -140,8 +144,14 @@ const initDeviceControlConfig = () => {
deviceControlConfig.value = { deviceControlConfig.value = {
productKey: '', productKey: '',
deviceNames: [], deviceNames: [],
type: IotDeviceMessageTypeEnum.PROPERTY, type:
identifier: IotDeviceMessageIdentifierEnum.PROPERTY_SET, props.actionType === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET
? IotDeviceMessageTypeEnum.PROPERTY
: IotDeviceMessageTypeEnum.SERVICE,
identifier:
props.actionType === IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET
? IotDeviceMessageIdentifierEnum.PROPERTY_SET
: IotDeviceMessageIdentifierEnum.SERVICE_INVOKE,
data: {} data: {}
} as ActionDeviceControl } as ActionDeviceControl
} else { } 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( watch(
() => deviceControlConfig.value.type, () => deviceControlConfig.value.type,