【功能新增】IoT: 获取产品物模型 TSL

This commit is contained in:
puhui999
2025-03-21 17:06:12 +08:00
parent a410fb40f6
commit 0743d372c2
3 changed files with 50 additions and 18 deletions

View File

@ -58,11 +58,10 @@ export const ThingModelApi = {
return await request.get({ url: `/iot/thing-model/list`, params })
},
// 获得产品物模型
getThingModelListByProductId: async (params: any) => {
// 获得产品物模型 TSL
getThingModelTSLByProductId: async (productId: number) => {
return await request.get({
url: `/iot/thing-model/list-by-product-id`,
params
url: `/iot/thing-model/tsl-by-product-id?productId=${productId}`
})
},

View File

@ -44,12 +44,15 @@
>
<div class="flex flex-col items-center justify-center mr-10px h-a">
<el-select v-model="condition.type" class="!w-160px" clearable placeholder="">
<el-option
v-for="dict in getStrDictOptions(DICT_TYPE.IOT_DEVICE_MESSAGE_TYPE_ENUM)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
<!-- <el-option-->
<!-- v-for="dict in getStrDictOptions(DICT_TYPE.IOT_DEVICE_MESSAGE_TYPE_ENUM)"-->
<!-- :key="dict.value"-->
<!-- :label="dict.label"-->
<!-- :value="dict.value"-->
<!-- />-->
<el-option label="属性" value="property" />
<el-option label="服务" value="service" />
<el-option label="事件" value="event" />
</el-select>
</div>
<div class="">
@ -57,6 +60,7 @@
v-for="(parameter, index2) in condition.parameters"
:key="index2"
:model-value="parameter"
:thingModels="thingModels(condition)"
@update:model-value="(val) => (condition.parameters[index2] = val)"
class="mb-10px last:mb-0"
>
@ -107,11 +111,12 @@
<script setup lang="ts">
import { Delete, Plus } from '@element-plus/icons-vue'
import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import DeviceListenerCondition from './DeviceListenerCondition.vue'
import IoTProductTableSelect from '@/views/iot/product/product/components/IoTProductTableSelect.vue'
import IoTDeviceTableSelect from '@/views/iot/device/device/components/IoTDeviceTableSelect.vue'
import {
IotRuleSceneTriggerCondition,
IotRuleSceneTriggerConditionParameter,
IotRuleSceneTriggerConfig
} from '@/api/iot/rule/scene/scene.types'
@ -119,6 +124,7 @@ import { ProductVO } from '@/api/iot/product/product'
import { DeviceVO } from '@/api/iot/device/device'
import { useVModel } from '@vueuse/core'
import { isEmpty } from '@/utils/is'
import { ThingModelApi } from '@/api/iot/thingmodel'
/** 场景联动之监听器组件 */
defineOptions({ name: 'DeviceListener' })
@ -161,6 +167,7 @@ const handleProductSelect = (val: ProductVO) => {
product.value = val
triggerConfig.value.productKey = val.productKey
deviceList.value = []
getThingModelTSL()
}
/** 处理设备选择 */
const handleDeviceSelect = (val: DeviceVO[]) => {
@ -175,6 +182,26 @@ const openDeviceSelect = () => {
}
deviceTableSelectRef.value?.open()
}
/** 获取产品物模型 */
const thingModelTSL = ref<any>()
const thingModels = computed(() => (condition: IotRuleSceneTriggerCondition) => {
switch (condition.type) {
case 'property':
return thingModelTSL.value.properties
case 'service':
return thingModelTSL.value.service
case 'event':
return thingModelTSL.value.event
}
return []
})
const getThingModelTSL = async () => {
if (!product.value) {
return
}
thingModelTSL.value = await ThingModelApi.getThingModelTSLByProductId(product.value.id)
}
</script>
<style lang="scss" scoped>

View File

@ -7,15 +7,15 @@
placeholder="请选择物模型"
>
<el-option
v-for="dict in getStrDictOptions(DICT_TYPE.IOT_DEVICE_MESSAGE_TYPE_ENUM)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
v-for="thingModel in thingModels"
:key="thingModel.identifier"
:label="thingModel.name"
:value="thingModel.identifier"
/>
</el-select>
<ConditionSelector v-model="conditionParameter.operator" class="!w-180px mr-10px" />
<el-input v-model="conditionParameter.value" class="!w-240px mr-10px" placeholder="请输入值">
<template #append> 单位 </template>
<template #append> {{ getUnitName }} </template>
</el-input>
<!-- 按钮插槽 -->
<slot></slot>
@ -25,17 +25,23 @@
<script setup lang="ts">
import ConditionSelector from './ConditionSelector.vue'
import { IotRuleSceneTriggerConditionParameter } from '@/api/iot/rule/scene/scene.types'
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
import { useVModel } from '@vueuse/core'
defineOptions({ name: 'DeviceListenerCondition' })
const props = defineProps<{ modelValue: any }>()
const props = defineProps<{ modelValue: any; thingModels: any }>()
const emits = defineEmits(['update:modelValue'])
const conditionParameter = useVModel(
props,
'modelValue',
emits
) as Ref<IotRuleSceneTriggerConditionParameter>
/** 获得属性单位 */
const getUnitName = computed(
() =>
props.thingModels.find((item: any) => item.identifier === conditionParameter.value.identifier)
?.dataSpecs?.unitName || '单位'
)
</script>
<style scoped lang="scss"></style>