Skip to content

Commit 341eb57

Browse files
author
puhui999
committed
【代码优化】IOT: 产品物模型独立包
1 parent c8ab57f commit 341eb57

File tree

12 files changed

+56
-63
lines changed

12 files changed

+56
-63
lines changed

src/api/iot/thinkmodelfunction/index.ts renamed to src/api/iot/thinkmodel/index.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import request from '@/config/axios'
33
/**
44
* IoT 产品物模型
55
*/
6-
export interface ThingModelData {
6+
export interface ThinkModelData {
77
id?: number // 物模型功能编号
88
identifier?: string // 功能标识
99
name?: string // 功能名称
@@ -12,29 +12,29 @@ export interface ThingModelData {
1212
productKey?: string // 产品标识
1313
dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致
1414
type: ProductFunctionTypeEnum // 功能类型
15-
property: ThingModelProperty // 属性
16-
event?: ThingModelEvent // 事件
17-
service?: ThingModelService // 服务
15+
property: ThinkModelProperty // 属性
16+
event?: ThinkModelEvent // 事件
17+
service?: ThinkModelService // 服务
1818
}
1919

2020
/**
21-
* ThingModelProperty 类型
21+
* ThinkModelProperty 类型
2222
*/
23-
export interface ThingModelProperty {
23+
export interface ThinkModelProperty {
2424
[key: string]: any
2525
}
2626

2727
/**
28-
* ThingModelEvent 类型
28+
* ThinkModelEvent 类型
2929
*/
30-
export interface ThingModelEvent {
30+
export interface ThinkModelEvent {
3131
[key: string]: any
3232
}
3333

3434
/**
35-
* ThingModelService 类型
35+
* ThinkModelService 类型
3636
*/
37-
export interface ThingModelService {
37+
export interface ThinkModelService {
3838
[key: string]: any
3939
}
4040

@@ -52,37 +52,37 @@ export enum ProductFunctionAccessModeEnum {
5252
}
5353

5454
// IoT 产品物模型 API
55-
export const ThinkModelFunctionApi = {
55+
export const ThinkModelApi = {
5656
// 查询产品物模型分页
57-
getProductThingModelPage: async (params: any) => {
57+
getProductThinkModelPage: async (params: any) => {
5858
return await request.get({ url: `/iot/product-thing-model/page`, params })
5959
},
6060

6161
// 获得产品物模型
62-
getProductThingModelListByProductId: async (params: any) => {
62+
getProductThinkModelListByProductId: async (params: any) => {
6363
return await request.get({
6464
url: `/iot/product-thing-model/list-by-product-id`,
6565
params
6666
})
6767
},
6868

6969
// 查询产品物模型详情
70-
getProductThingModel: async (id: number) => {
70+
getProductThinkModel: async (id: number) => {
7171
return await request.get({ url: `/iot/product-thing-model/get?id=` + id })
7272
},
7373

7474
// 新增产品物模型
75-
createProductThingModel: async (data: ThingModelData) => {
75+
createProductThinkModel: async (data: ThinkModelData) => {
7676
return await request.post({ url: `/iot/product-thing-model/create`, data })
7777
},
7878

7979
// 修改产品物模型
80-
updateProductThingModel: async (data: ThingModelData) => {
80+
updateProductThinkModel: async (data: ThinkModelData) => {
8181
return await request.put({ url: `/iot/product-thing-model/update`, data })
8282
},
8383

8484
// 删除产品物模型
85-
deleteProductThingModel: async (id: number) => {
85+
deleteProductThinkModel: async (id: number) => {
8686
return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id })
8787
}
8888
}

src/views/iot/product/product/detail/ThingModel/dataSpecs/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/views/iot/product/product/detail/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<el-tab-pane label="Topic 类列表" name="topic">
99
<ProductTopic v-if="activeTab === 'topic'" :product="product" />
1010
</el-tab-pane>
11-
<el-tab-pane label="功能定义" lazy name="thingModel">
12-
<IoTProductThingModel ref="thingModelRef" />
11+
<el-tab-pane label="功能定义" lazy name="thinkModel">
12+
<IoTProductThinkModel ref="thinkModelRef" />
1313
</el-tab-pane>
1414
<el-tab-pane label="消息解析" name="message" />
1515
<el-tab-pane label="服务端订阅" name="subscription" />
@@ -22,7 +22,7 @@ import { DeviceApi } from '@/api/iot/device'
2222
import ProductDetailsHeader from './ProductDetailsHeader.vue'
2323
import ProductDetailsInfo from './ProductDetailsInfo.vue'
2424
import ProductTopic from './ProductTopic.vue'
25-
import IoTProductThingModel from './ThingModel/index.vue'
25+
import IoTProductThinkModel from '@/views/iot/thinkmodel/index.vue'
2626
import { useTagsViewStore } from '@/store/modules/tagsView'
2727
import { useRouter } from 'vue-router'
2828
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'

src/views/iot/product/product/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ const openObjectModel = (item: ProductVO) => {
309309
push({
310310
name: 'IoTProductDetail',
311311
params: { id: item.id },
312-
query: { tab: 'thingModel' }
312+
query: { tab: 'thinkModel' }
313313
})
314314
}
315315

src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue renamed to src/views/iot/thinkmodel/ThinkModelDataSpecs.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</el-select>
1515
</el-form-item>
1616
<!-- 数值型配置 -->
17-
<ThingModelNumberTypeDataSpecs
17+
<ThinkModelNumberTypeDataSpecs
1818
v-if="
1919
[DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes(
2020
property.dataType || ''
@@ -23,7 +23,7 @@
2323
v-model="property.dataSpecs"
2424
/>
2525
<!-- 枚举型配置 -->
26-
<ThingModelEnumTypeDataSpecs
26+
<ThinkModelEnumTypeDataSpecs
2727
v-if="property.dataType === DataSpecsDataType.ENUM"
2828
v-model="property.dataSpecsList"
2929
/>
@@ -74,7 +74,7 @@
7474
<el-input class="w-255px!" disabled placeholder="String类型的UTC时间戳(毫秒)" />
7575
</el-form-item>
7676
<!-- 数组型配置-->
77-
<ThingModelArrayTypeDataSpecs
77+
<ThinkModelArrayTypeDataSpecs
7878
v-if="property.dataType === DataSpecsDataType.ARRAY"
7979
v-model="property.dataSpecs"
8080
/>
@@ -104,18 +104,18 @@
104104
import { useVModel } from '@vueuse/core'
105105
import { DataSpecsDataType, dataTypeOptions } from './config'
106106
import {
107-
ThingModelArrayTypeDataSpecs,
108-
ThingModelEnumTypeDataSpecs,
109-
ThingModelNumberTypeDataSpecs
107+
ThinkModelArrayTypeDataSpecs,
108+
ThinkModelEnumTypeDataSpecs,
109+
ThinkModelNumberTypeDataSpecs
110110
} from './dataSpecs'
111-
import { ThingModelProperty } from '@/api/iot/thinkmodelfunction'
111+
import { ThinkModelProperty } from '@/api/iot/thinkmodel'
112112
import { isEmpty } from '@/utils/is'
113113
114114
/** 物模型数据 */
115-
defineOptions({ name: 'ThingModelDataSpecs' })
115+
defineOptions({ name: 'IoTProductThinkModelDataSpecs' })
116116
const props = defineProps<{ modelValue: any }>()
117117
const emits = defineEmits(['update:modelValue'])
118-
const property = useVModel(props, 'modelValue', emits) as Ref<ThingModelProperty>
118+
const property = useVModel(props, 'modelValue', emits) as Ref<ThinkModelProperty>
119119
120120
/** 属性值的数据类型切换时初始化相关数据 */
121121
const handleChange = (dataType: any) => {

src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue renamed to src/views/iot/thinkmodel/ThinkModelForm.vue

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
2222
</el-form-item>
2323
<!-- 属性配置 -->
24-
<ThingModelDataSpecs
24+
<ThinkModelDataSpecs
2525
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
2626
v-model="formData.property"
2727
/>
@@ -36,17 +36,13 @@
3636

3737
<script lang="ts" setup>
3838
import { ProductVO } from '@/api/iot/product/product'
39-
import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
40-
import {
41-
ProductFunctionTypeEnum,
42-
ThingModelData,
43-
ThinkModelFunctionApi
44-
} from '@/api/iot/thinkmodelfunction'
39+
import ThinkModelDataSpecs from './ThinkModelDataSpecs.vue'
40+
import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/iot/thinkmodel'
4541
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
4642
import { DataSpecsDataType } from './config'
4743
import { cloneDeep } from 'lodash-es'
4844
49-
defineOptions({ name: 'IoTProductThingModelForm' })
45+
defineOptions({ name: 'IoTProductThinkModelForm' })
5046
5147
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // 注入产品信息
5248
@@ -57,7 +53,7 @@ const dialogVisible = ref(false)
5753
const dialogTitle = ref('')
5854
const formLoading = ref(false)
5955
const formType = ref('')
60-
const formData = ref<ThingModelData>({
56+
const formData = ref<ThinkModelData>({
6157
type: ProductFunctionTypeEnum.PROPERTY,
6258
dataType: DataSpecsDataType.INT,
6359
property: {
@@ -115,7 +111,7 @@ const open = async (type: string, id?: number) => {
115111
if (id) {
116112
formLoading.value = true
117113
try {
118-
formData.value = await ThinkModelFunctionApi.getProductThingModel(id)
114+
formData.value = await ThinkModelApi.getProductThinkModel(id)
119115
} finally {
120116
formLoading.value = false
121117
}
@@ -129,7 +125,7 @@ const submitForm = async () => {
129125
await formRef.value.validate()
130126
formLoading.value = true
131127
try {
132-
const data = cloneDeep(formData.value) as ThingModelData
128+
const data = cloneDeep(formData.value) as ThinkModelData
133129
// 信息补全
134130
data.productId = product!.value.id
135131
data.productKey = product!.value.productKey
@@ -138,10 +134,10 @@ const submitForm = async () => {
138134
data.property.identifier = data.identifier
139135
data.property.name = data.name
140136
if (formType.value === 'create') {
141-
await ThinkModelFunctionApi.createProductThingModel(data)
137+
await ThinkModelApi.createProductThinkModel(data)
142138
message.success(t('common.createSuccess'))
143139
} else {
144-
await ThinkModelFunctionApi.updateProductThingModel(data)
140+
await ThinkModelApi.updateProductThinkModel(data)
145141
message.success(t('common.updateSuccess'))
146142
}
147143
} finally {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { DataSpecsDataType, dataTypeOptions } from '../config'
3737
import { isEmpty } from '@/utils/is'
3838
3939
/** 数组型的 dataSpecs 配置组件 */
40-
defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
40+
defineOptions({ name: 'IoTProductThinkModelArrayTypeDataSpecs' })
4141
const props = defineProps<{ modelValue: any }>()
4242
const emits = defineEmits(['update:modelValue'])
4343
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<any>
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@
4444

4545
<script lang="ts" setup>
4646
import { useVModel } from '@vueuse/core'
47-
import {
48-
DataSpecsDataType,
49-
DataSpecsEnumOrBoolDataVO
50-
} from '@/views/iot/product/product/detail/ThingModel/config'
47+
import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
5148
import { isEmpty } from '@/utils/is'
5249
5350
/** 枚举型的 dataSpecs 配置组件 */
54-
defineOptions({ name: 'ThingModelEnumTypeDataSpecs' })
51+
defineOptions({ name: 'IoTProductThinkModelEnumTypeDataSpecs' })
5552
const props = defineProps<{ modelValue: any }>()
5653
const emits = defineEmits(['update:modelValue'])
5754
const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref<DataSpecsEnumOrBoolDataVO[]>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
6262
import { DataSpecsNumberDataVO } from '../config'
6363
6464
/** 数值型的 dataSpecs 配置组件 */
65-
defineOptions({ name: 'ThingModelNumberTypeDataSpecs' })
65+
defineOptions({ name: 'IoTProductThinkModelNumberTypeDataSpecs' })
6666
const props = defineProps<{ modelValue: any }>()
6767
const emits = defineEmits(['update:modelValue'])
6868
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<DataSpecsNumberDataVO>

0 commit comments

Comments
 (0)