【功能新增】IOT: ThingModel 服务和事件

pull/628/head
puhui999 2024-12-25 18:35:37 +08:00
parent 9bd96a3d63
commit d7c33b454f
9 changed files with 186 additions and 568 deletions

View File

@ -11,7 +11,7 @@ export interface ThingModelData {
productId?: number // 产品编号
productKey?: string // 产品标识
dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致
type: ProductFunctionTypeEnum // 功能类型
type: number // 功能类型
property: ThingModelProperty // 属性
event?: ThingModelEvent // 事件
service?: ThingModelService // 服务
@ -38,18 +38,58 @@ export interface ThingModelService {
[key: string]: any
}
// IOT 产品功能(物模型类型枚举类
export enum ProductFunctionTypeEnum {
PROPERTY = 1, // 属性
SERVICE = 2, // 服务
EVENT = 3 // 事件
}
// IOT 产品物模型类型枚举类
export const ThingModelType = {
PROPERTY: 1, // 属性
SERVICE: 2, // 服务
EVENT: 3 // 事件
} as const
// IOT 产品功能(物模型)访问模式枚举类
export enum ProductFunctionAccessModeEnum {
READ_WRITE = 'rw', // 读写
READ_ONLY = 'r' // 只读
}
// IOT 产品物模型访问模式枚举类
export const ThingModelAccessMode = {
READ_WRITE: {
label: '读写',
value: 'rw'
},
READ_ONLY: {
label: '只读',
value: 'r'
}
} as const
// IOT 产品物模型服务调用方式枚举
export const ThingModelServiceCallType = {
ASYNC: {
label: '异步调用',
value: 'async'
},
SYNC: {
label: '同步调用',
value: 'sync'
}
} as const
// IOT 产品物模型事件类型枚举
export const ThingModelServiceEventType = {
INFO: {
label: '信息',
value: 'info'
},
ALERT: {
label: '告警',
value: 'alert'
},
ERROR: {
label: '故障',
value: 'error'
}
} as const
// IOT 产品物模型参数是输入参数还是输出参数
export const ThingModelParamDirection = {
INPUT: 'input', // 输入参数
OUTPUT: 'output' // 输出参数
} as const
// IoT 产品物模型 API
export const ThingModelApi = {

View File

@ -238,7 +238,7 @@ export enum DICT_TYPE {
IOT_DEVICE_STATUS = 'iot_device_status', // IOT 设备状态
IOT_PRODUCT_THING_MODEL_TYPE = 'iot_product_thing_model_type', // IOT 产品功能类型
IOT_DATA_TYPE = 'iot_data_type', // IOT 数据类型
IOT_UNIT_TYPE = 'iot_unit_type', // IOT 单位类型
IOT_PRODUCT_THING_MODEL_UNIT = 'iot_product_thing_model_unit', // IOT 物模型单位
IOT_RW_TYPE = 'iot_rw_type', // IOT 读写类型
IOT_PLUGIN_DEPLOY_TYPE = 'iot_plugin_deploy_type', // IOT 插件部署类型
IOT_PLUGIN_STATUS = 'iot_plugin_status', // IOT 插件状态

View File

@ -0,0 +1,39 @@
<template>
<el-form-item
:rules="[{ required: true, message: '请选择事件类型', trigger: 'change' }]"
label="事件类型"
prop="thingModelEvent.type"
>
<el-radio-group v-model="thingModelEvent.type">
<el-radio :value="ThingModelServiceEventType.INFO.value">
{{ ThingModelServiceEventType.INFO.label }}
</el-radio>
<el-radio :value="ThingModelServiceEventType.ALERT.value">
{{ ThingModelServiceEventType.ALERT.label }}
</el-radio>
<el-radio :value="ThingModelServiceEventType.ERROR.value">
{{ ThingModelServiceEventType.ERROR.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</template>
<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
import { ThingModelEvent, ThingModelServiceEventType } from '@/api/iot/thingmodel'
/** IoT 物模型事件 */
defineOptions({ name: 'ThingModelEvent' })
const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean }>()
const emits = defineEmits(['update:modelValue'])
const thingModelEvent = useVModel(props, 'modelValue', emits) as Ref<ThingModelEvent>
</script>
<style lang="scss" scoped>
:deep(.el-form-item) {
.el-form-item {
margin-bottom: 0;
}
}
</style>

View File

@ -25,10 +25,17 @@
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
</el-form-item>
<!-- 属性配置 -->
<ThingModelDataSpecs
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
<ThingModelProperty
v-if="formData.type === ThingModelType.PROPERTY"
v-model="formData.property"
/>
<!-- 服务配置 -->
<ThingModelService
v-if="formData.type === ThingModelType.SERVICE"
v-model="formData.service"
/>
<!-- 事件配置 -->
<ThingModelEvent v-if="formData.type === ThingModelType.EVENT" v-model="formData.event" />
</el-form>
<template #footer>
@ -40,8 +47,10 @@
<script lang="ts" setup>
import { ProductVO } from '@/api/iot/product/product'
import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
import { ProductFunctionTypeEnum, ThingModelApi, ThingModelData } from '@/api/iot/thingmodel'
import ThingModelProperty from './ThingModelProperty.vue'
import ThingModelService from './ThingModelService.vue'
import ThingModelEvent from './ThingModelEvent.vue'
import { ThingModelApi, ThingModelData, ThingModelType } from '@/api/iot/thingmodel'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
import { DataSpecsDataType, ThingModelFormRules } from './config'
import { cloneDeep } from 'lodash-es'
@ -61,14 +70,16 @@ const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref<ThingModelData>({
type: ProductFunctionTypeEnum.PROPERTY,
type: ThingModelType.PROPERTY,
dataType: DataSpecsDataType.INT,
property: {
dataType: DataSpecsDataType.INT,
dataSpecs: {
dataType: DataSpecsDataType.INT
}
}
},
service: {},
event: {}
})
const formRef = ref() // Ref
@ -104,13 +115,7 @@ const submitForm = async () => {
data.dataType = data.property.dataType
data.property.identifier = data.identifier
data.property.name = data.name
// dataSpecs
if (isEmpty(data.property.dataSpecs)) {
delete data.property.dataSpecs
}
if (isEmpty(data.property.dataSpecsList)) {
delete data.property.dataSpecsList
}
removeExtraAttributes(data)
if (formType.value === 'create') {
await ThingModelApi.createThingModel(data)
message.success(t('common.createSuccess'))
@ -125,10 +130,34 @@ const submitForm = async () => {
}
}
/** 删除额外的属性 */
const removeExtraAttributes = (data: any) => {
// dataSpecs
if (isEmpty(data.property.dataSpecs)) {
delete data.property.dataSpecs
}
if (isEmpty(data.property.dataSpecsList)) {
delete data.property.dataSpecsList
}
//
if (data.type === ThingModelType.PROPERTY) {
delete data.service
delete data.event
}
if (data.type === ThingModelType.SERVICE) {
delete data.property
delete data.event
}
if (data.type === ThingModelType.EVENT) {
delete data.property
delete data.service
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
type: ProductFunctionTypeEnum.PROPERTY,
type: ThingModelType.PROPERTY,
dataType: DataSpecsDataType.INT,
property: {
dataType: DataSpecsDataType.INT,

View File

@ -77,8 +77,12 @@
/>
<el-form-item v-if="!isStructDataSpecs" label="读写类型" prop="property.accessMode">
<el-radio-group v-model="property.accessMode">
<el-radio label="rw">读写</el-radio>
<el-radio label="r">只读</el-radio>
<el-radio :label="ThingModelAccessMode.READ_WRITE.value">
{{ ThingModelAccessMode.READ_WRITE.label }}
</el-radio>
<el-radio :label="ThingModelAccessMode.READ_ONLY.value">
{{ ThingModelAccessMode.READ_ONLY.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="属性描述" prop="description">
@ -101,10 +105,10 @@ import {
ThingModelNumberDataSpecs,
ThingModelStructDataSpecs
} from './dataSpecs'
import { ThingModelProperty } from '@/api/iot/thingmodel'
import { ThingModelAccessMode, ThingModelProperty } from '@/api/iot/thingmodel'
/** IoT 物模型数据 */
defineOptions({ name: 'ThingModelDataSpecs' })
defineOptions({ name: 'ThingModelProperty' })
const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean }>()
const emits = defineEmits(['update:modelValue'])
@ -117,6 +121,7 @@ const getDataTypeOptions = computed(() => {
!([DataSpecsDataType.STRUCT, DataSpecsDataType.ARRAY] as any[]).includes(item.value)
)
}) //
/** 属性值的数据类型切换时初始化相关数据 */
const handleChange = (dataType: any) => {
property.value.dataSpecsList = []

View File

@ -0,0 +1,36 @@
<template>
<el-form-item
:rules="[{ required: true, message: '请选择调用方式', trigger: 'change' }]"
label="调用方式"
prop="service.callType"
>
<el-radio-group v-model="service.callType">
<el-radio :value="ThingModelServiceCallType.ASYNC.value">
{{ ThingModelServiceCallType.ASYNC.label }}
</el-radio>
<el-radio :value="ThingModelServiceCallType.SYNC.value">
{{ ThingModelServiceCallType.SYNC.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</template>
<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
import { ThingModelService, ThingModelServiceCallType } from '@/api/iot/thingmodel'
/** IoT 物模型服务 */
defineOptions({ name: 'ThingModelService' })
const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean }>()
const emits = defineEmits(['update:modelValue'])
const service = useVModel(props, 'modelValue', emits) as Ref<ThingModelService>
</script>
<style lang="scss" scoped>
:deep(.el-form-item) {
.el-form-item {
margin-bottom: 0;
}
}
</style>

View File

@ -47,10 +47,10 @@
@change="unitChange"
>
<el-option
v-for="(item, index) in UnifyUnitSpecsDTO"
v-for="(item, index) in getStrDictOptions(DICT_TYPE.IOT_PRODUCT_THING_MODEL_UNIT)"
:key="index"
:label="item.Name + '-' + item.Symbol"
:value="item.Name + '-' + item.Symbol"
:label="item.label + '-' + item.value"
:value="item.label + '-' + item.value"
/>
</el-select>
</el-form-item>
@ -58,8 +58,8 @@
<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
import { DataSpecsNumberDataVO } from '../config'
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
/** 数值型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThingModelNumberDataSpecs' })

View File

@ -35,7 +35,7 @@
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
</el-form-item>
<!-- 属性配置 -->
<ThingModelDataSpecs v-model="formData.property" is-struct-data-specs />
<ThingModelProperty v-model="formData.property" is-struct-data-specs />
</el-form>
<template #footer>
@ -47,7 +47,7 @@
<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
import ThingModelDataSpecs from '../ThingModelDataSpecs.vue'
import ThingModelProperty from '../ThingModelProperty.vue'
import { DataSpecsDataType, ThingModelFormRules } from '../config'
import { isEmpty } from '@/utils/is'

View File

@ -2,534 +2,3 @@
export const IOT_PROVIDE_KEY = {
PRODUCT: 'IOT_PRODUCT'
}
// TODO puhui999: 物模型数字数据类型单位类型,后面改成字典获取
export const UnifyUnitSpecsDTO = [
{
Symbol: 'L/min',
Name: '升每分钟'
},
{
Symbol: 'mg/kg',
Name: '毫克每千克'
},
{
Symbol: 'NTU',
Name: '浊度'
},
{
Symbol: 'pH',
Name: 'PH值'
},
{
Symbol: 'dS/m',
Name: '土壤EC值'
},
{
Symbol: 'W/㎡',
Name: '太阳总辐射'
},
{
Symbol: 'mm/hour',
Name: '降雨量'
},
{
Symbol: 'var',
Name: '乏'
},
{
Symbol: 'cP',
Name: '厘泊'
},
{
Symbol: 'aw',
Name: '饱和度'
},
{
Symbol: 'pcs',
Name: '个'
},
{
Symbol: 'cst',
Name: '厘斯'
},
{
Symbol: 'bar',
Name: '巴'
},
{
Symbol: 'ppt',
Name: '纳克每升'
},
{
Symbol: 'ppb',
Name: '微克每升'
},
{
Symbol: 'uS/cm',
Name: '微西每厘米'
},
{
Symbol: 'N/C',
Name: '牛顿每库仑'
},
{
Symbol: 'V/m',
Name: '伏特每米'
},
{
Symbol: 'ml/min',
Name: '滴速'
},
{
Symbol: 'mmHg',
Name: '毫米汞柱'
},
{
Symbol: 'mmol/L',
Name: '血糖'
},
{
Symbol: 'mm/s',
Name: '毫米每秒'
},
{
Symbol: 'turn/m',
Name: '转每分钟'
},
{
Symbol: 'count',
Name: '次'
},
{
Symbol: 'gear',
Name: '档'
},
{
Symbol: 'stepCount',
Name: '步'
},
{
Symbol: 'Nm3/h',
Name: '标准立方米每小时'
},
{
Symbol: 'kV',
Name: '千伏'
},
{
Symbol: 'kVA',
Name: '千伏安'
},
{
Symbol: 'kVar',
Name: '千乏'
},
{
Symbol: 'uw/cm2',
Name: '微瓦每平方厘米'
},
{
Symbol: '只',
Name: '只'
},
{
Symbol: '%RH',
Name: '相对湿度'
},
{
Symbol: 'm³/s',
Name: '立方米每秒'
},
{
Symbol: 'kg/s',
Name: '公斤每秒'
},
{
Symbol: 'r/min',
Name: '转每分钟'
},
{
Symbol: 't/h',
Name: '吨每小时'
},
{
Symbol: 'KCL/h',
Name: '千卡每小时'
},
{
Symbol: 'L/s',
Name: '升每秒'
},
{
Symbol: 'Mpa',
Name: '兆帕'
},
{
Symbol: 'm³/h',
Name: '立方米每小时'
},
{
Symbol: 'kvarh',
Name: '千乏时'
},
{
Symbol: 'μg/L',
Name: '微克每升'
},
{
Symbol: 'kcal',
Name: '千卡路里'
},
{
Symbol: 'GB',
Name: '吉字节'
},
{
Symbol: 'MB',
Name: '兆字节'
},
{
Symbol: 'KB',
Name: '千字节'
},
{
Symbol: 'B',
Name: '字节'
},
{
Symbol: 'μg/(d㎡·d)',
Name: '微克每平方分米每天'
},
{
Symbol: '',
Name: '无'
},
{
Symbol: 'ppm',
Name: '百万分率'
},
{
Symbol: 'pixel',
Name: '像素'
},
{
Symbol: 'Lux',
Name: '照度'
},
{
Symbol: 'grav',
Name: '重力加速度'
},
{
Symbol: 'dB',
Name: '分贝'
},
{
Symbol: '%',
Name: '百分比'
},
{
Symbol: 'lm',
Name: '流明'
},
{
Symbol: 'bit',
Name: '比特'
},
{
Symbol: 'g/mL',
Name: '克每毫升'
},
{
Symbol: 'g/L',
Name: '克每升'
},
{
Symbol: 'mg/L',
Name: '毫克每升'
},
{
Symbol: 'μg/m³',
Name: '微克每立方米'
},
{
Symbol: 'mg/m³',
Name: '毫克每立方米'
},
{
Symbol: 'g/m³',
Name: '克每立方米'
},
{
Symbol: 'kg/m³',
Name: '千克每立方米'
},
{
Symbol: 'nF',
Name: '纳法'
},
{
Symbol: 'pF',
Name: '皮法'
},
{
Symbol: 'μF',
Name: '微法'
},
{
Symbol: 'F',
Name: '法拉'
},
{
Symbol: 'Ω',
Name: '欧姆'
},
{
Symbol: 'μA',
Name: '微安'
},
{
Symbol: 'mA',
Name: '毫安'
},
{
Symbol: 'kA',
Name: '千安'
},
{
Symbol: 'A',
Name: '安培'
},
{
Symbol: 'mV',
Name: '毫伏'
},
{
Symbol: 'V',
Name: '伏特'
},
{
Symbol: 'ms',
Name: '毫秒'
},
{
Symbol: 's',
Name: '秒'
},
{
Symbol: 'min',
Name: '分钟'
},
{
Symbol: 'h',
Name: '小时'
},
{
Symbol: 'day',
Name: '日'
},
{
Symbol: 'week',
Name: '周'
},
{
Symbol: 'month',
Name: '月'
},
{
Symbol: 'year',
Name: '年'
},
{
Symbol: 'kn',
Name: '节'
},
{
Symbol: 'km/h',
Name: '千米每小时'
},
{
Symbol: 'm/s',
Name: '米每秒'
},
{
Symbol: '″',
Name: '秒'
},
{
Symbol: '',
Name: '分'
},
{
Symbol: '°',
Name: '度'
},
{
Symbol: 'rad',
Name: '弧度'
},
{
Symbol: 'Hz',
Name: '赫兹'
},
{
Symbol: 'μW',
Name: '微瓦'
},
{
Symbol: 'mW',
Name: '毫瓦'
},
{
Symbol: 'kW',
Name: '千瓦特'
},
{
Symbol: 'W',
Name: '瓦特'
},
{
Symbol: 'cal',
Name: '卡路里'
},
{
Symbol: 'kW·h',
Name: '千瓦时'
},
{
Symbol: 'Wh',
Name: '瓦时'
},
{
Symbol: 'eV',
Name: '电子伏'
},
{
Symbol: 'kJ',
Name: '千焦'
},
{
Symbol: 'J',
Name: '焦耳'
},
{
Symbol: '℉',
Name: '华氏度'
},
{
Symbol: 'K',
Name: '开尔文'
},
{
Symbol: 't',
Name: '吨'
},
{
Symbol: '°C',
Name: '摄氏度'
},
{
Symbol: 'mPa',
Name: '毫帕'
},
{
Symbol: 'hPa',
Name: '百帕'
},
{
Symbol: 'kPa',
Name: '千帕'
},
{
Symbol: 'Pa',
Name: '帕斯卡'
},
{
Symbol: 'mg',
Name: '毫克'
},
{
Symbol: 'g',
Name: '克'
},
{
Symbol: 'kg',
Name: '千克'
},
{
Symbol: 'N',
Name: '牛'
},
{
Symbol: 'mL',
Name: '毫升'
},
{
Symbol: 'L',
Name: '升'
},
{
Symbol: 'mm³',
Name: '立方毫米'
},
{
Symbol: 'cm³',
Name: '立方厘米'
},
{
Symbol: 'km³',
Name: '立方千米'
},
{
Symbol: 'm³',
Name: '立方米'
},
{
Symbol: 'h㎡',
Name: '公顷'
},
{
Symbol: 'c㎡',
Name: '平方厘米'
},
{
Symbol: 'm㎡',
Name: '平方毫米'
},
{
Symbol: 'k㎡',
Name: '平方千米'
},
{
Symbol: '㎡',
Name: '平方米'
},
{
Symbol: 'nm',
Name: '纳米'
},
{
Symbol: 'μm',
Name: '微米'
},
{
Symbol: 'mm',
Name: '毫米'
},
{
Symbol: 'cm',
Name: '厘米'
},
{
Symbol: 'dm',
Name: '分米'
},
{
Symbol: 'km',
Name: '千米'
},
{
Symbol: 'm',
Name: '米'
}
]