【功能完善】IoT: 场景联动执行器配置

This commit is contained in:
puhui999
2025-03-28 17:22:52 +08:00
parent eadf26dc3b
commit c06f7f9ebd
4 changed files with 163 additions and 456 deletions

View File

@ -22,7 +22,7 @@
class="flex items-center mr-60px"
>
<span class="mr-10px">产品</span>
<el-button type="primary" @click="productTableSelectRef?.open()" size="small" plain>
<el-button type="primary" @click="handleSelectProduct" size="small" plain>
{{ product ? product.name : '选择产品' }}
</el-button>
</div>
@ -31,8 +31,8 @@
class="flex items-center mr-60px"
>
<span class="mr-10px">设备</span>
<el-button type="primary" @click="openDeviceSelect" size="small" plain>
{{ isEmpty(deviceList) ? '选择设备' : actionConfig.deviceControl?.deviceNames.join(',') }}
<el-button type="primary" @click="handleSelectDevice" size="small" plain>
{{ isEmpty(deviceList) ? '选择设备' : deviceList.map(d => d.deviceName).join(',') }}
</el-button>
</div>
<!-- 删除执行器 -->
@ -47,6 +47,7 @@
<DeviceControlAction
v-if="actionConfig.type === IotRuleSceneActionTypeEnum.DEVICE_CONTROL"
:model-value="actionConfig.deviceControl"
:product-id="product?.id"
@update:model-value="(val) => (actionConfig.deviceControl = val)"
/>
@ -86,12 +87,13 @@ import AlertAction from './AlertAction.vue'
import DataBridgeAction from './DataBridgeAction.vue'
import { ProductVO } from '@/api/iot/product/product'
import { DeviceVO } from '@/api/iot/device/device'
import { ThingModelApi } from '@/api/iot/thingmodel'
import {
ActionAlert,
ActionConfig,
ActionDeviceControl,
IotRuleSceneActionTypeEnum
IotRuleSceneActionTypeEnum,
IotDeviceMessageTypeEnum,
IotDeviceMessageIdentifierEnum
} from '@/api/iot/rule/scene/scene.types'
/** 场景联动之执行器组件 */
@ -114,7 +116,13 @@ const initActionConfig = () => {
actionConfig.value.type === IotRuleSceneActionTypeEnum.DEVICE_CONTROL &&
!actionConfig.value.deviceControl
) {
actionConfig.value.deviceControl = {} as ActionDeviceControl
actionConfig.value.deviceControl = {
productKey: '',
deviceNames: [],
type: IotDeviceMessageTypeEnum.PROPERTY,
identifier: IotDeviceMessageIdentifierEnum.PROPERTY_SET,
data: {}
} as ActionDeviceControl
}
// 告警执行器初始化
@ -146,22 +154,13 @@ const deviceTableSelectRef = ref<InstanceType<typeof DeviceTableSelect>>()
const product = ref<ProductVO>()
const deviceList = ref<DeviceVO[]>([])
/** 处理产品选择 */
const handleProductSelect = (val: ProductVO) => {
product.value = val
actionConfig.value.deviceControl!.productKey = val.productKey
deviceList.value = []
getThingModelTSL()
/** 处理选择产品 */
const handleSelectProduct = () => {
productTableSelectRef.value?.open()
}
/** 处理设备选择 */
const handleDeviceSelect = (val: DeviceVO[]) => {
deviceList.value = val
actionConfig.value.deviceControl!.deviceNames = val.map((item) => item.deviceName)
}
/** 打开设备选择器 */
const openDeviceSelect = () => {
/** 处理选择设备 */
const handleSelectDevice = () => {
if (!product.value) {
message.warning('请先选择一个产品')
return
@ -169,12 +168,24 @@ const openDeviceSelect = () => {
deviceTableSelectRef.value?.open()
}
/** 获取产品物模型 */
const thingModelTSL = ref<any>()
const getThingModelTSL = async () => {
if (!product.value) {
return
/** 处理产品选择成功 */
const handleProductSelect = (val: ProductVO) => {
product.value = val
if (actionConfig.value.deviceControl) {
actionConfig.value.deviceControl.productKey = val.productKey
}
// 重置设备选择
deviceList.value = []
if (actionConfig.value.deviceControl) {
actionConfig.value.deviceControl.deviceNames = []
}
}
/** 处理设备选择成功 */
const handleDeviceSelect = (val: DeviceVO[]) => {
deviceList.value = val
if (actionConfig.value.deviceControl) {
actionConfig.value.deviceControl.deviceNames = val.map((item) => item.deviceName)
}
thingModelTSL.value = await ThingModelApi.getThingModelTSLByProductId(product.value.id)
}
</script>