From 9f819db14dc4c89719ab37d82ae9b0c207378f5d Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 17 Dec 2024 16:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91IOT:=20=E4=BA=A7=E5=93=81=E7=89=A9=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1=E9=97=AE=E9=A2=98=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/thinkmodel/index.ts | 13 ++++---- src/utils/dict.ts | 6 ++-- .../iot/thinkmodel/ThinkModelDataSpecs.vue | 5 +-- src/views/iot/thinkmodel/ThinkModelForm.vue | 32 +++++++++++-------- .../ThinkModelArrayTypeDataSpecs.vue | 3 +- .../dataSpecs/ThinkModelEnumTypeDataSpecs.vue | 3 +- .../ThinkModelNumberTypeDataSpecs.vue | 9 +++--- src/views/iot/thinkmodel/index.vue | 8 ++--- 8 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/api/iot/thinkmodel/index.ts b/src/api/iot/thinkmodel/index.ts index 8817f755..e5eac028 100644 --- a/src/api/iot/thinkmodel/index.ts +++ b/src/api/iot/thinkmodel/index.ts @@ -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 }) } } diff --git a/src/utils/dict.ts b/src/utils/dict.ts index 5538ed60..0f57ba4e 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -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 读写类型 diff --git a/src/views/iot/thinkmodel/ThinkModelDataSpecs.vue b/src/views/iot/thinkmodel/ThinkModelDataSpecs.vue index d352695c..f38e965e 100644 --- a/src/views/iot/thinkmodel/ThinkModelDataSpecs.vue +++ b/src/views/iot/thinkmodel/ThinkModelDataSpecs.vue @@ -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 diff --git a/src/views/iot/thinkmodel/ThinkModelForm.vue b/src/views/iot/thinkmodel/ThinkModelForm.vue index 0674cebd..985f930f 100644 --- a/src/views/iot/thinkmodel/ThinkModelForm.vue +++ b/src/views/iot/thinkmodel/ThinkModelForm.vue @@ -9,9 +9,13 @@ > - 属性 - 服务 - 事件 + + {{ dict.label }} + @@ -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>(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({ 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 { diff --git a/src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue b/src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue index 70339ce0..fa2581ba 100644 --- a/src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue +++ b/src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue @@ -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 diff --git a/src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue b/src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue index 49bdcc09..b8411e55 100644 --- a/src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue +++ b/src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue @@ -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 diff --git a/src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue b/src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue index f1065219..d3fe26b4 100644 --- a/src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue +++ b/src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue @@ -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 @@ -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) diff --git a/src/views/iot/thinkmodel/index.vue b/src/views/iot/thinkmodel/index.vue index 5bfabde6..71f0082a 100644 --- a/src/views/iot/thinkmodel/index.vue +++ b/src/views/iot/thinkmodel/index.vue @@ -17,7 +17,7 @@ placeholder="请选择功能类型" > @@ -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()