Skip to content

Commit 187b5b0

Browse files
author
puhui999
committed
【功能完善】IOT: 物模型数据类型组件完善
1 parent 488800b commit 187b5b0

File tree

4 files changed

+87
-74
lines changed

4 files changed

+87
-74
lines changed

src/api/iot/thinkmodelfunction/index.ts

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
import request from '@/config/axios'
22

3-
// IoT 产品物模型 VO
4-
export interface ThinkModelFunctionVO {
5-
id: number // 物模型功能编号
6-
identifier: string // 功能标识
7-
name: string // 功能名称
8-
description: string // 功能描述
9-
productId: number // 产品编号
10-
productKey: string // 产品标识
11-
type: number // 功能类型
12-
property: string // 属性
13-
event: string // 事件
14-
service: string // 服务
3+
/**
4+
* IoT 产品物模型
5+
*/
6+
export interface ThingModelData {
7+
id?: number // 物模型功能编号
8+
identifier?: string // 功能标识
9+
name?: string // 功能名称
10+
description?: string // 功能描述
11+
productId?: number // 产品编号
12+
productKey?: string // 产品标识
13+
type: ProductFunctionTypeEnum // 功能类型
14+
property: ThingModelProperty // 属性
15+
event?: ThingModelEvent // 事件
16+
service?: ThingModelService // 服务
17+
}
18+
19+
/**
20+
* ThingModelProperty 类型
21+
*/
22+
export interface ThingModelProperty {
23+
[key: string]: any
24+
}
25+
26+
/**
27+
* ThingModelEvent 类型
28+
*/
29+
export interface ThingModelEvent {
30+
[key: string]: any
31+
}
32+
33+
/**
34+
* ThingModelService 类型
35+
*/
36+
export interface ThingModelService {
37+
[key: string]: any
1538
}
1639

1740
// IOT 产品功能(物模型)类型枚举类
@@ -47,22 +70,17 @@ export const ThinkModelFunctionApi = {
4770
},
4871

4972
// 新增产品物模型
50-
createThinkModelFunction: async (data: ThinkModelFunctionVO) => {
73+
createThinkModelFunction: async (data: ThingModelData) => {
5174
return await request.post({ url: `/iot/think-model-function/create`, data })
5275
},
5376

5477
// 修改产品物模型
55-
updateThinkModelFunction: async (data: ThinkModelFunctionVO) => {
78+
updateThinkModelFunction: async (data: ThingModelData) => {
5679
return await request.put({ url: `/iot/think-model-function/update`, data })
5780
},
5881

5982
// 删除产品物模型
6083
deleteThinkModelFunction: async (id: number) => {
6184
return await request.delete({ url: `/iot/think-model-function/delete?id=` + id })
62-
},
63-
64-
// 导出产品物模型 Excel
65-
exportThinkModelFunction: async (params) => {
66-
return await request.download({ url: `/iot/think-model-function/export-excel`, params })
6785
}
6886
}

src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<el-form-item label="数据类型" prop="dataType">
3-
<el-select v-model="formData.dataType" placeholder="请选择数据类型" @change="handleChange">
3+
<el-select v-model="property.dataType" placeholder="请选择数据类型" @change="handleChange">
44
<el-option
55
v-for="option in dataTypeOptions"
66
:key="option.value"
@@ -13,19 +13,19 @@
1313
<ThingModelNumberTypeDataSpecs
1414
v-if="
1515
[DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes(
16-
formData.dataType || ''
16+
property.dataType || ''
1717
)
1818
"
19-
v-model="formData.dataSpecs"
19+
v-model="property.dataSpecs"
2020
/>
2121
<!-- 枚举型配置 -->
2222
<ThingModelEnumTypeDataSpecs
23-
v-if="formData.dataType === DataSpecsDataType.ENUM"
24-
v-model="formData.dataSpecsList"
23+
v-if="property.dataType === DataSpecsDataType.ENUM"
24+
v-model="property.dataSpecsList"
2525
/>
2626
<!-- 布尔型配置 -->
27-
<el-form-item label="布尔值" prop="bool" v-if="formData.dataType === DataSpecsDataType.BOOL">
28-
<template v-for="item in formData.dataSpecsList" :key="item.value">
27+
<el-form-item label="布尔值" prop="bool" v-if="property.dataType === DataSpecsDataType.BOOL">
28+
<template v-for="item in property.dataSpecsList" :key="item.value">
2929
<div class="flex items-center justify-start w-1/1 mb-5px">
3030
<span>{{ item.value }}</span>
3131
<span class="mx-2">-</span>
@@ -38,20 +38,29 @@
3838
</template>
3939
</el-form-item>
4040
<!-- 文本型配置 -->
41-
<el-form-item label="数据长度" prop="text" v-if="formData.dataType === DataSpecsDataType.TEXT">
42-
<el-input v-model="formData.length" class="w-255px!" placeholder="请输入文本字节长度">
41+
<el-form-item label="数据长度" prop="text" v-if="property.dataType === DataSpecsDataType.TEXT">
42+
<el-input v-model="property.length" class="w-255px!" placeholder="请输入文本字节长度">
4343
<template #append>字节</template>
4444
</el-input>
4545
</el-form-item>
4646
<!-- 时间型配置 -->
47-
<el-form-item label="时间格式" prop="date" v-if="formData.dataType === DataSpecsDataType.DATE">
47+
<el-form-item label="时间格式" prop="date" v-if="property.dataType === DataSpecsDataType.DATE">
4848
<el-input disabled class="w-255px!" placeholder="String类型的UTC时间戳(毫秒)" />
4949
</el-form-item>
5050
<!-- 数组型配置-->
5151
<ThingModelArrayTypeDataSpecs
52-
v-model="formData.dataSpecs"
53-
v-if="formData.dataType === DataSpecsDataType.ARRAY"
52+
v-model="property.dataSpecs"
53+
v-if="property.dataType === DataSpecsDataType.ARRAY"
5454
/>
55+
<el-form-item label="读写类型" prop="accessMode">
56+
<el-radio-group v-model="property.accessMode">
57+
<el-radio label="rw">读写</el-radio>
58+
<el-radio label="r">只读</el-radio>
59+
</el-radio-group>
60+
</el-form-item>
61+
<el-form-item label="属性描述" prop="description">
62+
<el-input v-model="property.description" placeholder="请输入属性描述" type="textarea" />
63+
</el-form-item>
5564
</template>
5665

5766
<script lang="ts" setup>
@@ -62,46 +71,47 @@ import {
6271
ThingModelEnumTypeDataSpecs,
6372
ThingModelNumberTypeDataSpecs
6473
} from './dataSpecs'
74+
import { ThingModelProperty } from '@/api/iot/thinkmodelfunction'
6575
6676
/** 物模型数据 */
6777
defineOptions({ name: 'ThingModelDataSpecs' })
6878
const props = defineProps<{ modelValue: any }>()
6979
const emits = defineEmits(['update:modelValue'])
70-
const formData = useVModel(props, 'modelValue', emits) as Ref<any>
80+
const property = useVModel(props, 'modelValue', emits) as Ref<ThingModelProperty>
7181
7282
/** 属性值的数据类型切换时初始化相关数据 */
7383
const handleChange = (dataType: any) => {
74-
formData.value.dataSpecsList = []
75-
formData.value.dataSpecs = {}
84+
property.value.dataSpecsList = []
85+
property.value.dataSpecs = {}
7686
7787
switch (dataType) {
7888
case DataSpecsDataType.INT:
79-
formData.value.dataSpecs.dataType = DataSpecsDataType.INT
89+
property.value.dataSpecs.dataType = DataSpecsDataType.INT
8090
break
8191
case DataSpecsDataType.DOUBLE:
82-
formData.value.dataSpecs.dataType = DataSpecsDataType.DOUBLE
92+
property.value.dataSpecs.dataType = DataSpecsDataType.DOUBLE
8393
break
8494
case DataSpecsDataType.FLOAT:
85-
formData.value.dataSpecs.dataType = DataSpecsDataType.FLOAT
95+
property.value.dataSpecs.dataType = DataSpecsDataType.FLOAT
8696
break
8797
case DataSpecsDataType.ENUM:
88-
formData.value.dataSpecsList.push({
98+
property.value.dataSpecsList.push({
8999
dataType: DataSpecsDataType.ENUM,
90100
name: '', // 枚举项的名称
91101
value: undefined // 枚举值
92102
})
93103
break
94104
case DataSpecsDataType.BOOL:
95105
for (let i = 0; i < 2; i++) {
96-
formData.value.dataSpecsList.push({
106+
property.value.dataSpecsList.push({
97107
dataType: DataSpecsDataType.BOOL,
98108
name: '', // 布尔值的名称
99109
value: i // 布尔值
100110
})
101111
}
102112
break
103113
case DataSpecsDataType.ARRAY:
104-
formData.value.dataSpecs.dataType = DataSpecsDataType.ARRAY
114+
property.value.dataSpecs.dataType = DataSpecsDataType.ARRAY
105115
break
106116
}
107117
}

src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,11 @@
2020
<el-form-item label="标识符" prop="identifier">
2121
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
2222
</el-form-item>
23-
<ThingModelDataSpecs v-model="formData" />
24-
<el-form-item label="读写类型" prop="accessMode">
25-
<el-radio-group v-model="formData.accessMode">
26-
<el-radio label="rw">读写</el-radio>
27-
<el-radio label="r">只读</el-radio>
28-
</el-radio-group>
29-
</el-form-item>
30-
<el-form-item label="属性描述" prop="property.description">
31-
<el-input v-model="formData.description" placeholder="请输入属性描述" type="textarea" />
32-
</el-form-item>
23+
<!-- 属性配置 -->
24+
<ThingModelDataSpecs
25+
v-model="formData.property"
26+
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
27+
/>
3328
</el-form>
3429

3530
<template #footer>
@@ -45,7 +40,7 @@ import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
4540
import {
4641
ProductFunctionTypeEnum,
4742
ThinkModelFunctionApi,
48-
ThinkModelFunctionVO
43+
ThingModelData
4944
} from '@/api/iot/thinkmodelfunction'
5045
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
5146
import { DataSpecsDataType } from './config'
@@ -61,18 +56,13 @@ const dialogVisible = ref(false)
6156
const dialogTitle = ref('')
6257
const formLoading = ref(false)
6358
const formType = ref('')
64-
const formData = ref({
65-
id: undefined,
66-
productId: undefined,
67-
productKey: undefined,
68-
identifier: undefined,
69-
name: undefined,
70-
description: undefined,
59+
const formData = ref<ThingModelData>({
7160
type: ProductFunctionTypeEnum.PROPERTY,
72-
dataType: DataSpecsDataType.INT,
73-
dataSpecsList: [],
74-
dataSpecs: {},
75-
accessMode: undefined
61+
property: {
62+
dataType: DataSpecsDataType.INT,
63+
dataSpecsList: [],
64+
dataSpecs: {}
65+
}
7666
})
7767
const formRules = reactive({
7868
name: [
@@ -138,7 +128,7 @@ const submitForm = async () => {
138128
await formRef.value.validate()
139129
formLoading.value = true
140130
try {
141-
const data = formData.value as unknown as ThinkModelFunctionVO
131+
const data = formData.value as unknown as ThingModelData
142132
data.productId = product!.value.id
143133
data.productKey = product!.value.productKey
144134
if (formType.value === 'create') {
@@ -158,17 +148,12 @@ const submitForm = async () => {
158148
/** 重置表单 */
159149
const resetForm = () => {
160150
formData.value = {
161-
id: undefined,
162-
productId: undefined,
163-
productKey: undefined,
164-
identifier: undefined,
165-
name: undefined,
166-
description: undefined,
167151
type: ProductFunctionTypeEnum.PROPERTY,
168-
dataType: DataSpecsDataType.INT,
169-
dataSpecsList: [],
170-
dataSpecs: {},
171-
accessMode: undefined
152+
property: {
153+
dataType: DataSpecsDataType.INT,
154+
dataSpecsList: [],
155+
dataSpecs: {}
156+
}
172157
}
173158
formRef.value?.resetFields()
174159
}

src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelArrayTypeDataSpecs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import { useVModel } from '@vueuse/core'
2525
import { DataSpecsDataType, dataTypeOptions } from '../config'
2626
27-
/** 数值型的 dataSpecs 配置组件 */
27+
/** 数组型的 dataSpecs 配置组件 */
2828
defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
2929
const props = defineProps<{ modelValue: any }>()
3030
const emits = defineEmits(['update:modelValue'])

0 commit comments

Comments
 (0)