【功能新增】IoT: 获取产品物模型 TSL
This commit is contained in:
@ -58,11 +58,10 @@ export const ThingModelApi = {
|
|||||||
return await request.get({ url: `/iot/thing-model/list`, params })
|
return await request.get({ url: `/iot/thing-model/list`, params })
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获得产品物模型
|
// 获得产品物模型 TSL
|
||||||
getThingModelListByProductId: async (params: any) => {
|
getThingModelTSLByProductId: async (productId: number) => {
|
||||||
return await request.get({
|
return await request.get({
|
||||||
url: `/iot/thing-model/list-by-product-id`,
|
url: `/iot/thing-model/tsl-by-product-id?productId=${productId}`
|
||||||
params
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -44,12 +44,15 @@
|
|||||||
>
|
>
|
||||||
<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="condition.type" class="!w-160px" clearable placeholder="">
|
<el-select v-model="condition.type" class="!w-160px" clearable placeholder="">
|
||||||
<el-option
|
<!-- <el-option-->
|
||||||
v-for="dict in getStrDictOptions(DICT_TYPE.IOT_DEVICE_MESSAGE_TYPE_ENUM)"
|
<!-- v-for="dict in getStrDictOptions(DICT_TYPE.IOT_DEVICE_MESSAGE_TYPE_ENUM)"-->
|
||||||
:key="dict.value"
|
<!-- :key="dict.value"-->
|
||||||
:label="dict.label"
|
<!-- :label="dict.label"-->
|
||||||
:value="dict.value"
|
<!-- :value="dict.value"-->
|
||||||
/>
|
<!-- />-->
|
||||||
|
<el-option label="属性" value="property" />
|
||||||
|
<el-option label="服务" value="service" />
|
||||||
|
<el-option label="事件" value="event" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
@ -57,6 +60,7 @@
|
|||||||
v-for="(parameter, index2) in condition.parameters"
|
v-for="(parameter, index2) in condition.parameters"
|
||||||
:key="index2"
|
:key="index2"
|
||||||
:model-value="parameter"
|
:model-value="parameter"
|
||||||
|
:thingModels="thingModels(condition)"
|
||||||
@update:model-value="(val) => (condition.parameters[index2] = val)"
|
@update:model-value="(val) => (condition.parameters[index2] = val)"
|
||||||
class="mb-10px last:mb-0"
|
class="mb-10px last:mb-0"
|
||||||
>
|
>
|
||||||
@ -107,11 +111,12 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Delete, Plus } from '@element-plus/icons-vue'
|
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 DeviceListenerCondition from './DeviceListenerCondition.vue'
|
||||||
import IoTProductTableSelect from '@/views/iot/product/product/components/IoTProductTableSelect.vue'
|
import IoTProductTableSelect from '@/views/iot/product/product/components/IoTProductTableSelect.vue'
|
||||||
import IoTDeviceTableSelect from '@/views/iot/device/device/components/IoTDeviceTableSelect.vue'
|
import IoTDeviceTableSelect from '@/views/iot/device/device/components/IoTDeviceTableSelect.vue'
|
||||||
import {
|
import {
|
||||||
|
IotRuleSceneTriggerCondition,
|
||||||
IotRuleSceneTriggerConditionParameter,
|
IotRuleSceneTriggerConditionParameter,
|
||||||
IotRuleSceneTriggerConfig
|
IotRuleSceneTriggerConfig
|
||||||
} from '@/api/iot/rule/scene/scene.types'
|
} 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 { DeviceVO } from '@/api/iot/device/device'
|
||||||
import { useVModel } from '@vueuse/core'
|
import { useVModel } from '@vueuse/core'
|
||||||
import { isEmpty } from '@/utils/is'
|
import { isEmpty } from '@/utils/is'
|
||||||
|
import { ThingModelApi } from '@/api/iot/thingmodel'
|
||||||
|
|
||||||
/** 场景联动之监听器组件 */
|
/** 场景联动之监听器组件 */
|
||||||
defineOptions({ name: 'DeviceListener' })
|
defineOptions({ name: 'DeviceListener' })
|
||||||
@ -161,6 +167,7 @@ const handleProductSelect = (val: ProductVO) => {
|
|||||||
product.value = val
|
product.value = val
|
||||||
triggerConfig.value.productKey = val.productKey
|
triggerConfig.value.productKey = val.productKey
|
||||||
deviceList.value = []
|
deviceList.value = []
|
||||||
|
getThingModelTSL()
|
||||||
}
|
}
|
||||||
/** 处理设备选择 */
|
/** 处理设备选择 */
|
||||||
const handleDeviceSelect = (val: DeviceVO[]) => {
|
const handleDeviceSelect = (val: DeviceVO[]) => {
|
||||||
@ -175,6 +182,26 @@ const openDeviceSelect = () => {
|
|||||||
}
|
}
|
||||||
deviceTableSelectRef.value?.open()
|
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>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@ -7,15 +7,15 @@
|
|||||||
placeholder="请选择物模型"
|
placeholder="请选择物模型"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="dict in getStrDictOptions(DICT_TYPE.IOT_DEVICE_MESSAGE_TYPE_ENUM)"
|
v-for="thingModel in thingModels"
|
||||||
:key="dict.value"
|
:key="thingModel.identifier"
|
||||||
:label="dict.label"
|
:label="thingModel.name"
|
||||||
:value="dict.value"
|
:value="thingModel.identifier"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
<ConditionSelector v-model="conditionParameter.operator" class="!w-180px mr-10px" />
|
<ConditionSelector v-model="conditionParameter.operator" class="!w-180px mr-10px" />
|
||||||
<el-input v-model="conditionParameter.value" class="!w-240px mr-10px" placeholder="请输入值">
|
<el-input v-model="conditionParameter.value" class="!w-240px mr-10px" placeholder="请输入值">
|
||||||
<template #append> 单位 </template>
|
<template #append> {{ getUnitName }} </template>
|
||||||
</el-input>
|
</el-input>
|
||||||
<!-- 按钮插槽 -->
|
<!-- 按钮插槽 -->
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
@ -25,17 +25,23 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ConditionSelector from './ConditionSelector.vue'
|
import ConditionSelector from './ConditionSelector.vue'
|
||||||
import { IotRuleSceneTriggerConditionParameter } from '@/api/iot/rule/scene/scene.types'
|
import { IotRuleSceneTriggerConditionParameter } from '@/api/iot/rule/scene/scene.types'
|
||||||
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
|
|
||||||
import { useVModel } from '@vueuse/core'
|
import { useVModel } from '@vueuse/core'
|
||||||
|
|
||||||
defineOptions({ name: 'DeviceListenerCondition' })
|
defineOptions({ name: 'DeviceListenerCondition' })
|
||||||
const props = defineProps<{ modelValue: any }>()
|
const props = defineProps<{ modelValue: any; thingModels: any }>()
|
||||||
const emits = defineEmits(['update:modelValue'])
|
const emits = defineEmits(['update:modelValue'])
|
||||||
const conditionParameter = useVModel(
|
const conditionParameter = useVModel(
|
||||||
props,
|
props,
|
||||||
'modelValue',
|
'modelValue',
|
||||||
emits
|
emits
|
||||||
) as Ref<IotRuleSceneTriggerConditionParameter>
|
) as Ref<IotRuleSceneTriggerConditionParameter>
|
||||||
|
|
||||||
|
/** 获得属性单位 */
|
||||||
|
const getUnitName = computed(
|
||||||
|
() =>
|
||||||
|
props.thingModels.find((item: any) => item.identifier === conditionParameter.value.identifier)
|
||||||
|
?.dataSpecs?.unitName || '单位'
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss"></style>
|
<style scoped lang="scss"></style>
|
||||||
|
|||||||
Reference in New Issue
Block a user