Skip to content

Commit d5f3d40

Browse files
author
puhui999
committed
【代码优化】IOT: ThingModel 优化
1 parent b6d3a85 commit d5f3d40

File tree

12 files changed

+62
-63
lines changed

12 files changed

+62
-63
lines changed

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

Lines changed: 23 additions & 24 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 ThinkModelData {
6+
export interface ThingModelData {
77
id?: number // 物模型功能编号
88
identifier?: string // 功能标识
99
name?: string // 功能名称
@@ -12,29 +12,29 @@ export interface ThinkModelData {
1212
productKey?: string // 产品标识
1313
dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致
1414
type: ProductFunctionTypeEnum // 功能类型
15-
property: ThinkModelProperty // 属性
16-
event?: ThinkModelEvent // 事件
17-
service?: ThinkModelService // 服务
15+
property: ThingModelProperty // 属性
16+
event?: ThingModelEvent // 事件
17+
service?: ThingModelService // 服务
1818
}
1919

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

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

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

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

5454
// IoT 产品物模型 API
55-
export const ThinkModelApi = {
55+
export const ThingModelApi = {
5656
// 查询产品物模型分页
57-
// TODO @puhui999:product 前缀,是不是去掉哈。
58-
getThinkModelPage: async (params: any) => {
59-
return await request.get({ url: `/iot/product-think-model/page`, params })
57+
getThingModelPage: async (params: any) => {
58+
return await request.get({ url: `/iot/product-thing-model/page`, params })
6059
},
6160

6261
// 获得产品物模型
63-
getThinkModelListByProductId: async (params: any) => {
62+
getThingModelListByProductId: async (params: any) => {
6463
return await request.get({
65-
url: `/iot/product-think-model/list-by-product-id`,
64+
url: `/iot/product-thing-model/list-by-product-id`,
6665
params
6766
})
6867
},
6968

7069
// 查询产品物模型详情
71-
getThinkModel: async (id: number) => {
72-
return await request.get({ url: `/iot/product-think-model/get?id=` + id })
70+
getThingModel: async (id: number) => {
71+
return await request.get({ url: `/iot/product-thing-model/get?id=` + id })
7372
},
7473

7574
// 新增产品物模型
76-
createThinkModel: async (data: ThinkModelData) => {
77-
return await request.post({ url: `/iot/product-think-model/create`, data })
75+
createThingModel: async (data: ThingModelData) => {
76+
return await request.post({ url: `/iot/product-thing-model/create`, data })
7877
},
7978

8079
// 修改产品物模型
81-
updateThinkModel: async (data: ThinkModelData) => {
82-
return await request.put({ url: `/iot/product-think-model/update`, data })
80+
updateThingModel: async (data: ThingModelData) => {
81+
return await request.put({ url: `/iot/product-thing-model/update`, data })
8382
},
8483

8584
// 删除产品物模型
86-
deleteThinkModel: async (id: number) => {
87-
return await request.delete({ url: `/iot/product-think-model/delete?id=` + id })
85+
deleteThingModel: async (id: number) => {
86+
return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id })
8887
}
8988
}

src/utils/dict.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export enum DICT_TYPE {
236236
IOT_DATA_FORMAT = 'iot_data_format', // IOT 数据格式
237237
IOT_PROTOCOL_TYPE = 'iot_protocol_type', // IOT 接入网关协议
238238
IOT_DEVICE_STATUS = 'iot_device_status', // IOT 设备状态
239-
IOT_PRODUCT_THINK_MODEL_TYPE = 'iot_product_think_model_type', // IOT 产品功能类型
239+
IOT_PRODUCT_THING_MODEL_TYPE = 'iot_product_thing_model_type', // IOT 产品功能类型
240240
IOT_DATA_TYPE = 'iot_data_type', // IOT 数据类型
241241
IOT_UNIT_TYPE = 'iot_unit_type', // IOT 单位类型
242242
IOT_RW_TYPE = 'iot_rw_type', // IOT 读写类型

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { DeviceApi } from '@/api/iot/device/device'
2222
import ProductDetailsHeader from './ProductDetailsHeader.vue'
2323
import ProductDetailsInfo from './ProductDetailsInfo.vue'
2424
import ProductTopic from './ProductTopic.vue'
25-
import IoTProductThinkModel from '@/views/iot/thinkmodel/index.vue'
25+
import IoTProductThinkModel from '@/views/iot/thingmodel/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/thinkmodel/ThinkModelDataSpecs.vue renamed to src/views/iot/thingmodel/ThingModelDataSpecs.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-
<ThinkModelNumberTypeDataSpecs
17+
<ThingModelNumberTypeDataSpecs
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-
<ThinkModelEnumTypeDataSpecs
26+
<ThingModelEnumTypeDataSpecs
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-
<ThinkModelArrayTypeDataSpecs
77+
<ThingModelArrayTypeDataSpecs
7878
v-if="property.dataType === DataSpecsDataType.ARRAY"
7979
v-model="property.dataSpecs"
8080
/>
@@ -104,19 +104,19 @@
104104
import { useVModel } from '@vueuse/core'
105105
import { DataSpecsDataType, dataTypeOptions } from './config'
106106
import {
107-
ThinkModelArrayTypeDataSpecs,
108-
ThinkModelEnumTypeDataSpecs,
109-
ThinkModelNumberTypeDataSpecs
107+
ThingModelArrayTypeDataSpecs,
108+
ThingModelEnumTypeDataSpecs,
109+
ThingModelNumberTypeDataSpecs
110110
} from './dataSpecs'
111-
import { ThinkModelProperty } from '@/api/iot/thinkmodel'
111+
import { ThingModelProperty } from 'src/api/iot/thingmodel'
112112
import { isEmpty } from '@/utils/is'
113113
114114
/** IoT 物模型数据 */
115-
defineOptions({ name: 'ThinkModelDataSpecs' })
115+
defineOptions({ name: 'ThingModelDataSpecs' })
116116
117117
const props = defineProps<{ modelValue: any }>()
118118
const emits = defineEmits(['update:modelValue'])
119-
const property = useVModel(props, 'modelValue', emits) as Ref<ThinkModelProperty>
119+
const property = useVModel(props, 'modelValue', emits) as Ref<ThingModelProperty>
120120
121121
/** 属性值的数据类型切换时初始化相关数据 */
122122
const handleChange = (dataType: any) => {

src/views/iot/thinkmodel/ThinkModelForm.vue renamed to src/views/iot/thingmodel/ThingModelForm.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<el-form-item label="功能类型" prop="type">
1111
<el-radio-group v-model="formData.type">
1212
<el-radio-button
13-
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THINK_MODEL_TYPE)"
13+
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THING_MODEL_TYPE)"
1414
:key="dict.value"
1515
:value="dict.value"
1616
>
@@ -25,7 +25,7 @@
2525
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
2626
</el-form-item>
2727
<!-- 属性配置 -->
28-
<ThinkModelDataSpecs
28+
<ThingModelDataSpecs
2929
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
3030
v-model="formData.property"
3131
/>
@@ -40,15 +40,15 @@
4040

4141
<script lang="ts" setup>
4242
import { ProductVO } from '@/api/iot/product/product'
43-
import ThinkModelDataSpecs from './ThinkModelDataSpecs.vue'
44-
import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/iot/thinkmodel'
43+
import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
44+
import { ProductFunctionTypeEnum, ThingModelApi, ThingModelData } from 'src/api/iot/thingmodel'
4545
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
4646
import { DataSpecsDataType } from './config'
4747
import { cloneDeep } from 'lodash-es'
4848
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
4949
5050
/** IoT 物模型数据表单 */
51-
defineOptions({ name: 'IoTProductThinkModelForm' })
51+
defineOptions({ name: 'IoTProductThingModelForm' })
5252
5353
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // 注入产品信息
5454
@@ -59,7 +59,7 @@ const dialogVisible = ref(false) // 弹窗的是否展示
5959
const dialogTitle = ref('') // 弹窗的标题
6060
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
6161
const formType = ref('') // 表单的类型:create - 新增;update - 修改
62-
const formData = ref<ThinkModelData>({
62+
const formData = ref<ThingModelData>({
6363
type: ProductFunctionTypeEnum.PROPERTY,
6464
dataType: DataSpecsDataType.INT,
6565
property: {
@@ -117,7 +117,7 @@ const open = async (type: string, id?: number) => {
117117
if (id) {
118118
formLoading.value = true
119119
try {
120-
formData.value = await ThinkModelApi.getThinkModel(id)
120+
formData.value = await ThingModelApi.getThingModel(id)
121121
} finally {
122122
formLoading.value = false
123123
}
@@ -131,7 +131,7 @@ const submitForm = async () => {
131131
await formRef.value.validate()
132132
formLoading.value = true
133133
try {
134-
const data = cloneDeep(formData.value) as ThinkModelData
134+
const data = cloneDeep(formData.value) as ThingModelData
135135
// 信息补全
136136
data.productId = product!.value.id
137137
data.productKey = product!.value.productKey
@@ -140,10 +140,10 @@ const submitForm = async () => {
140140
data.property.identifier = data.identifier
141141
data.property.name = data.name
142142
if (formType.value === 'create') {
143-
await ThinkModelApi.createThinkModel(data)
143+
await ThingModelApi.createThingModel(data)
144144
message.success(t('common.createSuccess'))
145145
} else {
146-
await ThinkModelApi.updateThinkModel(data)
146+
await ThingModelApi.updateThingModel(data)
147147
message.success(t('common.updateSuccess'))
148148
}
149149
} finally {

src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue renamed to src/views/iot/thingmodel/dataSpecs/ThingModelArrayTypeDataSpecs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { isEmpty } from '@/utils/is'
3939
// TODO @puhui999:参数校验,是不是还是定义一个变量,统一管,好阅读点哈?
4040
4141
/** 数组型的 dataSpecs 配置组件 */
42-
defineOptions({ name: 'ThinkModelArrayTypeDataSpecs' })
42+
defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
4343
4444
const props = defineProps<{ modelValue: any }>()
4545
const emits = defineEmits(['update:modelValue'])

src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue renamed to src/views/iot/thingmodel/dataSpecs/ThingModelEnumTypeDataSpecs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
4848
import { isEmpty } from '@/utils/is'
4949
5050
/** 枚举型的 dataSpecs 配置组件 */
51-
defineOptions({ name: 'ThinkModelEnumTypeDataSpecs' })
51+
defineOptions({ name: 'ThingModelEnumTypeDataSpecs' })
5252
5353
const props = defineProps<{ modelValue: any }>()
5454
const emits = defineEmits(['update:modelValue'])

src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue renamed to src/views/iot/thingmodel/dataSpecs/ThingModelNumberTypeDataSpecs.vue

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: 'ThinkModelNumberTypeDataSpecs' })
65+
defineOptions({ name: 'ThingModelNumberTypeDataSpecs' })
6666
6767
const props = defineProps<{ modelValue: any }>()
6868
const emits = defineEmits(['update:modelValue'])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import ThingModelEnumTypeDataSpecs from './ThingModelEnumTypeDataSpecs.vue'
2+
import ThingModelNumberTypeDataSpecs from './ThingModelNumberTypeDataSpecs.vue'
3+
import ThingModelArrayTypeDataSpecs from './ThingModelArrayTypeDataSpecs.vue'
4+
5+
export { ThingModelEnumTypeDataSpecs, ThingModelNumberTypeDataSpecs, ThingModelArrayTypeDataSpecs }

0 commit comments

Comments
 (0)