diff --git a/src/api/iot/thinkmodelfunction/index.ts b/src/api/iot/thinkmodelfunction/index.ts index 012ba190..9c01cfa9 100644 --- a/src/api/iot/thinkmodelfunction/index.ts +++ b/src/api/iot/thinkmodelfunction/index.ts @@ -10,6 +10,7 @@ export interface ThingModelData { description?: string // 功能描述 productId?: number // 产品编号 productKey?: string // 产品标识 + dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致 type: ProductFunctionTypeEnum // 功能类型 property: ThingModelProperty // 属性 event?: ThingModelEvent // 事件 @@ -53,34 +54,35 @@ export enum ProductFunctionAccessModeEnum { // IoT 产品物模型 API export const ThinkModelFunctionApi = { // 查询产品物模型分页 - getThinkModelFunctionPage: async (params: any) => { - return await request.get({ url: `/iot/think-model-function/page`, params }) + getProductThingModelPage: async (params: any) => { + return await request.get({ url: `/iot/product-thing-model/page`, params }) }, + // 获得产品物模型 - getThinkModelFunctionListByProductId: async (params: any) => { + getProductThingModelListByProductId: async (params: any) => { return await request.get({ - url: `/iot/think-model-function/list-by-product-id`, + url: `/iot/product-thing-model/list-by-product-id`, params }) }, // 查询产品物模型详情 - getThinkModelFunction: async (id: number) => { - return await request.get({ url: `/iot/think-model-function/get?id=` + id }) + getProductThingModel: async (id: number) => { + return await request.get({ url: `/iot/product-thing-model/get?id=` + id }) }, // 新增产品物模型 - createThinkModelFunction: async (data: ThingModelData) => { - return await request.post({ url: `/iot/think-model-function/create`, data }) + createProductThingModel: async (data: ThingModelData) => { + return await request.post({ url: `/iot/product-thing-model/create`, data }) }, // 修改产品物模型 - updateThinkModelFunction: async (data: ThingModelData) => { - return await request.put({ url: `/iot/think-model-function/update`, data }) + updateProductThingModel: async (data: ThingModelData) => { + return await request.put({ url: `/iot/product-thing-model/update`, data }) }, // 删除产品物模型 - deleteThinkModelFunction: async (id: number) => { - return await request.delete({ url: `/iot/think-model-function/delete?id=` + id }) + deleteProductThingModel: async (id: number) => { + return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id }) } } diff --git a/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue b/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue index a672baab..38819105 100644 --- a/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue +++ b/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue @@ -24,34 +24,35 @@ v-model="property.dataSpecsList" /> - + - - + + - - + + + 读写 @@ -84,16 +85,8 @@ const handleChange = (dataType: any) => { property.value.dataSpecsList = [] property.value.dataSpecs = {} + property.value.dataSpecs.dataType = dataType switch (dataType) { - case DataSpecsDataType.INT: - property.value.dataSpecs.dataType = DataSpecsDataType.INT - break - case DataSpecsDataType.DOUBLE: - property.value.dataSpecs.dataType = DataSpecsDataType.DOUBLE - break - case DataSpecsDataType.FLOAT: - property.value.dataSpecs.dataType = DataSpecsDataType.FLOAT - break case DataSpecsDataType.ENUM: property.value.dataSpecsList.push({ dataType: DataSpecsDataType.ENUM, @@ -110,9 +103,6 @@ const handleChange = (dataType: any) => { }) } break - case DataSpecsDataType.ARRAY: - property.value.dataSpecs.dataType = DataSpecsDataType.ARRAY - break } } diff --git a/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue b/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue index 78a39695..f3d55d49 100644 --- a/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue +++ b/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue @@ -22,8 +22,8 @@ @@ -39,11 +39,12 @@ import { ProductVO } from '@/api/iot/product/product' import ThingModelDataSpecs from './ThingModelDataSpecs.vue' import { ProductFunctionTypeEnum, - ThinkModelFunctionApi, - ThingModelData + ThingModelData, + ThinkModelFunctionApi } from '@/api/iot/thinkmodelfunction' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' import { DataSpecsDataType } from './config' +import { cloneDeep } from 'lodash-es' defineOptions({ name: 'IoTProductThingModelForm' }) @@ -58,12 +59,15 @@ const formLoading = ref(false) const formType = ref('') const formData = ref({ type: ProductFunctionTypeEnum.PROPERTY, + dataType: DataSpecsDataType.INT, property: { dataType: DataSpecsDataType.INT, - dataSpecsList: [], - dataSpecs: {} + dataSpecs: { + dataType: DataSpecsDataType.INT + } } }) +// TODO puhui999: 表单校验待完善 const formRules = reactive({ name: [ { required: true, message: '功能名称不能为空', trigger: 'blur' }, @@ -114,7 +118,7 @@ const open = async (type: string, id?: number) => { if (id) { formLoading.value = true try { - formData.value = await ThinkModelFunctionApi.getThinkModelFunction(id) + formData.value = await ThinkModelFunctionApi.getProductThingModel(id) } finally { formLoading.value = false } @@ -128,14 +132,19 @@ const submitForm = async () => { await formRef.value.validate() formLoading.value = true try { - const data = formData.value as unknown as ThingModelData + const data = cloneDeep(formData.value) as ThingModelData + // 信息补全 data.productId = product!.value.id data.productKey = product!.value.productKey + data.description = data.property.description + data.dataType = data.property.dataType + data.property.identifier = data.identifier + data.property.name = data.name if (formType.value === 'create') { - await ThinkModelFunctionApi.createThinkModelFunction(data) + await ThinkModelFunctionApi.createProductThingModel(data) message.success(t('common.createSuccess')) } else { - await ThinkModelFunctionApi.updateThinkModelFunction(data) + await ThinkModelFunctionApi.updateProductThingModel(data) message.success(t('common.updateSuccess')) } } finally { @@ -149,10 +158,12 @@ const submitForm = async () => { const resetForm = () => { formData.value = { type: ProductFunctionTypeEnum.PROPERTY, + dataType: DataSpecsDataType.INT, property: { dataType: DataSpecsDataType.INT, - dataSpecsList: [], - dataSpecs: {} + dataSpecs: { + dataType: DataSpecsDataType.INT + } } } formRef.value?.resetFields() diff --git a/src/views/iot/product/product/detail/ThingModel/config.ts b/src/views/iot/product/product/detail/ThingModel/config.ts index cd9d059d..eb651960 100644 --- a/src/views/iot/product/product/detail/ThingModel/config.ts +++ b/src/views/iot/product/product/detail/ThingModel/config.ts @@ -43,3 +43,8 @@ export const dataTypeOptions = [ { value: DataSpecsDataType.STRUCT, label: 'struct (结构体)' }, { value: DataSpecsDataType.ARRAY, label: 'array (数组)' } ] + +/** 获得物体模型数据类型配置项名称 */ +export const getDataTypeOptionsLabel = (value: string) => { + return dataTypeOptions.find((option) => option.value === value)?.label +} diff --git a/src/views/iot/product/product/detail/ThingModel/index.vue b/src/views/iot/product/product/detail/ThingModel/index.vue index 286fe12d..41cbb39d 100644 --- a/src/views/iot/product/product/detail/ThingModel/index.vue +++ b/src/views/iot/product/product/detail/ThingModel/index.vue @@ -32,7 +32,12 @@ 重置 - + 添加功能 @@ -49,12 +54,21 @@ - - + + + + + +