【代码优化】IOT: 产品物模型代码评审问题优化
parent
53c967c308
commit
9f819db14d
|
@ -51,16 +51,15 @@ export enum ProductFunctionAccessModeEnum {
|
|||
READ_ONLY = 'r' // 只读
|
||||
}
|
||||
|
||||
// TODO @puhui999:getProductThingModelPage => getThingModelPage 哈,不用带 product 前缀
|
||||
// IoT 产品物模型 API
|
||||
export const ThinkModelApi = {
|
||||
// 查询产品物模型分页
|
||||
getProductThinkModelPage: async (params: any) => {
|
||||
getThinkModelPage: async (params: any) => {
|
||||
return await request.get({ url: `/iot/product-thing-model/page`, params })
|
||||
},
|
||||
|
||||
// 获得产品物模型
|
||||
getProductThinkModelListByProductId: async (params: any) => {
|
||||
getThinkModelListByProductId: async (params: any) => {
|
||||
return await request.get({
|
||||
url: `/iot/product-thing-model/list-by-product-id`,
|
||||
params
|
||||
|
@ -68,22 +67,22 @@ export const ThinkModelApi = {
|
|||
},
|
||||
|
||||
// 查询产品物模型详情
|
||||
getProductThinkModel: async (id: number) => {
|
||||
getThinkModel: async (id: number) => {
|
||||
return await request.get({ url: `/iot/product-thing-model/get?id=` + id })
|
||||
},
|
||||
|
||||
// 新增产品物模型
|
||||
createProductThinkModel: async (data: ThinkModelData) => {
|
||||
createThinkModel: async (data: ThinkModelData) => {
|
||||
return await request.post({ url: `/iot/product-thing-model/create`, data })
|
||||
},
|
||||
|
||||
// 修改产品物模型
|
||||
updateProductThinkModel: async (data: ThinkModelData) => {
|
||||
updateThinkModel: async (data: ThinkModelData) => {
|
||||
return await request.put({ url: `/iot/product-thing-model/update`, data })
|
||||
},
|
||||
|
||||
// 删除产品物模型
|
||||
deleteProductThinkModel: async (id: number) => {
|
||||
deleteThinkModel: async (id: number) => {
|
||||
return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/**
|
||||
* 数据字典工具类
|
||||
*/
|
||||
import { useDictStoreWithOut } from '@/store/modules/dict'
|
||||
import { ElementPlusInfoType } from '@/types/elementPlus'
|
||||
import {useDictStoreWithOut} from '@/store/modules/dict'
|
||||
import {ElementPlusInfoType} from '@/types/elementPlus'
|
||||
|
||||
const dictStore = useDictStoreWithOut()
|
||||
|
||||
|
@ -236,7 +236,7 @@ export enum DICT_TYPE {
|
|||
IOT_DATA_FORMAT = 'iot_data_format', // IOT 数据格式
|
||||
IOT_PROTOCOL_TYPE = 'iot_protocol_type', // 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_UNIT_TYPE = 'iot_unit_type', // IOT 单位类型
|
||||
IOT_RW_TYPE = 'iot_rw_type', // IOT 读写类型
|
||||
|
|
|
@ -111,8 +111,9 @@ import {
|
|||
import { ThinkModelProperty } from '@/api/iot/thinkmodel'
|
||||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
/** 物模型数据 */
|
||||
defineOptions({ name: 'IoTProductThinkModelDataSpecs' })
|
||||
/** IoT 物模型数据 */
|
||||
defineOptions({ name: 'ThinkModelDataSpecs' })
|
||||
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const property = useVModel(props, 'modelValue', emits) as Ref<ThinkModelProperty>
|
||||
|
|
|
@ -9,9 +9,13 @@
|
|||
>
|
||||
<el-form-item label="功能类型" prop="type">
|
||||
<el-radio-group v-model="formData.type">
|
||||
<el-radio-button :value="1"> 属性</el-radio-button>
|
||||
<el-radio-button :value="2"> 服务</el-radio-button>
|
||||
<el-radio-button :value="3"> 事件</el-radio-button>
|
||||
<el-radio-button
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THINK_MODEL_TYPE)"
|
||||
:key="dict.value"
|
||||
:value="dict.value"
|
||||
>
|
||||
{{ dict.label }}
|
||||
</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="功能名称" prop="name">
|
||||
|
@ -41,18 +45,20 @@ import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/io
|
|||
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
|
||||
import { DataSpecsDataType } from './config'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
|
||||
/** IoT 物模型数据表单 */
|
||||
defineOptions({ name: 'IoTProductThinkModelForm' })
|
||||
|
||||
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // 注入产品信息
|
||||
|
||||
const { t } = useI18n()
|
||||
const message = useMessage()
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const formLoading = ref(false)
|
||||
const formType = ref('')
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref<ThinkModelData>({
|
||||
type: ProductFunctionTypeEnum.PROPERTY,
|
||||
dataType: DataSpecsDataType.INT,
|
||||
|
@ -100,7 +106,7 @@ const formRules = reactive({
|
|||
}
|
||||
]
|
||||
})
|
||||
const formRef = ref()
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
|
@ -111,7 +117,7 @@ const open = async (type: string, id?: number) => {
|
|||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await ThinkModelApi.getProductThinkModel(id)
|
||||
formData.value = await ThinkModelApi.getThinkModel(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
|
@ -134,10 +140,10 @@ const submitForm = async () => {
|
|||
data.property.identifier = data.identifier
|
||||
data.property.name = data.name
|
||||
if (formType.value === 'create') {
|
||||
await ThinkModelApi.createProductThinkModel(data)
|
||||
await ThinkModelApi.createThinkModel(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await ThinkModelApi.updateProductThinkModel(data)
|
||||
await ThinkModelApi.updateThinkModel(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
} finally {
|
||||
|
|
|
@ -37,7 +37,8 @@ import { DataSpecsDataType, dataTypeOptions } from '../config'
|
|||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
/** 数组型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'IoTProductThinkModelArrayTypeDataSpecs' })
|
||||
defineOptions({ name: 'ThinkModelArrayTypeDataSpecs' })
|
||||
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<any>
|
||||
|
|
|
@ -48,7 +48,8 @@ import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
|
|||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
/** 枚举型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'IoTProductThinkModelEnumTypeDataSpecs' })
|
||||
defineOptions({ name: 'ThinkModelEnumTypeDataSpecs' })
|
||||
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref<DataSpecsEnumOrBoolDataVO[]>
|
||||
|
|
|
@ -62,7 +62,8 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
|
|||
import { DataSpecsNumberDataVO } from '../config'
|
||||
|
||||
/** 数值型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'IoTProductThinkModelNumberTypeDataSpecs' })
|
||||
defineOptions({ name: 'ThinkModelNumberTypeDataSpecs' })
|
||||
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<DataSpecsNumberDataVO>
|
||||
|
@ -74,7 +75,7 @@ const unitChange = (UnitSpecs: string) => {
|
|||
dataSpecs.value.unit = unit
|
||||
}
|
||||
|
||||
// 校验最小值
|
||||
/** 校验最小值 */
|
||||
const validateMin = (_: any, __: any, callback: any) => {
|
||||
const min = Number(dataSpecs.value.min)
|
||||
const max = Number(dataSpecs.value.max)
|
||||
|
@ -92,7 +93,7 @@ const validateMin = (_: any, __: any, callback: any) => {
|
|||
callback()
|
||||
}
|
||||
|
||||
// 校验最大值
|
||||
/** 校验最大值 */
|
||||
const validateMax = (_: any, __: any, callback: any) => {
|
||||
const min = Number(dataSpecs.value.min)
|
||||
const max = Number(dataSpecs.value.max)
|
||||
|
@ -110,7 +111,7 @@ const validateMax = (_: any, __: any, callback: any) => {
|
|||
callback()
|
||||
}
|
||||
|
||||
// 校验步长
|
||||
/** 校验步长 */
|
||||
const validateStep = (_: any, __: any, callback: any) => {
|
||||
const step = Number(dataSpecs.value.step)
|
||||
const min = Number(dataSpecs.value.min)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
placeholder="请选择功能类型"
|
||||
>
|
||||
<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"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
|
@ -50,7 +50,7 @@
|
|||
<el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
|
||||
<el-table-column align="center" label="功能类型" prop="type">
|
||||
<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>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" label="功能名称" prop="name" />
|
||||
|
@ -131,7 +131,7 @@ const getList = async () => {
|
|||
loading.value = true
|
||||
try {
|
||||
queryParams.productId = product?.value?.id || -1
|
||||
const data = await ThinkModelApi.getProductThinkModelPage(queryParams)
|
||||
const data = await ThinkModelApi.getThinkModelPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
} finally {
|
||||
|
@ -163,7 +163,7 @@ const handleDelete = async (id: number) => {
|
|||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
await ThinkModelApi.deleteProductThinkModel(id)
|
||||
await ThinkModelApi.deleteThinkModel(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
|
|
Loading…
Reference in New Issue