Skip to content

Commit 9f819db

Browse files
author
puhui999
committed
【代码优化】IOT: 产品物模型代码评审问题优化
1 parent 53c967c commit 9f819db

File tree

8 files changed

+44
-35
lines changed

8 files changed

+44
-35
lines changed

src/api/iot/thinkmodel/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,38 @@ export enum ProductFunctionAccessModeEnum {
5151
READ_ONLY = 'r' // 只读
5252
}
5353

54-
// TODO @puhui999:getProductThingModelPage => getThingModelPage 哈,不用带 product 前缀
5554
// IoT 产品物模型 API
5655
export const ThinkModelApi = {
5756
// 查询产品物模型分页
58-
getProductThinkModelPage: async (params: any) => {
57+
getThinkModelPage: async (params: any) => {
5958
return await request.get({ url: `/iot/product-thing-model/page`, params })
6059
},
6160

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

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

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

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

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

src/utils/dict.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* 数据字典工具类
33
*/
4-
import { useDictStoreWithOut } from '@/store/modules/dict'
5-
import { ElementPlusInfoType } from '@/types/elementPlus'
4+
import {useDictStoreWithOut} from '@/store/modules/dict'
5+
import {ElementPlusInfoType} from '@/types/elementPlus'
66

77
const dictStore = useDictStoreWithOut()
88

@@ -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_FUNCTION_TYPE = 'iot_product_function_type', // IOT 产品功能类型
239+
IOT_PRODUCT_THINK_MODEL_TYPE = 'iot_product_think_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/thinkmodel/ThinkModelDataSpecs.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ import {
111111
import { ThinkModelProperty } from '@/api/iot/thinkmodel'
112112
import { isEmpty } from '@/utils/is'
113113
114-
/** 物模型数据 */
115-
defineOptions({ name: 'IoTProductThinkModelDataSpecs' })
114+
/** IoT 物模型数据 */
115+
defineOptions({ name: 'ThinkModelDataSpecs' })
116+
116117
const props = defineProps<{ modelValue: any }>()
117118
const emits = defineEmits(['update:modelValue'])
118119
const property = useVModel(props, 'modelValue', emits) as Ref<ThinkModelProperty>

src/views/iot/thinkmodel/ThinkModelForm.vue

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
>
1010
<el-form-item label="功能类型" prop="type">
1111
<el-radio-group v-model="formData.type">
12-
<el-radio-button :value="1"> 属性</el-radio-button>
13-
<el-radio-button :value="2"> 服务</el-radio-button>
14-
<el-radio-button :value="3"> 事件</el-radio-button>
12+
<el-radio-button
13+
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THINK_MODEL_TYPE)"
14+
:key="dict.value"
15+
:value="dict.value"
16+
>
17+
{{ dict.label }}
18+
</el-radio-button>
1519
</el-radio-group>
1620
</el-form-item>
1721
<el-form-item label="功能名称" prop="name">
@@ -41,18 +45,20 @@ import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/io
4145
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
4246
import { DataSpecsDataType } from './config'
4347
import { cloneDeep } from 'lodash-es'
48+
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
4449
50+
/** IoT 物模型数据表单 */
4551
defineOptions({ name: 'IoTProductThinkModelForm' })
4652
4753
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // 注入产品信息
4854
49-
const { t } = useI18n()
50-
const message = useMessage()
55+
const { t } = useI18n() // 国际化
56+
const message = useMessage() // 消息弹窗
5157
52-
const dialogVisible = ref(false)
53-
const dialogTitle = ref('')
54-
const formLoading = ref(false)
55-
const formType = ref('')
58+
const dialogVisible = ref(false) // 弹窗的是否展示
59+
const dialogTitle = ref('') // 弹窗的标题
60+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
61+
const formType = ref('') // 表单的类型:create - 新增;update - 修改
5662
const formData = ref<ThinkModelData>({
5763
type: ProductFunctionTypeEnum.PROPERTY,
5864
dataType: DataSpecsDataType.INT,
@@ -100,7 +106,7 @@ const formRules = reactive({
100106
}
101107
]
102108
})
103-
const formRef = ref()
109+
const formRef = ref() // 表单 Ref
104110
105111
/** 打开弹窗 */
106112
const open = async (type: string, id?: number) => {
@@ -111,7 +117,7 @@ const open = async (type: string, id?: number) => {
111117
if (id) {
112118
formLoading.value = true
113119
try {
114-
formData.value = await ThinkModelApi.getProductThinkModel(id)
120+
formData.value = await ThinkModelApi.getThinkModel(id)
115121
} finally {
116122
formLoading.value = false
117123
}
@@ -134,10 +140,10 @@ const submitForm = async () => {
134140
data.property.identifier = data.identifier
135141
data.property.name = data.name
136142
if (formType.value === 'create') {
137-
await ThinkModelApi.createProductThinkModel(data)
143+
await ThinkModelApi.createThinkModel(data)
138144
message.success(t('common.createSuccess'))
139145
} else {
140-
await ThinkModelApi.updateProductThinkModel(data)
146+
await ThinkModelApi.updateThinkModel(data)
141147
message.success(t('common.updateSuccess'))
142148
}
143149
} finally {

src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import { DataSpecsDataType, dataTypeOptions } from '../config'
3737
import { isEmpty } from '@/utils/is'
3838
3939
/** 数组型的 dataSpecs 配置组件 */
40-
defineOptions({ name: 'IoTProductThinkModelArrayTypeDataSpecs' })
40+
defineOptions({ name: 'ThinkModelArrayTypeDataSpecs' })
41+
4142
const props = defineProps<{ modelValue: any }>()
4243
const emits = defineEmits(['update:modelValue'])
4344
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<any>

src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
4848
import { isEmpty } from '@/utils/is'
4949
5050
/** 枚举型的 dataSpecs 配置组件 */
51-
defineOptions({ name: 'IoTProductThinkModelEnumTypeDataSpecs' })
51+
defineOptions({ name: 'ThinkModelEnumTypeDataSpecs' })
52+
5253
const props = defineProps<{ modelValue: any }>()
5354
const emits = defineEmits(['update:modelValue'])
5455
const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref<DataSpecsEnumOrBoolDataVO[]>

src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
6262
import { DataSpecsNumberDataVO } from '../config'
6363
6464
/** 数值型的 dataSpecs 配置组件 */
65-
defineOptions({ name: 'IoTProductThinkModelNumberTypeDataSpecs' })
65+
defineOptions({ name: 'ThinkModelNumberTypeDataSpecs' })
66+
6667
const props = defineProps<{ modelValue: any }>()
6768
const emits = defineEmits(['update:modelValue'])
6869
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<DataSpecsNumberDataVO>
@@ -74,7 +75,7 @@ const unitChange = (UnitSpecs: string) => {
7475
dataSpecs.value.unit = unit
7576
}
7677
77-
// 校验最小值
78+
/** 校验最小值 */
7879
const validateMin = (_: any, __: any, callback: any) => {
7980
const min = Number(dataSpecs.value.min)
8081
const max = Number(dataSpecs.value.max)
@@ -92,7 +93,7 @@ const validateMin = (_: any, __: any, callback: any) => {
9293
callback()
9394
}
9495
95-
// 校验最大值
96+
/** 校验最大值 */
9697
const validateMax = (_: any, __: any, callback: any) => {
9798
const min = Number(dataSpecs.value.min)
9899
const max = Number(dataSpecs.value.max)
@@ -110,7 +111,7 @@ const validateMax = (_: any, __: any, callback: any) => {
110111
callback()
111112
}
112113
113-
// 校验步长
114+
/** 校验步长 */
114115
const validateStep = (_: any, __: any, callback: any) => {
115116
const step = Number(dataSpecs.value.step)
116117
const min = Number(dataSpecs.value.min)

src/views/iot/thinkmodel/index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
placeholder="请选择功能类型"
1818
>
1919
<el-option
20-
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_FUNCTION_TYPE)"
20+
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THINK_MODEL_TYPE)"
2121
:key="dict.value"
2222
:label="dict.label"
2323
:value="dict.value"
@@ -50,7 +50,7 @@
5050
<el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
5151
<el-table-column align="center" label="功能类型" prop="type">
5252
<template #default="scope">
53-
<dict-tag :type="DICT_TYPE.IOT_PRODUCT_FUNCTION_TYPE" :value="scope.row.type" />
53+
<dict-tag :type="DICT_TYPE.IOT_PRODUCT_THINK_MODEL_TYPE" :value="scope.row.type" />
5454
</template>
5555
</el-table-column>
5656
<el-table-column align="center" label="功能名称" prop="name" />
@@ -131,7 +131,7 @@ const getList = async () => {
131131
loading.value = true
132132
try {
133133
queryParams.productId = product?.value?.id || -1
134-
const data = await ThinkModelApi.getProductThinkModelPage(queryParams)
134+
const data = await ThinkModelApi.getThinkModelPage(queryParams)
135135
list.value = data.list
136136
total.value = data.total
137137
} finally {
@@ -163,7 +163,7 @@ const handleDelete = async (id: number) => {
163163
// 删除的二次确认
164164
await message.delConfirm()
165165
// 发起删除
166-
await ThinkModelApi.deleteProductThinkModel(id)
166+
await ThinkModelApi.deleteThinkModel(id)
167167
message.success(t('common.delSuccess'))
168168
// 刷新列表
169169
await getList()

0 commit comments

Comments
 (0)