Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9f819db1
authored
Dec 17, 2024
by
puhui999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【代码优化】IOT: 产品物模型代码评审问题优化
parent
53c967c3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
44 additions
and
35 deletions
+44
-35
src/api/iot/thinkmodel/index.ts
+6
-7
src/utils/dict.ts
+3
-3
src/views/iot/thinkmodel/ThinkModelDataSpecs.vue
+3
-2
src/views/iot/thinkmodel/ThinkModelForm.vue
+19
-13
src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue
+2
-1
src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue
+2
-1
src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue
+5
-4
src/views/iot/thinkmodel/index.vue
+4
-4
No files found.
src/api/iot/thinkmodel/index.ts
View file @
9f819db1
...
@@ -51,16 +51,15 @@ export enum ProductFunctionAccessModeEnum {
...
@@ -51,16 +51,15 @@ export enum ProductFunctionAccessModeEnum {
READ_ONLY
=
'r'
// 只读
READ_ONLY
=
'r'
// 只读
}
}
// TODO @puhui999:getProductThingModelPage => getThingModelPage 哈,不用带 product 前缀
// IoT 产品物模型 API
// IoT 产品物模型 API
export
const
ThinkModelApi
=
{
export
const
ThinkModelApi
=
{
// 查询产品物模型分页
// 查询产品物模型分页
get
Product
ThinkModelPage
:
async
(
params
:
any
)
=>
{
getThinkModelPage
:
async
(
params
:
any
)
=>
{
return
await
request
.
get
({
url
:
`/iot/product-thing-model/page`
,
params
})
return
await
request
.
get
({
url
:
`/iot/product-thing-model/page`
,
params
})
},
},
// 获得产品物模型
// 获得产品物模型
get
Product
ThinkModelListByProductId
:
async
(
params
:
any
)
=>
{
getThinkModelListByProductId
:
async
(
params
:
any
)
=>
{
return
await
request
.
get
({
return
await
request
.
get
({
url
:
`/iot/product-thing-model/list-by-product-id`
,
url
:
`/iot/product-thing-model/list-by-product-id`
,
params
params
...
@@ -68,22 +67,22 @@ export const ThinkModelApi = {
...
@@ -68,22 +67,22 @@ export const ThinkModelApi = {
},
},
// 查询产品物模型详情
// 查询产品物模型详情
get
Product
ThinkModel
:
async
(
id
:
number
)
=>
{
getThinkModel
:
async
(
id
:
number
)
=>
{
return
await
request
.
get
({
url
:
`/iot/product-thing-model/get?id=`
+
id
})
return
await
request
.
get
({
url
:
`/iot/product-thing-model/get?id=`
+
id
})
},
},
// 新增产品物模型
// 新增产品物模型
create
Product
ThinkModel
:
async
(
data
:
ThinkModelData
)
=>
{
createThinkModel
:
async
(
data
:
ThinkModelData
)
=>
{
return
await
request
.
post
({
url
:
`/iot/product-thing-model/create`
,
data
})
return
await
request
.
post
({
url
:
`/iot/product-thing-model/create`
,
data
})
},
},
// 修改产品物模型
// 修改产品物模型
update
Product
ThinkModel
:
async
(
data
:
ThinkModelData
)
=>
{
updateThinkModel
:
async
(
data
:
ThinkModelData
)
=>
{
return
await
request
.
put
({
url
:
`/iot/product-thing-model/update`
,
data
})
return
await
request
.
put
({
url
:
`/iot/product-thing-model/update`
,
data
})
},
},
// 删除产品物模型
// 删除产品物模型
delete
Product
ThinkModel
:
async
(
id
:
number
)
=>
{
deleteThinkModel
:
async
(
id
:
number
)
=>
{
return
await
request
.
delete
({
url
:
`/iot/product-thing-model/delete?id=`
+
id
})
return
await
request
.
delete
({
url
:
`/iot/product-thing-model/delete?id=`
+
id
})
}
}
}
}
src/utils/dict.ts
View file @
9f819db1
/**
/**
* 数据字典工具类
* 数据字典工具类
*/
*/
import
{
useDictStoreWithOut
}
from
'@/store/modules/dict'
import
{
useDictStoreWithOut
}
from
'@/store/modules/dict'
import
{
ElementPlusInfoType
}
from
'@/types/elementPlus'
import
{
ElementPlusInfoType
}
from
'@/types/elementPlus'
const
dictStore
=
useDictStoreWithOut
()
const
dictStore
=
useDictStoreWithOut
()
...
@@ -236,7 +236,7 @@ export enum DICT_TYPE {
...
@@ -236,7 +236,7 @@ export enum DICT_TYPE {
IOT_DATA_FORMAT
=
'iot_data_format'
,
// IOT 数据格式
IOT_DATA_FORMAT
=
'iot_data_format'
,
// IOT 数据格式
IOT_PROTOCOL_TYPE
=
'iot_protocol_type'
,
// IOT 接入网关协议
IOT_PROTOCOL_TYPE
=
'iot_protocol_type'
,
// IOT 接入网关协议
IOT_DEVICE_STATUS
=
'iot_device_status'
,
// IOT 设备状态
IOT_DEVICE_STATUS
=
'iot_device_status'
,
// IOT 设备状态
IOT_PRODUCT_
FUNCTION_TYPE
=
'iot_product_function
_type'
,
// IOT 产品功能类型
IOT_PRODUCT_
THINK_MODEL_TYPE
=
'iot_product_think_model
_type'
,
// IOT 产品功能类型
IOT_DATA_TYPE
=
'iot_data_type'
,
// IOT 数据类型
IOT_DATA_TYPE
=
'iot_data_type'
,
// IOT 数据类型
IOT_UNIT_TYPE
=
'iot_unit_type'
,
// IOT 单位类型
IOT_UNIT_TYPE
=
'iot_unit_type'
,
// IOT 单位类型
IOT_RW_TYPE
=
'iot_rw_type'
,
// IOT 读写类型
IOT_RW_TYPE
=
'iot_rw_type'
,
// IOT 读写类型
...
...
src/views/iot/thinkmodel/ThinkModelDataSpecs.vue
View file @
9f819db1
...
@@ -111,8 +111,9 @@ import {
...
@@ -111,8 +111,9 @@ import {
import
{
ThinkModelProperty
}
from
'@/api/iot/thinkmodel'
import
{
ThinkModelProperty
}
from
'@/api/iot/thinkmodel'
import
{
isEmpty
}
from
'@/utils/is'
import
{
isEmpty
}
from
'@/utils/is'
/** 物模型数据 */
/** IoT 物模型数据 */
defineOptions
({
name
:
'IoTProductThinkModelDataSpecs'
})
defineOptions
({
name
:
'ThinkModelDataSpecs'
})
const
props
=
defineProps
<
{
modelValue
:
any
}
>
()
const
props
=
defineProps
<
{
modelValue
:
any
}
>
()
const
emits
=
defineEmits
([
'update:modelValue'
])
const
emits
=
defineEmits
([
'update:modelValue'
])
const
property
=
useVModel
(
props
,
'modelValue'
,
emits
)
as
Ref
<
ThinkModelProperty
>
const
property
=
useVModel
(
props
,
'modelValue'
,
emits
)
as
Ref
<
ThinkModelProperty
>
...
...
src/views/iot/thinkmodel/ThinkModelForm.vue
View file @
9f819db1
...
@@ -9,9 +9,13 @@
...
@@ -9,9 +9,13 @@
>
>
<el-form-item
label=
"功能类型"
prop=
"type"
>
<el-form-item
label=
"功能类型"
prop=
"type"
>
<el-radio-group
v-model=
"formData.type"
>
<el-radio-group
v-model=
"formData.type"
>
<el-radio-button
:value=
"1"
>
属性
</el-radio-button>
<el-radio-button
<el-radio-button
:value=
"2"
>
服务
</el-radio-button>
v-for=
"dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THINK_MODEL_TYPE)"
<el-radio-button
:value=
"3"
>
事件
</el-radio-button>
:key=
"dict.value"
:value=
"dict.value"
>
{{
dict
.
label
}}
</el-radio-button>
</el-radio-group>
</el-radio-group>
</el-form-item>
</el-form-item>
<el-form-item
label=
"功能名称"
prop=
"name"
>
<el-form-item
label=
"功能名称"
prop=
"name"
>
...
@@ -41,18 +45,20 @@ import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/io
...
@@ -41,18 +45,20 @@ import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/io
import
{
IOT_PROVIDE_KEY
}
from
'@/views/iot/utils/constants'
import
{
IOT_PROVIDE_KEY
}
from
'@/views/iot/utils/constants'
import
{
DataSpecsDataType
}
from
'./config'
import
{
DataSpecsDataType
}
from
'./config'
import
{
cloneDeep
}
from
'lodash-es'
import
{
cloneDeep
}
from
'lodash-es'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
/** IoT 物模型数据表单 */
defineOptions
({
name
:
'IoTProductThinkModelForm'
})
defineOptions
({
name
:
'IoTProductThinkModelForm'
})
const
product
=
inject
<
Ref
<
ProductVO
>>
(
IOT_PROVIDE_KEY
.
PRODUCT
)
// 注入产品信息
const
product
=
inject
<
Ref
<
ProductVO
>>
(
IOT_PROVIDE_KEY
.
PRODUCT
)
// 注入产品信息
const
{
t
}
=
useI18n
()
const
{
t
}
=
useI18n
()
// 国际化
const
message
=
useMessage
()
const
message
=
useMessage
()
// 消息弹窗
const
dialogVisible
=
ref
(
false
)
const
dialogVisible
=
ref
(
false
)
// 弹窗的是否展示
const
dialogTitle
=
ref
(
''
)
const
dialogTitle
=
ref
(
''
)
// 弹窗的标题
const
formLoading
=
ref
(
false
)
const
formLoading
=
ref
(
false
)
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const
formType
=
ref
(
''
)
const
formType
=
ref
(
''
)
// 表单的类型:create - 新增;update - 修改
const
formData
=
ref
<
ThinkModelData
>
({
const
formData
=
ref
<
ThinkModelData
>
({
type
:
ProductFunctionTypeEnum
.
PROPERTY
,
type
:
ProductFunctionTypeEnum
.
PROPERTY
,
dataType
:
DataSpecsDataType
.
INT
,
dataType
:
DataSpecsDataType
.
INT
,
...
@@ -100,7 +106,7 @@ const formRules = reactive({
...
@@ -100,7 +106,7 @@ const formRules = reactive({
}
}
]
]
})
})
const
formRef
=
ref
()
const
formRef
=
ref
()
// 表单 Ref
/** 打开弹窗 */
/** 打开弹窗 */
const
open
=
async
(
type
:
string
,
id
?:
number
)
=>
{
const
open
=
async
(
type
:
string
,
id
?:
number
)
=>
{
...
@@ -111,7 +117,7 @@ const open = async (type: string, id?: number) => {
...
@@ -111,7 +117,7 @@ const open = async (type: string, id?: number) => {
if
(
id
)
{
if
(
id
)
{
formLoading
.
value
=
true
formLoading
.
value
=
true
try
{
try
{
formData
.
value
=
await
ThinkModelApi
.
get
Product
ThinkModel
(
id
)
formData
.
value
=
await
ThinkModelApi
.
getThinkModel
(
id
)
}
finally
{
}
finally
{
formLoading
.
value
=
false
formLoading
.
value
=
false
}
}
...
@@ -134,10 +140,10 @@ const submitForm = async () => {
...
@@ -134,10 +140,10 @@ const submitForm = async () => {
data
.
property
.
identifier
=
data
.
identifier
data
.
property
.
identifier
=
data
.
identifier
data
.
property
.
name
=
data
.
name
data
.
property
.
name
=
data
.
name
if
(
formType
.
value
===
'create'
)
{
if
(
formType
.
value
===
'create'
)
{
await
ThinkModelApi
.
create
Product
ThinkModel
(
data
)
await
ThinkModelApi
.
createThinkModel
(
data
)
message
.
success
(
t
(
'common.createSuccess'
))
message
.
success
(
t
(
'common.createSuccess'
))
}
else
{
}
else
{
await
ThinkModelApi
.
update
Product
ThinkModel
(
data
)
await
ThinkModelApi
.
updateThinkModel
(
data
)
message
.
success
(
t
(
'common.updateSuccess'
))
message
.
success
(
t
(
'common.updateSuccess'
))
}
}
}
finally
{
}
finally
{
...
...
src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue
View file @
9f819db1
...
@@ -37,7 +37,8 @@ import { DataSpecsDataType, dataTypeOptions } from '../config'
...
@@ -37,7 +37,8 @@ import { DataSpecsDataType, dataTypeOptions } from '../config'
import
{
isEmpty
}
from
'@/utils/is'
import
{
isEmpty
}
from
'@/utils/is'
/** 数组型的 dataSpecs 配置组件 */
/** 数组型的 dataSpecs 配置组件 */
defineOptions
({
name
:
'IoTProductThinkModelArrayTypeDataSpecs'
})
defineOptions
({
name
:
'ThinkModelArrayTypeDataSpecs'
})
const
props
=
defineProps
<
{
modelValue
:
any
}
>
()
const
props
=
defineProps
<
{
modelValue
:
any
}
>
()
const
emits
=
defineEmits
([
'update:modelValue'
])
const
emits
=
defineEmits
([
'update:modelValue'
])
const
dataSpecs
=
useVModel
(
props
,
'modelValue'
,
emits
)
as
Ref
<
any
>
const
dataSpecs
=
useVModel
(
props
,
'modelValue'
,
emits
)
as
Ref
<
any
>
...
...
src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue
View file @
9f819db1
...
@@ -48,7 +48,8 @@ import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
...
@@ -48,7 +48,8 @@ import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
import
{
isEmpty
}
from
'@/utils/is'
import
{
isEmpty
}
from
'@/utils/is'
/** 枚举型的 dataSpecs 配置组件 */
/** 枚举型的 dataSpecs 配置组件 */
defineOptions
({
name
:
'IoTProductThinkModelEnumTypeDataSpecs'
})
defineOptions
({
name
:
'ThinkModelEnumTypeDataSpecs'
})
const
props
=
defineProps
<
{
modelValue
:
any
}
>
()
const
props
=
defineProps
<
{
modelValue
:
any
}
>
()
const
emits
=
defineEmits
([
'update:modelValue'
])
const
emits
=
defineEmits
([
'update:modelValue'
])
const
dataSpecsList
=
useVModel
(
props
,
'modelValue'
,
emits
)
as
Ref
<
DataSpecsEnumOrBoolDataVO
[]
>
const
dataSpecsList
=
useVModel
(
props
,
'modelValue'
,
emits
)
as
Ref
<
DataSpecsEnumOrBoolDataVO
[]
>
...
...
src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue
View file @
9f819db1
...
@@ -62,7 +62,8 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
...
@@ -62,7 +62,8 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
import
{
DataSpecsNumberDataVO
}
from
'../config'
import
{
DataSpecsNumberDataVO
}
from
'../config'
/** 数值型的 dataSpecs 配置组件 */
/** 数值型的 dataSpecs 配置组件 */
defineOptions
({
name
:
'IoTProductThinkModelNumberTypeDataSpecs'
})
defineOptions
({
name
:
'ThinkModelNumberTypeDataSpecs'
})
const
props
=
defineProps
<
{
modelValue
:
any
}
>
()
const
props
=
defineProps
<
{
modelValue
:
any
}
>
()
const
emits
=
defineEmits
([
'update:modelValue'
])
const
emits
=
defineEmits
([
'update:modelValue'
])
const
dataSpecs
=
useVModel
(
props
,
'modelValue'
,
emits
)
as
Ref
<
DataSpecsNumberDataVO
>
const
dataSpecs
=
useVModel
(
props
,
'modelValue'
,
emits
)
as
Ref
<
DataSpecsNumberDataVO
>
...
@@ -74,7 +75,7 @@ const unitChange = (UnitSpecs: string) => {
...
@@ -74,7 +75,7 @@ const unitChange = (UnitSpecs: string) => {
dataSpecs
.
value
.
unit
=
unit
dataSpecs
.
value
.
unit
=
unit
}
}
/
/ 校验最小值
/
** 校验最小值 */
const
validateMin
=
(
_
:
any
,
__
:
any
,
callback
:
any
)
=>
{
const
validateMin
=
(
_
:
any
,
__
:
any
,
callback
:
any
)
=>
{
const
min
=
Number
(
dataSpecs
.
value
.
min
)
const
min
=
Number
(
dataSpecs
.
value
.
min
)
const
max
=
Number
(
dataSpecs
.
value
.
max
)
const
max
=
Number
(
dataSpecs
.
value
.
max
)
...
@@ -92,7 +93,7 @@ const validateMin = (_: any, __: any, callback: any) => {
...
@@ -92,7 +93,7 @@ const validateMin = (_: any, __: any, callback: any) => {
callback
()
callback
()
}
}
/
/ 校验最大值
/
** 校验最大值 */
const
validateMax
=
(
_
:
any
,
__
:
any
,
callback
:
any
)
=>
{
const
validateMax
=
(
_
:
any
,
__
:
any
,
callback
:
any
)
=>
{
const
min
=
Number
(
dataSpecs
.
value
.
min
)
const
min
=
Number
(
dataSpecs
.
value
.
min
)
const
max
=
Number
(
dataSpecs
.
value
.
max
)
const
max
=
Number
(
dataSpecs
.
value
.
max
)
...
@@ -110,7 +111,7 @@ const validateMax = (_: any, __: any, callback: any) => {
...
@@ -110,7 +111,7 @@ const validateMax = (_: any, __: any, callback: any) => {
callback
()
callback
()
}
}
/
/ 校验步长
/
** 校验步长 */
const
validateStep
=
(
_
:
any
,
__
:
any
,
callback
:
any
)
=>
{
const
validateStep
=
(
_
:
any
,
__
:
any
,
callback
:
any
)
=>
{
const
step
=
Number
(
dataSpecs
.
value
.
step
)
const
step
=
Number
(
dataSpecs
.
value
.
step
)
const
min
=
Number
(
dataSpecs
.
value
.
min
)
const
min
=
Number
(
dataSpecs
.
value
.
min
)
...
...
src/views/iot/thinkmodel/index.vue
View file @
9f819db1
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
placeholder=
"请选择功能类型"
placeholder=
"请选择功能类型"
>
>
<el-option
<el-option
v-for=
"dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_
FUNCTION
_TYPE)"
v-for=
"dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_
THINK_MODEL
_TYPE)"
:key=
"dict.value"
:key=
"dict.value"
:label=
"dict.label"
:label=
"dict.label"
:value=
"dict.value"
:value=
"dict.value"
...
@@ -50,7 +50,7 @@
...
@@ -50,7 +50,7 @@
<el-table
v-loading=
"loading"
:data=
"list"
:show-overflow-tooltip=
"true"
:stripe=
"true"
>
<el-table
v-loading=
"loading"
:data=
"list"
:show-overflow-tooltip=
"true"
:stripe=
"true"
>
<el-table-column
align=
"center"
label=
"功能类型"
prop=
"type"
>
<el-table-column
align=
"center"
label=
"功能类型"
prop=
"type"
>
<template
#
default=
"scope"
>
<template
#
default=
"scope"
>
<dict-tag
:type=
"DICT_TYPE.IOT_PRODUCT_
FUNCTION
_TYPE"
:value=
"scope.row.type"
/>
<dict-tag
:type=
"DICT_TYPE.IOT_PRODUCT_
THINK_MODEL
_TYPE"
:value=
"scope.row.type"
/>
</
template
>
</
template
>
</el-table-column>
</el-table-column>
<el-table-column
align=
"center"
label=
"功能名称"
prop=
"name"
/>
<el-table-column
align=
"center"
label=
"功能名称"
prop=
"name"
/>
...
@@ -131,7 +131,7 @@ const getList = async () => {
...
@@ -131,7 +131,7 @@ const getList = async () => {
loading
.
value
=
true
loading
.
value
=
true
try
{
try
{
queryParams
.
productId
=
product
?.
value
?.
id
||
-
1
queryParams
.
productId
=
product
?.
value
?.
id
||
-
1
const
data
=
await
ThinkModelApi
.
get
Product
ThinkModelPage
(
queryParams
)
const
data
=
await
ThinkModelApi
.
getThinkModelPage
(
queryParams
)
list
.
value
=
data
.
list
list
.
value
=
data
.
list
total
.
value
=
data
.
total
total
.
value
=
data
.
total
}
finally
{
}
finally
{
...
@@ -163,7 +163,7 @@ const handleDelete = async (id: number) => {
...
@@ -163,7 +163,7 @@ const handleDelete = async (id: number) => {
// 删除的二次确认
// 删除的二次确认
await
message
.
delConfirm
()
await
message
.
delConfirm
()
// 发起删除
// 发起删除
await
ThinkModelApi
.
delete
Product
ThinkModel
(
id
)
await
ThinkModelApi
.
deleteThinkModel
(
id
)
message
.
success
(
t
(
'common.delSuccess'
))
message
.
success
(
t
(
'common.delSuccess'
))
// 刷新列表
// 刷新列表
await
getList
()
await
getList
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment