【代码优化】IOT: ThingModel 优化

This commit is contained in:
puhui999 2024-12-23 10:13:14 +08:00
parent b6d3a85a8b
commit d5f3d4006a
12 changed files with 62 additions and 63 deletions

View File

@ -3,7 +3,7 @@ import request from '@/config/axios'
/** /**
* IoT * IoT
*/ */
export interface ThinkModelData { export interface ThingModelData {
id?: number // 物模型功能编号 id?: number // 物模型功能编号
identifier?: string // 功能标识 identifier?: string // 功能标识
name?: string // 功能名称 name?: string // 功能名称
@ -12,29 +12,29 @@ export interface ThinkModelData {
productKey?: string // 产品标识 productKey?: string // 产品标识
dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致 dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致
type: ProductFunctionTypeEnum // 功能类型 type: ProductFunctionTypeEnum // 功能类型
property: ThinkModelProperty // 属性 property: ThingModelProperty // 属性
event?: ThinkModelEvent // 事件 event?: ThingModelEvent // 事件
service?: ThinkModelService // 服务 service?: ThingModelService // 服务
} }
/** /**
* ThinkModelProperty * ThingModelProperty
*/ */
export interface ThinkModelProperty { export interface ThingModelProperty {
[key: string]: any [key: string]: any
} }
/** /**
* ThinkModelEvent * ThingModelEvent
*/ */
export interface ThinkModelEvent { export interface ThingModelEvent {
[key: string]: any [key: string]: any
} }
/** /**
* ThinkModelService * ThingModelService
*/ */
export interface ThinkModelService { export interface ThingModelService {
[key: string]: any [key: string]: any
} }
@ -52,38 +52,37 @@ export enum ProductFunctionAccessModeEnum {
} }
// IoT 产品物模型 API // IoT 产品物模型 API
export const ThinkModelApi = { export const ThingModelApi = {
// 查询产品物模型分页 // 查询产品物模型分页
// TODO @puhui999product 前缀,是不是去掉哈。 getThingModelPage: 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-think-model/page`, params })
}, },
// 获得产品物模型 // 获得产品物模型
getThinkModelListByProductId: async (params: any) => { getThingModelListByProductId: async (params: any) => {
return await request.get({ return await request.get({
url: `/iot/product-think-model/list-by-product-id`, url: `/iot/product-thing-model/list-by-product-id`,
params params
}) })
}, },
// 查询产品物模型详情 // 查询产品物模型详情
getThinkModel: async (id: number) => { getThingModel: async (id: number) => {
return await request.get({ url: `/iot/product-think-model/get?id=` + id }) return await request.get({ url: `/iot/product-thing-model/get?id=` + id })
}, },
// 新增产品物模型 // 新增产品物模型
createThinkModel: async (data: ThinkModelData) => { createThingModel: async (data: ThingModelData) => {
return await request.post({ url: `/iot/product-think-model/create`, data }) return await request.post({ url: `/iot/product-thing-model/create`, data })
}, },
// 修改产品物模型 // 修改产品物模型
updateThinkModel: async (data: ThinkModelData) => { updateThingModel: async (data: ThingModelData) => {
return await request.put({ url: `/iot/product-think-model/update`, data }) return await request.put({ url: `/iot/product-thing-model/update`, data })
}, },
// 删除产品物模型 // 删除产品物模型
deleteThinkModel: async (id: number) => { deleteThingModel: async (id: number) => {
return await request.delete({ url: `/iot/product-think-model/delete?id=` + id }) return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id })
} }
} }

View File

@ -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_THINK_MODEL_TYPE = 'iot_product_think_model_type', // IOT 产品功能类型 IOT_PRODUCT_THING_MODEL_TYPE = 'iot_product_thing_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 读写类型

View File

@ -22,7 +22,7 @@ import { DeviceApi } from '@/api/iot/device/device'
import ProductDetailsHeader from './ProductDetailsHeader.vue' import ProductDetailsHeader from './ProductDetailsHeader.vue'
import ProductDetailsInfo from './ProductDetailsInfo.vue' import ProductDetailsInfo from './ProductDetailsInfo.vue'
import ProductTopic from './ProductTopic.vue' import ProductTopic from './ProductTopic.vue'
import IoTProductThinkModel from '@/views/iot/thinkmodel/index.vue' import IoTProductThinkModel from '@/views/iot/thingmodel/index.vue'
import { useTagsViewStore } from '@/store/modules/tagsView' import { useTagsViewStore } from '@/store/modules/tagsView'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'

View File

