mirror of
https://gitee.com/myxzgzs/boyue-ui-admin-vue3
synced 2025-08-08 16:32:43 +08:00
【代码优化】IOT: ThingModel 优化
This commit is contained in:
parent
b6d3a85a8b
commit
d5f3d4006a
@ -3,7 +3,7 @@ import request from '@/config/axios'
|
||||
/**
|
||||
* IoT 产品物模型
|
||||
*/
|
||||
export interface ThinkModelData {
|
||||
export interface ThingModelData {
|
||||
id?: number // 物模型功能编号
|
||||
identifier?: string // 功能标识
|
||||
name?: string // 功能名称
|
||||
@ -12,29 +12,29 @@ export interface ThinkModelData {
|
||||
productKey?: string // 产品标识
|
||||
dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致
|
||||
type: ProductFunctionTypeEnum // 功能类型
|
||||
property: ThinkModelProperty // 属性
|
||||
event?: ThinkModelEvent // 事件
|
||||
service?: ThinkModelService // 服务
|
||||
property: ThingModelProperty // 属性
|
||||
event?: ThingModelEvent // 事件
|
||||
service?: ThingModelService // 服务
|
||||
}
|
||||
|
||||
/**
|
||||
* ThinkModelProperty 类型
|
||||
* ThingModelProperty 类型
|
||||
*/
|
||||
export interface ThinkModelProperty {
|
||||
export interface ThingModelProperty {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/**
|
||||
* ThinkModelEvent 类型
|
||||
* ThingModelEvent 类型
|
||||
*/
|
||||
export interface ThinkModelEvent {
|
||||
export interface ThingModelEvent {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/**
|
||||
* ThinkModelService 类型
|
||||
* ThingModelService 类型
|
||||
*/
|
||||
export interface ThinkModelService {
|
||||
export interface ThingModelService {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
@ -52,38 +52,37 @@ export enum ProductFunctionAccessModeEnum {
|
||||
}
|
||||
|
||||
// IoT 产品物模型 API
|
||||
export const ThinkModelApi = {
|
||||
export const ThingModelApi = {
|
||||
// 查询产品物模型分页
|
||||
// TODO @puhui999:product 前缀,是不是去掉哈。
|
||||
getThinkModelPage: async (params: any) => {
|
||||
return await request.get({ url: `/iot/product-think-model/page`, params })
|
||||
getThingModelPage: async (params: any) => {
|
||||
return await request.get({ url: `/iot/product-thing-model/page`, params })
|
||||
},
|
||||
|
||||
// 获得产品物模型
|
||||
getThinkModelListByProductId: async (params: any) => {
|
||||
getThingModelListByProductId: async (params: any) => {
|
||||
return await request.get({
|
||||
url: `/iot/product-think-model/list-by-product-id`,
|
||||
url: `/iot/product-thing-model/list-by-product-id`,
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
// 查询产品物模型详情
|
||||
getThinkModel: async (id: number) => {
|
||||
return await request.get({ url: `/iot/product-think-model/get?id=` + id })
|
||||
getThingModel: async (id: number) => {
|
||||
return await request.get({ url: `/iot/product-thing-model/get?id=` + id })
|
||||
},
|
||||
|
||||
// 新增产品物模型
|
||||
createThinkModel: async (data: ThinkModelData) => {
|
||||
return await request.post({ url: `/iot/product-think-model/create`, data })
|
||||
createThingModel: async (data: ThingModelData) => {
|
||||
return await request.post({ url: `/iot/product-thing-model/create`, data })
|
||||
},
|
||||
|
||||
// 修改产品物模型
|
||||
updateThinkModel: async (data: ThinkModelData) => {
|
||||
return await request.put({ url: `/iot/product-think-model/update`, data })
|
||||
updateThingModel: async (data: ThingModelData) => {
|
||||
return await request.put({ url: `/iot/product-thing-model/update`, data })
|
||||
},
|
||||
|
||||
// 删除产品物模型
|
||||
deleteThinkModel: async (id: number) => {
|
||||
return await request.delete({ url: `/iot/product-think-model/delete?id=` + id })
|
||||
deleteThingModel: async (id: number) => {
|
||||
return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id })
|
||||
}
|
||||
}
|
@ -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_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_UNIT_TYPE = 'iot_unit_type', // IOT 单位类型
|
||||
IOT_RW_TYPE = 'iot_rw_type', // IOT 读写类型
|
||||
|
@ -22,7 +22,7 @@ import { DeviceApi } from '@/api/iot/device/device'
|
||||
import ProductDetailsHeader from './ProductDetailsHeader.vue'
|
||||
import ProductDetailsInfo from './ProductDetailsInfo.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 { useRouter } from 'vue-router'
|
||||
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
|
||||
|
@ -14,7 +14,7 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<!-- 数值型配置 -->
|
||||
<ThinkModelNumberTypeDataSpecs
|
||||
<ThingModelNumberTypeDataSpecs
|
||||
v-if="
|
||||
[DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes(
|
||||
property.dataType || ''
|
||||
@ -23,7 +23,7 @@
|
||||
v-model="property.dataSpecs"
|
||||
/>
|
||||
<!-- 枚举型配置 -->
|
||||
<ThinkModelEnumTypeDataSpecs
|
||||
<ThingModelEnumTypeDataSpecs
|
||||
v-if="property.dataType === DataSpecsDataType.ENUM"
|
||||
v-model="property.dataSpecsList"
|
||||
/>
|
||||
@ -74,7 +74,7 @@
|
||||
<el-input class="w-255px!" disabled placeholder="String类型的UTC时间戳(毫秒)" />
|
||||
</el-form-item>
|
||||
<!-- 数组型配置-->
|
||||
<ThinkModelArrayTypeDataSpecs
|
||||
<ThingModelArrayTypeDataSpecs
|
||||
v-if="property.dataType === DataSpecsDataType.ARRAY"
|
||||
v-model="property.dataSpecs"
|
||||
/>
|
||||
@ -104,19 +104,19 @@
|
||||
import { useVModel } from '@vueuse/core'
|
||||
import { DataSpecsDataType, dataTypeOptions } from './config'
|
||||
import {
|
||||
ThinkModelArrayTypeDataSpecs,
|
||||
ThinkModelEnumTypeDataSpecs,
|
||||
ThinkModelNumberTypeDataSpecs
|
||||
ThingModelArrayTypeDataSpecs,
|
||||
ThingModelEnumTypeDataSpecs,
|
||||
ThingModelNumberTypeDataSpecs
|
||||
} from './dataSpecs'
|
||||
import { ThinkModelProperty } from '@/api/iot/thinkmodel'
|
||||
import { ThingModelProperty } from 'src/api/iot/thingmodel'
|
||||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
/** IoT 物模型数据 */
|
||||
defineOptions({ name: 'ThinkModelDataSpecs' })
|
||||
defineOptions({ name: 'ThingModelDataSpecs' })
|
||||
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
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) => {
|
@ -10,7 +10,7 @@
|
||||
<el-form-item label="功能类型" prop="type">
|
||||
<el-radio-group v-model="formData.type">
|
||||
<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"
|
||||
:value="dict.value"
|
||||
>
|
||||
@ -25,7 +25,7 @@
|
||||
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
|
||||
</el-form-item>
|
||||
<!-- 属性配置 -->
|
||||
<ThinkModelDataSpecs
|
||||
<ThingModelDataSpecs
|
||||
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
|
||||
v-model="formData.property"
|
||||
/>
|
||||
@ -40,15 +40,15 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ProductVO } from '@/api/iot/product/product'
|
||||
import ThinkModelDataSpecs from './ThinkModelDataSpecs.vue'
|
||||
import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/iot/thinkmodel'
|
||||
import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
|
||||
import { ProductFunctionTypeEnum, ThingModelApi, ThingModelData } from 'src/api/iot/thingmodel'
|
||||
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' })
|
||||
defineOptions({ name: 'IoTProductThingModelForm' })
|
||||
|
||||
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // 注入产品信息
|
||||
|
||||
@ -59,7 +59,7 @@ const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref<ThinkModelData>({
|
||||
const formData = ref<ThingModelData>({
|
||||
type: ProductFunctionTypeEnum.PROPERTY,
|
||||
dataType: DataSpecsDataType.INT,
|
||||
property: {
|
||||
@ -117,7 +117,7 @@ const open = async (type: string, id?: number) => {
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await ThinkModelApi.getThinkModel(id)
|
||||
formData.value = await ThingModelApi.getThingModel(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
@ -131,7 +131,7 @@ const submitForm = async () => {
|
||||
await formRef.value.validate()
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = cloneDeep(formData.value) as ThinkModelData
|
||||
const data = cloneDeep(formData.value) as ThingModelData
|
||||
// 信息补全
|
||||
data.productId = product!.value.id
|
||||
data.productKey = product!.value.productKey
|
||||
@ -140,10 +140,10 @@ const submitForm = async () => {
|
||||
data.property.identifier = data.identifier
|
||||
data.property.name = data.name
|
||||
if (formType.value === 'create') {
|
||||
await ThinkModelApi.createThinkModel(data)
|
||||
await ThingModelApi.createThingModel(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await ThinkModelApi.updateThinkModel(data)
|
||||
await ThingModelApi.updateThingModel(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
} finally {
|
@ -39,7 +39,7 @@ import { isEmpty } from '@/utils/is'
|
||||
// TODO @puhui999:参数校验,是不是还是定义一个变量,统一管,好阅读点哈?
|
||||
|
||||
/** 数组型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'ThinkModelArrayTypeDataSpecs' })
|
||||
defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
|
||||
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
@ -48,7 +48,7 @@ import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
|
||||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
/** 枚举型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'ThinkModelEnumTypeDataSpecs' })
|
||||
defineOptions({ name: 'ThingModelEnumTypeDataSpecs' })
|
||||
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
@ -62,7 +62,7 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
|
||||
import { DataSpecsNumberDataVO } from '../config'
|
||||
|
||||
/** 数值型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'ThinkModelNumberTypeDataSpecs' })
|
||||
defineOptions({ name: 'ThingModelNumberTypeDataSpecs' })
|
||||
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
5
src/views/iot/thingmodel/dataSpecs/index.ts
Normal file
5
src/views/iot/thingmodel/dataSpecs/index.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import ThingModelEnumTypeDataSpecs from './ThingModelEnumTypeDataSpecs.vue'
|
||||
import ThingModelNumberTypeDataSpecs from './ThingModelNumberTypeDataSpecs.vue'
|
||||
import ThingModelArrayTypeDataSpecs from './ThingModelArrayTypeDataSpecs.vue'
|
||||
|
||||
export { ThingModelEnumTypeDataSpecs, ThingModelNumberTypeDataSpecs, ThingModelArrayTypeDataSpecs }
|
@ -17,7 +17,7 @@
|
||||
placeholder="请选择功能类型"
|
||||
>
|
||||
<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"
|
||||
: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_THINK_MODEL_TYPE" :value="scope.row.type" />
|
||||
<dict-tag :type="DICT_TYPE.IOT_PRODUCT_THING_MODEL_TYPE" :value="scope.row.type" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" label="功能名称" prop="name" />
|
||||
@ -97,23 +97,23 @@
|
||||
</el-tabs>
|
||||
</ContentWrap>
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<ThinkModelForm ref="formRef" @success="getList" />
|
||||
<ThingModelForm ref="formRef" @success="getList" />
|
||||
</template>
|
||||
<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 ThinkModelForm from './ThinkModelForm.vue'
|
||||
import ThingModelForm from './ThingModelForm.vue'
|
||||
import { ProductVO } from '@/api/iot/product/product'
|
||||
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 message = useMessage() // 消息弹窗
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const list = ref<ThinkModelData[]>([]) // 列表的数据
|
||||
const list = ref<ThingModelData[]>([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
@ -131,7 +131,7 @@ const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
queryParams.productId = product?.value?.id || -1
|
||||
const data = await ThinkModelApi.getThinkModelPage(queryParams)
|
||||
const data = await ThingModelApi.getThingModelPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
} finally {
|
||||
@ -163,7 +163,7 @@ const handleDelete = async (id: number) => {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
await ThinkModelApi.deleteThinkModel(id)
|
||||
await ThingModelApi.deleteThingModel(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
@ -1,5 +0,0 @@
|
||||
import ThinkModelEnumTypeDataSpecs from './ThinkModelEnumTypeDataSpecs.vue'
|
||||
import ThinkModelNumberTypeDataSpecs from './ThinkModelNumberTypeDataSpecs.vue'
|
||||
import ThinkModelArrayTypeDataSpecs from './ThinkModelArrayTypeDataSpecs.vue'
|
||||
|
||||
export { ThinkModelEnumTypeDataSpecs, ThinkModelNumberTypeDataSpecs, ThinkModelArrayTypeDataSpecs }
|
Loading…
x
Reference in New Issue
Block a user