Skip to content

Commit d7c33b4

Browse files
author
puhui999
committed
【功能新增】IOT: ThingModel 服务和事件
1 parent 9bd96a3 commit d7c33b4

File tree

9 files changed

+186
-568
lines changed

9 files changed

+186
-568
lines changed

src/api/iot/thingmodel/index.ts

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface ThingModelData {
1111
productId?: number // 产品编号
1212
productKey?: string // 产品标识
1313
dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致
14-
type: ProductFunctionTypeEnum // 功能类型
14+
type: number // 功能类型
1515
property: ThingModelProperty // 属性
1616
event?: ThingModelEvent // 事件
1717
service?: ThingModelService // 服务
@@ -38,18 +38,58 @@ export interface ThingModelService {
3838
[key: string]: any
3939
}
4040

41-
// IOT 产品功能(物模型)类型枚举类
42-
export enum ProductFunctionTypeEnum {
43-
PROPERTY = 1, // 属性
44-
SERVICE = 2, // 服务
45-
EVENT = 3 // 事件
46-
}
41+
// IOT 产品物模型类型枚举类
42+
export const ThingModelType = {
43+
PROPERTY: 1, // 属性
44+
SERVICE: 2, // 服务
45+
EVENT: 3 // 事件
46+
} as const
4747

48-
// IOT 产品功能(物模型)访问模式枚举类
49-
export enum ProductFunctionAccessModeEnum {
50-
READ_WRITE = 'rw', // 读写
51-
READ_ONLY = 'r' // 只读
52-
}
48+
// IOT 产品物模型访问模式枚举类
49+
export const ThingModelAccessMode = {
50+
READ_WRITE: {
51+
label: '读写',
52+
value: 'rw'
53+
},
54+
READ_ONLY: {
55+
label: '只读',
56+
value: 'r'
57+
}
58+
} as const
59+
60+
// IOT 产品物模型服务调用方式枚举
61+
export const ThingModelServiceCallType = {
62+
ASYNC: {
63+
label: '异步调用',
64+
value: 'async'
65+
},
66+
SYNC: {
67+
label: '同步调用',
68+
value: 'sync'
69+
}
70+
} as const
71+
72+
// IOT 产品物模型事件类型枚举
73+
export const ThingModelServiceEventType = {
74+
INFO: {
75+
label: '信息',
76+
value: 'info'
77+
},
78+
ALERT: {
79+
label: '告警',
80+
value: 'alert'
81+
},
82+
ERROR: {
83+
label: '故障',
84+
value: 'error'
85+
}
86+
} as const
87+
88+
// IOT 产品物模型参数是输入参数还是输出参数
89+
export const ThingModelParamDirection = {
90+
INPUT: 'input', // 输入参数
91+
OUTPUT: 'output' // 输出参数
92+
} as const
5393

5494
// IoT 产品物模型 API
5595
export const ThingModelApi = {

src/utils/dict.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export enum DICT_TYPE {
238238
IOT_DEVICE_STATUS = 'iot_device_status', // IOT 设备状态
239239
IOT_PRODUCT_THING_MODEL_TYPE = 'iot_product_thing_model_type', // IOT 产品功能类型
240240
IOT_DATA_TYPE = 'iot_data_type', // IOT 数据类型
241-
IOT_UNIT_TYPE = 'iot_unit_type', // IOT 单位类型
241+
IOT_PRODUCT_THING_MODEL_UNIT = 'iot_product_thing_model_unit', // IOT 物模型单位
242242
IOT_RW_TYPE = 'iot_rw_type', // IOT 读写类型
243243
IOT_PLUGIN_DEPLOY_TYPE = 'iot_plugin_deploy_type', // IOT 插件部署类型
244244
IOT_PLUGIN_STATUS = 'iot_plugin_status', // IOT 插件状态
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template>
2+
<el-form-item
3+
:rules="[{ required: true, message: '请选择事件类型', trigger: 'change' }]"
4+
label="事件类型"
5+
prop="thingModelEvent.type"
6+
>
7+
<el-radio-group v-model="thingModelEvent.type">
8+
<el-radio :value="ThingModelServiceEventType.INFO.value">
9+
{{ ThingModelServiceEventType.INFO.label }}
10+
</el-radio>
11+
<el-radio :value="ThingModelServiceEventType.ALERT.value">
12+
{{ ThingModelServiceEventType.ALERT.label }}
13+
</el-radio>
14+
<el-radio :value="ThingModelServiceEventType.ERROR.value">
15+
{{ ThingModelServiceEventType.ERROR.label }}
16+
</el-radio>
17+
</el-radio-group>
18+
</el-form-item>
19+
</template>
20+
21+
<script lang="ts" setup>
22+
import { useVModel } from '@vueuse/core'
23+
import { ThingModelEvent, ThingModelServiceEventType } from '@/api/iot/thingmodel'
24+
25+
/** IoT 物模型事件 */
26+
defineOptions({ name: 'ThingModelEvent' })
27+
28+
const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean }>()
29+
const emits = defineEmits(['update:modelValue'])
30+
const thingModelEvent = useVModel(props, 'modelValue', emits) as Ref<ThingModelEvent>
31+
</script>
32+
33+
<style lang="scss" scoped>
34+
:deep(.el-form-item) {
35+
.el-form-item {
36+
margin-bottom: 0;
37+
}
38+
}
39+
</style>

src/views/iot/thingmodel/ThingModelForm.vue

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@
2525
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
2626
</el-form-item>
2727
<!-- 属性配置 -->
28-
<ThingModelDataSpecs
29-
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
28+
<ThingModelProperty
29+
v-if="formData.type === ThingModelType.PROPERTY"
3030
v-model="formData.property"
3131
/>
32+
<!-- 服务配置 -->
33+
<ThingModelService
34+
v-if="formData.type === ThingModelType.SERVICE"
35+
v-model="formData.service"
36+
/>
37+
<!-- 事件配置 -->
38+
<ThingModelEvent v-if="formData.type === ThingModelType.EVENT" v-model="formData.event" />
3239
</el-form>
3340

3441
<template #footer>
@@ -40,8 +47,10 @@
4047

4148
<script lang="ts" setup>
4249
import { ProductVO } from '@/api/iot/product/product'
43-
import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
44-
import { ProductFunctionTypeEnum, ThingModelApi, ThingModelData } from '@/api/iot/thingmodel'
50+
import ThingModelProperty from './ThingModelProperty.vue'
51+
import ThingModelService from './ThingModelService.vue'
52+
import ThingModelEvent from './ThingModelEvent.vue'
53+
import { ThingModelApi, ThingModelData, ThingModelType } from '@/api/iot/thingmodel'
4554
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
4655
import { DataSpecsDataType, ThingModelFormRules } from './config'
4756
import { cloneDeep } from 'lodash-es'
@@ -61,14 +70,16 @@ const dialogTitle = ref('') // 弹窗的标题
6170
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
6271
const formType = ref('') // 表单的类型:create - 新增;update - 修改
6372
const formData = ref<ThingModelData>({
64-
type: ProductFunctionTypeEnum.PROPERTY,
73+
type: ThingModelType.PROPERTY,
6574
dataType: DataSpecsDataType.INT,
6675
property: {
6776
dataType: DataSpecsDataType.INT,
6877
dataSpecs: {
6978
dataType: DataSpecsDataType.INT
7079
}
71-
}
80+
},
81+
service: {},
82+
event: {}
7283
})
7384
7485
const formRef = ref() // 表单 Ref
@@ -104,13 +115,7 @@ const submitForm = async () => {
104115
data.dataType = data.property.dataType
105116
data.property.identifier = data.identifier
106117
data.property.name = data.name
107-
// 处理 dataSpecs 为空的情况
108-
if (isEmpty(data.property.dataSpecs)) {
109-
delete data.property.dataSpecs
110-
}
111-
if (isEmpty(data.property.dataSpecsList)) {
112-
delete data.property.dataSpecsList
113-
}
118+
removeExtraAttributes(data)
114119
if (formType.value === 'create') {
115120
await ThingModelApi.createThingModel(data)
116121
message.success(t('common.createSuccess'))
@@ -125,10 +130,34 @@ const submitForm = async () => {
125130
}
126131
}
127132
133+
/** 删除额外的属性 */
134+
const removeExtraAttributes = (data: any) => {
135+
// 处理 dataSpecs 为空的情况
136+
if (isEmpty(data.property.dataSpecs)) {
137+
delete data.property.dataSpecs
138+
}
139+
if (isEmpty(data.property.dataSpecsList)) {
140+
delete data.property.dataSpecsList
141+
}
142+
// 处理不同类型的情况
143+
if (data.type === ThingModelType.PROPERTY) {
144+
delete data.service
145+
delete data.event
146+
}
147+
if (data.type === ThingModelType.SERVICE) {
148+
delete data.property
149+
delete data.event
150+
}
151+
if (data.type === ThingModelType.EVENT) {
152+
delete data.property
153+
delete data.service
154+
}
155+
}
156+
128157
/** 重置表单 */
129158
const resetForm = () => {
130159
formData.value = {
131-
type: ProductFunctionTypeEnum.PROPERTY,
160+
type: ThingModelType.PROPERTY,
132161
dataType: DataSpecsDataType.INT,
133162
property: {
134163
dataType: DataSpecsDataType.INT,

src/views/iot/thingmodel/ThingModelDataSpecs.vue renamed to src/views/iot/thingmodel/ThingModelProperty.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@
7777
/>
7878
<el-form-item v-if="!isStructDataSpecs" label="读写类型" prop="property.accessMode">
7979
<el-radio-group v-model="property.accessMode">
80-
<el-radio label="rw">读写</el-radio>
81-
<el-radio label="r">只读</el-radio>
80+
<el-radio :label="ThingModelAccessMode.READ_WRITE.value">
81+
{{ ThingModelAccessMode.READ_WRITE.label }}
82+
</el-radio>
83+
<el-radio :label="ThingModelAccessMode.READ_ONLY.value">
84+
{{ ThingModelAccessMode.READ_ONLY.label }}
85+
</el-radio>
8286
</el-radio-group>
8387
</el-form-item>
8488
<el-form-item label="属性描述" prop="description">
@@ -101,10 +105,10 @@ import {
101105
ThingModelNumberDataSpecs,
102106
ThingModelStructDataSpecs
103107
} from './dataSpecs'
104-
import { ThingModelProperty } from '@/api/iot/thingmodel'
108+
import { ThingModelAccessMode, ThingModelProperty } from '@/api/iot/thingmodel'
105109
106110
/** IoT 物模型数据 */
107-
defineOptions({ name: 'ThingModelDataSpecs' })
111+
defineOptions({ name: 'ThingModelProperty' })
108112
109113
const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean }>()
110114
const emits = defineEmits(['update:modelValue'])
@@ -117,6 +121,7 @@ const getDataTypeOptions = computed(() => {
117121
!([DataSpecsDataType.STRUCT, DataSpecsDataType.ARRAY] as any[]).includes(item.value)
118122
)
119123
}) // 获得数据类型列表
124+
120125
/** 属性值的数据类型切换时初始化相关数据 */
121126
const handleChange = (dataType: any) => {
122127
property.value.dataSpecsList = []
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template>
2+
<el-form-item
3+
:rules="[{ required: true, message: '请选择调用方式', trigger: 'change' }]"
4+
label="调用方式"
5+
prop="service.callType"
6+
>
7+
<el-radio-group v-model="service.callType">
8+
<el-radio :value="ThingModelServiceCallType.ASYNC.value">
9+
{{ ThingModelServiceCallType.ASYNC.label }}
10+
</el-radio>
11+
<el-radio :value="ThingModelServiceCallType.SYNC.value">
12+
{{ ThingModelServiceCallType.SYNC.label }}
13+
</el-radio>
14+
</el-radio-group>
15+
</el-form-item>
16+
</template>
17+
18+
<script lang="ts" setup>
19+
import { useVModel } from '@vueuse/core'
20+
import { ThingModelService, ThingModelServiceCallType } from '@/api/iot/thingmodel'
21+
22+
/** IoT 物模型服务 */
23+
defineOptions({ name: 'ThingModelService' })
24+
25+
const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean }>()
26+
const emits = defineEmits(['update:modelValue'])
27+
const service = useVModel(props, 'modelValue', emits) as Ref<ThingModelService>
28+
</script>
29+
30+
<style lang="scss" scoped>
31+
:deep(.el-form-item) {
32+
.el-form-item {
33+
margin-bottom: 0;
34+
}
35+
}
36+
</style>

src/views/iot/thingmodel/dataSpecs/ThingModelNumberDataSpecs.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@
4747
@change="unitChange"
4848
>
4949
<el-option
50-
v-for="(item, index) in UnifyUnitSpecsDTO"
50+
v-for="(item, index) in getStrDictOptions(DICT_TYPE.IOT_PRODUCT_THING_MODEL_UNIT)"
5151
:key="index"
52-
:label="item.Name + '-' + item.Symbol"
53-
:value="item.Name + '-' + item.Symbol"
52+
:label="item.label + '-' + item.value"
53+
:value="item.label + '-' + item.value"
5454
/>
5555
</el-select>
5656
</el-form-item>
5757
</template>
5858

5959
<script lang="ts" setup>
6060
import { useVModel } from '@vueuse/core'
61-
import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
6261
import { DataSpecsNumberDataVO } from '../config'
62+
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
6363
6464
/** 数值型的 dataSpecs 配置组件 */
6565
defineOptions({ name: 'ThingModelNumberDataSpecs' })

src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
3636
</el-form-item>
3737
<!-- 属性配置 -->
38-
<ThingModelDataSpecs v-model="formData.property" is-struct-data-specs />
38+
<ThingModelProperty v-model="formData.property" is-struct-data-specs />
3939
</el-form>
4040

4141
<template #footer>
@@ -47,7 +47,7 @@
4747

4848
<script lang="ts" setup>
4949
import { useVModel } from '@vueuse/core'
50-
import ThingModelDataSpecs from '../ThingModelDataSpecs.vue'
50+
import ThingModelProperty from '../ThingModelProperty.vue'
5151
import { DataSpecsDataType, ThingModelFormRules } from '../config'
5252
import { isEmpty } from '@/utils/is'
5353

0 commit comments

Comments
 (0)