@ -14,7 +14,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- 数值型配置 --> <!-- 数值型配置 -->
<ThinkModelNumberTypeDataSpecs <ThingModelNumberTypeDataSpecs
v-if=" v-if="
[DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes( [DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes(
property.dataType || '' property.dataType || ''
@ -23,7 +23,7 @@
v-model="property.dataSpecs" v-model="property.dataSpecs"
/> />
<!-- 枚举型配置 --> <!-- 枚举型配置 -->
<ThinkModelEnumTypeDataSpecs <ThingModelEnumTypeDataSpecs
v-if="property.dataType === DataSpecsDataType.ENUM" v-if="property.dataType === DataSpecsDataType.ENUM"
v-model="property.dataSpecsList" v-model="property.dataSpecsList"
/> />
@ -74,7 +74,7 @@
<el-input class="w-255px!" disabled placeholder="String类型的UTC时间戳毫秒" /> <el-input class="w-255px!" disabled placeholder="String类型的UTC时间戳毫秒" />
</el-form-item> </el-form-item>
<!-- 数组型配置--> <!-- 数组型配置-->
<ThinkModelArrayTypeDataSpecs <ThingModelArrayTypeDataSpecs
v-if="property.dataType === DataSpecsDataType.ARRAY" v-if="property.dataType === DataSpecsDataType.ARRAY"
v-model="property.dataSpecs" v-model="property.dataSpecs"
/> />
@ -104,19 +104,19 @@
import { useVModel } from '@vueuse/core' import { useVModel } from '@vueuse/core'
import { DataSpecsDataType, dataTypeOptions } from './config' import { DataSpecsDataType, dataTypeOptions } from './config'
import { import {
ThinkModelArrayTypeDataSpecs, ThingModelArrayTypeDataSpecs,
ThinkModelEnumTypeDataSpecs, ThingModelEnumTypeDataSpecs,
ThinkModelNumberTypeDataSpecs ThingModelNumberTypeDataSpecs
} from './dataSpecs' } from './dataSpecs'
import { ThinkModelProperty } from '@/api/iot/thinkmodel' import { ThingModelProperty } from 'src/api/iot/thingmodel'
import { isEmpty } from '@/utils/is' import { isEmpty } from '@/utils/is'
/** IoT 物模型数据 */ /** IoT 物模型数据 */
defineOptions({ name: 'ThinkModelDataSpecs' }) defineOptions({ name: 'ThingModelDataSpecs' })
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<ThingModelProperty>
/** 属性值的数据类型切换时初始化相关数据 */ /** 属性值的数据类型切换时初始化相关数据 */
const handleChange = (dataType: any) => { const handleChange = (dataType: any) => {

View File

@ -10,7 +10,7 @@
<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 <el-radio-button
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THINK_MODEL_TYPE)" v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THING_MODEL_TYPE)"
:key="dict.value" :key="dict.value"
:value="dict.value" :value="dict.value"
> >
@ -25,7 +25,7 @@
<el-input v-model="formData.identifier" placeholder="请输入标识符" /> <el-input v-model="formData.identifier" placeholder="请输入标识符" />
</el-form-item> </el-form-item>
<!-- 属性配置 --> <!-- 属性配置 -->
<ThinkModelDataSpecs <ThingModelDataSpecs
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY" v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
v-model="formData.property" v-model="formData.property"
/> />
@ -40,15 +40,15 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ProductVO } from '@/api/iot/product/product' import { ProductVO } from '@/api/iot/product/product'
import ThinkModelDataSpecs from './ThinkModelDataSpecs.vue' import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/iot/thinkmodel' import { ProductFunctionTypeEnum, ThingModelApi, ThingModelData } from 'src/api/iot/thingmodel'
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' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
/** IoT 物模型数据表单 */ /** IoT 物模型数据表单 */
defineOptions({ name: 'IoTProductThinkModelForm' }) defineOptions({ name: 'IoTProductThingModelForm' })
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) //
@ -59,7 +59,7 @@ const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // const dialogTitle = ref('') //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formType = ref('') // create - update - const formType = ref('') // create - update -
const formData = ref<ThinkModelData>({ const formData = ref<ThingModelData>({
type: ProductFunctionTypeEnum.PROPERTY, type: ProductFunctionTypeEnum.PROPERTY,
dataType: DataSpecsDataType.INT, dataType: DataSpecsDataType.INT,
property: { property: {
@ -117,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.getThinkModel(id) formData.value = await ThingModelApi.getThingModel(id)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -131,7 +131,7 @@ const submitForm = async () => {
await formRef.value.validate() await formRef.value.validate()
formLoading.value = true formLoading.value = true
try { try {
const data = cloneDeep(formData.value) as ThinkModelData const data = cloneDeep(formData.value) as ThingModelData
// //
data.productId = product!.value.id data.productId = product!.value.id
data.productKey = product!.value.productKey data.productKey = product!.value.productKey
@ -140,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.createThinkModel(data) await ThingModelApi.createThingModel(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await ThinkModelApi.updateThinkModel(data) await ThingModelApi.updateThingModel(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
} finally { } finally {

View File

@ -39,7 +39,7 @@ import { isEmpty } from '@/utils/is'
// TODO @puhui999 // TODO @puhui999
/** 数组型的 dataSpecs 配置组件 */ /** 数组型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThinkModelArrayTypeDataSpecs' }) defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])

View File

@ -48,7 +48,7 @@ import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
import { isEmpty } from '@/utils/is' import { isEmpty } from '@/utils/is'
/** 枚举型的 dataSpecs 配置组件 */ /** 枚举型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThinkModelEnumTypeDataSpecs' }) defineOptions({ name: 'ThingModelEnumTypeDataSpecs' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])

View File

@ -62,7 +62,7 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
import { DataSpecsNumberDataVO } from '../config' import { DataSpecsNumberDataVO } from '../config'
/** 数值型的 dataSpecs 配置组件 */ /** 数值型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThinkModelNumberTypeDataSpecs' }) defineOptions({ name: 'ThingModelNumberTypeDataSpecs' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])

View File

@ -0,0 +1,5 @@
import ThingModelEnumTypeDataSpecs from './ThingModelEnumTypeDataSpecs.vue'
import ThingModelNumberTypeDataSpecs from './ThingModelNumberTypeDataSpecs.vue'
import ThingModelArrayTypeDataSpecs from './ThingModelArrayTypeDataSpecs.vue'
export { ThingModelEnumTypeDataSpecs, ThingModelNumberTypeDataSpecs, ThingModelArrayTypeDataSpecs }

View File

@ -17,7 +17,7 @@
placeholder="请选择功能类型" placeholder="请选择功能类型"
> >
<el-option <el-option
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THINK_MODEL_TYPE)" v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_THING_MODEL_TYPE)"
:key="dict.value" :key="dict.value"
:label="dict.label" :label="dict.label"
:value="dict.value" :value="dict.value"
@ -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_THINK_MODEL_TYPE" :value="scope.row.type" /> <dict-tag :type="DICT_TYPE.IOT_PRODUCT_THING_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" />
@ -97,23 +97,23 @@
</el-tabs> </el-tabs>
</ContentWrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<ThinkModelForm ref="formRef" @success="getList" /> <ThingModelForm ref="formRef" @success="getList" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ThinkModelApi, ThinkModelData } from '@/api/iot/thinkmodel' import { ThingModelApi, ThingModelData } from 'src/api/iot/thingmodel'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import ThinkModelForm from './ThinkModelForm.vue' import ThingModelForm from './ThingModelForm.vue'
import { ProductVO } from '@/api/iot/product/product' import { ProductVO } from '@/api/iot/product/product'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
import { getDataTypeOptionsLabel } from '@/views/iot/thinkmodel/config' import { getDataTypeOptionsLabel } from '@/views/iot/thingmodel/config'
defineOptions({ name: 'IoTProductThinkModel' }) defineOptions({ name: 'IoTProductThingModel' })
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const loading = ref(true) // const loading = ref(true) //
const list = ref<ThinkModelData[]>([]) // const list = ref<ThingModelData[]>([]) //
const total = ref(0) // const total = ref(0) //
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
@ -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.getThinkModelPage(queryParams) const data = await ThingModelApi.getThingModelPage(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) => {
// //
await message.delConfirm() await message.delConfirm()
// //
await ThinkModelApi.deleteThinkModel(id) await ThingModelApi.deleteThingModel(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// //
await getList() await getList()

View File

@ -1,5 +0,0 @@
import ThinkModelEnumTypeDataSpecs from './ThinkModelEnumTypeDataSpecs.vue'
import ThinkModelNumberTypeDataSpecs from './ThinkModelNumberTypeDataSpecs.vue'
import ThinkModelArrayTypeDataSpecs from './ThinkModelArrayTypeDataSpecs.vue'
export { ThinkModelEnumTypeDataSpecs, ThinkModelNumberTypeDataSpecs, ThinkModelArrayTypeDataSpecs }