【功能完善】IoT: 场景联动产品设备信息回显

pull/757/head
puhui999 2025-03-29 12:07:27 +08:00
parent 5fa9e4e855
commit 6b99fdb41f
4 changed files with 136 additions and 7 deletions

View File

@ -165,5 +165,16 @@ export const DeviceApi = {
// 获取设备MQTT连接参数
getMqttConnectionParams: async (deviceId: number) => {
return await request.get({ url: `/iot/device/mqtt-connection-params`, params: { deviceId } })
},
// 根据ProductKey和DeviceNames获取设备列表
getDevicesByProductKeyAndNames: async (productKey: string, deviceNames: string[]) => {
return await request.get({
url: `/iot/device/get-by-product-key-and-names`,
params: {
productKey,
deviceNames: deviceNames.join(',')
}
})
}
}

View File

@ -78,5 +78,10 @@ export const ProductApi = {
// 查询产品(精简)列表
getSimpleProductList() {
return request.get({ url: '/iot/product/simple-list' })
},
// 根据ProductKey获取产品信息
getProductByKey: async (productKey: string) => {
return await request.get({ url: `/iot/product/get-by-key`, params: { productKey } })
}
}

View File

@ -1,6 +1,6 @@
<template>
<div class="m-10px">
<!-- TODO puhui999: 产品设备回显 -->
<!-- 产品设备回显区域 -->
<div class="relative bg-[#eff3f7] h-50px flex items-center px-10px">
<div class="flex items-center mr-60px">
<span class="mr-10px">执行动作</span>
@ -79,15 +79,14 @@
<script setup lang="ts">
import { useVModel } from '@vueuse/core'
import { isEmpty } from '@/utils/is'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import ProductTableSelect from '@/views/iot/product/product/components/ProductTableSelect.vue'
import DeviceTableSelect from '@/views/iot/device/device/components/DeviceTableSelect.vue'
import DeviceControlAction from './DeviceControlAction.vue'
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 { ProductApi, ProductVO } from '@/api/iot/product/product'
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
import {
ActionAlert,
ActionConfig,
@ -190,8 +189,61 @@ watch(
{ immediate: true }
)
/**
* 初始化产品回显信息
*/
const initProductInfo = async () => {
if (!actionConfig.value.deviceControl?.productKey) {
return
}
try {
// 使APIproductKey
const productData = await ProductApi.getProductByKey(
actionConfig.value.deviceControl.productKey
)
if (productData) {
product.value = productData
}
} catch (error) {
console.error('获取产品信息失败:', error)
}
}
/**
* 初始化设备回显信息
*/
const initDeviceInfo = async () => {
if (
!actionConfig.value.deviceControl?.productKey ||
!actionConfig.value.deviceControl?.deviceNames?.length
) {
return
}
try {
// 使APIproductKeydeviceNames
const deviceData = await DeviceApi.getDevicesByProductKeyAndNames(
actionConfig.value.deviceControl.productKey,
actionConfig.value.deviceControl.deviceNames
)
if (deviceData && deviceData.length > 0) {
deviceList.value = deviceData
}
} catch (error) {
console.error('获取设备信息失败:', error)
}
}
/** 初始化 */
onMounted(() => {
onMounted(async () => {
initActionConfig()
//
if (actionConfig.value.deviceControl) {
await initProductInfo()
await initDeviceInfo()
}
})
</script>

View File

@ -144,8 +144,8 @@ import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import DeviceListenerCondition from './DeviceListenerCondition.vue'
import ProductTableSelect from '@/views/iot/product/product/components/ProductTableSelect.vue'
import DeviceTableSelect from '@/views/iot/device/device/components/DeviceTableSelect.vue'
import { ProductVO } from '@/api/iot/product/product'
import { DeviceVO } from '@/api/iot/device/device'
import { ProductApi, ProductVO } from '@/api/iot/product/product'
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
import { ThingModelApi } from '@/api/iot/thingmodel'
import {
IotDeviceMessageIdentifierEnum,
@ -219,9 +219,56 @@ const openDeviceSelect = () => {
deviceTableSelectRef.value?.open()
}
/**
* 初始化产品回显信息
*/
const initProductInfo = async () => {
if (!triggerConfig.value.productKey) {
return
}
try {
// 使APIproductKey
const productData = await ProductApi.getProductByKey(triggerConfig.value.productKey)
if (productData) {
product.value = productData
//
await getThingModelTSL()
}
} catch (error) {
console.error('获取产品信息失败:', error)
}
}
/**
* 初始化设备回显信息
*/
const initDeviceInfo = async () => {
if (!triggerConfig.value.productKey || !triggerConfig.value.deviceNames?.length) {
return
}
try {
// 使APIproductKeydeviceNames
const deviceData = await DeviceApi.getDevicesByProductKeyAndNames(
triggerConfig.value.productKey,
triggerConfig.value.deviceNames
)
if (deviceData && deviceData.length > 0) {
deviceList.value = deviceData
}
} catch (error) {
console.error('获取设备信息失败:', error)
}
}
/** 获取产品物模型 */
const thingModelTSL = ref<any>()
const thingModels = computed(() => (condition: TriggerCondition) => {
if (isEmpty(thingModelTSL.value)) {
return []
}
switch (condition.type) {
case IotDeviceMessageTypeEnum.PROPERTY:
return thingModelTSL.value.properties
@ -239,4 +286,18 @@ const getThingModelTSL = async () => {
}
thingModelTSL.value = await ThingModelApi.getThingModelTSLByProductId(product.value.id)
}
/** 初始化 */
onMounted(async () => {
//
if (triggerConfig.value) {
// conditions
if (!triggerConfig.value.conditions) {
triggerConfig.value.conditions = []
}
await initProductInfo()
await initDeviceInfo()
}
})
</script>