diff --git a/src/api/iot/thinkmodelfunction/index.ts b/src/api/iot/thinkmodel/index.ts similarity index 50% rename from src/api/iot/thinkmodelfunction/index.ts rename to src/api/iot/thinkmodel/index.ts index 0117e7aac31f2f61dc4c7ddb18bdf6b279b9f996..f900ce6a8ca0a34651804d9526f66177c6732232 100644 --- a/src/api/iot/thinkmodelfunction/index.ts +++ b/src/api/iot/thinkmodel/index.ts @@ -3,7 +3,7 @@ import request from '@/config/axios' /** * IoT 产品物模型 */ -export interface ThingModelData { +export interface ThinkModelData { id?: number // 物模型功能编号 identifier?: string // 功能标识 name?: string // 功能名称 @@ -12,29 +12,29 @@ export interface ThingModelData { productKey?: string // 产品标识 dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致 type: ProductFunctionTypeEnum // 功能类型 - property: ThingModelProperty // 属性 - event?: ThingModelEvent // 事件 - service?: ThingModelService // 服务 + property: ThinkModelProperty // 属性 + event?: ThinkModelEvent // 事件 + service?: ThinkModelService // 服务 } /** - * ThingModelProperty 类型 + * ThinkModelProperty 类型 */ -export interface ThingModelProperty { +export interface ThinkModelProperty { [key: string]: any } /** - * ThingModelEvent 类型 + * ThinkModelEvent 类型 */ -export interface ThingModelEvent { +export interface ThinkModelEvent { [key: string]: any } /** - * ThingModelService 类型 + * ThinkModelService 类型 */ -export interface ThingModelService { +export interface ThinkModelService { [key: string]: any } @@ -51,39 +51,38 @@ export enum ProductFunctionAccessModeEnum { READ_ONLY = 'r' // 只读 } -// TODO @puhui999:getProductThingModelPage => getThingModelPage 哈,不用带 product 前缀 // IoT 产品物模型 API -export const ThinkModelFunctionApi = { +export const ThinkModelApi = { // 查询产品物模型分页 - getProductThingModelPage: async (params: any) => { - return await request.get({ url: `/iot/product-thing-model/page`, params }) + getThinkModelPage: async (params: any) => { + return await request.get({ url: `/iot/product-think-model/page`, params }) }, // 获得产品物模型 - getProductThingModelListByProductId: async (params: any) => { + getThinkModelListByProductId: async (params: any) => { return await request.get({ - url: `/iot/product-thing-model/list-by-product-id`, + url: `/iot/product-think-model/list-by-product-id`, params }) }, // 查询产品物模型详情 - getProductThingModel: async (id: number) => { - return await request.get({ url: `/iot/product-thing-model/get?id=` + id }) + getThinkModel: async (id: number) => { + return await request.get({ url: `/iot/product-think-model/get?id=` + id }) }, // 新增产品物模型 - createProductThingModel: async (data: ThingModelData) => { - return await request.post({ url: `/iot/product-thing-model/create`, data }) + createThinkModel: async (data: ThinkModelData) => { + return await request.post({ url: `/iot/product-think-model/create`, data }) }, // 修改产品物模型 - updateProductThingModel: async (data: ThingModelData) => { - return await request.put({ url: `/iot/product-thing-model/update`, data }) + updateThinkModel: async (data: ThinkModelData) => { + return await request.put({ url: `/iot/product-think-model/update`, data }) }, // 删除产品物模型 - deleteProductThingModel: async (id: number) => { - return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id }) + deleteThinkModel: async (id: number) => { + return await request.delete({ url: `/iot/product-think-model/delete?id=` + id }) } } diff --git a/src/utils/dict.ts b/src/utils/dict.ts index 5538ed607a142d95195ea0894e15c2b0b203ba0e..0f57ba4eafa5d0052ce17834fad85b1eaff705ef 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/product/product/detail/ThingModel/dataSpecs/ThingModelEnumTypeDataSpecs.vue b/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelEnumTypeDataSpecs.vue deleted file mode 100644 index af28e11edb9bfc3b34d3716403416adbef6f8333..0000000000000000000000000000000000000000 --- a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelEnumTypeDataSpecs.vue +++ /dev/null @@ -1,57 +0,0 @@ - - - - - 参数值 - 参数描述 - - - - ~ - - 删除 - - +添加枚举项 - - - - - - - diff --git a/src/views/iot/product/product/detail/ThingModel/dataSpecs/index.ts b/src/views/iot/product/product/detail/ThingModel/dataSpecs/index.ts deleted file mode 100644 index f2e1daafaa996ea49c71e6786360340fcfc22b0e..0000000000000000000000000000000000000000 --- a/src/views/iot/product/product/detail/ThingModel/dataSpecs/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import ThingModelEnumTypeDataSpecs from './ThingModelEnumTypeDataSpecs.vue' -import ThingModelNumberTypeDataSpecs from './ThingModelNumberTypeDataSpecs.vue' -import ThingModelArrayTypeDataSpecs from './ThingModelArrayTypeDataSpecs.vue' - -export { ThingModelEnumTypeDataSpecs, ThingModelNumberTypeDataSpecs, ThingModelArrayTypeDataSpecs } diff --git a/src/views/iot/product/product/detail/index.vue b/src/views/iot/product/product/detail/index.vue index e30b16365b0cbace4c54b48630a85181a2a9aaab..e35376420c612fe2510c9ffd5e931a756df1adbe 100644 --- a/src/views/iot/product/product/detail/index.vue +++ b/src/views/iot/product/product/detail/index.vue @@ -8,8 +8,8 @@ - - + + @@ -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 IoTProductThingModel from './ThingModel/index.vue' +import IoTProductThinkModel from '@/views/iot/thinkmodel/index.vue' import { useTagsViewStore } from '@/store/modules/tagsView' import { useRouter } from 'vue-router' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' diff --git a/src/views/iot/product/product/index.vue b/src/views/iot/product/product/index.vue index db61ccfe73ebe16a42d50e644ccb168b24443fb4..09fa02377b0e5af54781d45ed127e2f102677c18 100644 --- a/src/views/iot/product/product/index.vue +++ b/src/views/iot/product/product/index.vue @@ -309,7 +309,7 @@ const openObjectModel = (item: ProductVO) => { push({ name: 'IoTProductDetail', params: { id: item.id }, - query: { tab: 'thingModel' } + query: { tab: 'thinkModel' } }) } diff --git a/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue b/src/views/iot/thinkmodel/ThinkModelDataSpecs.vue similarity index 47% rename from src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue rename to src/views/iot/thinkmodel/ThinkModelDataSpecs.vue index ab7d91e8aecbfa0671757aa0b65e61b885d946f4..f38e965e595603ad11d05783847ff7c986e19ccf 100644 --- a/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue +++ b/src/views/iot/thinkmodel/ThinkModelDataSpecs.vue @@ -1,5 +1,9 @@ - + - - - - + + {{ item.value }} - - + + + - + 字节 @@ -48,19 +74,29 @@ - - + 读写 只读 - + @@ -68,18 +104,19 @@ import { useVModel } from '@vueuse/core' import { DataSpecsDataType, dataTypeOptions } from './config' import { - ThingModelArrayTypeDataSpecs, - ThingModelEnumTypeDataSpecs, - ThingModelNumberTypeDataSpecs + ThinkModelArrayTypeDataSpecs, + ThinkModelEnumTypeDataSpecs, + ThinkModelNumberTypeDataSpecs } from './dataSpecs' -import { ThingModelProperty } from '@/api/iot/thinkmodelfunction' +import { ThinkModelProperty } from '@/api/iot/thinkmodel' +import { isEmpty } from '@/utils/is' /** IoT 物模型数据 */ -defineOptions({ name: 'ThingModelDataSpecs' }) +defineOptions({ name: 'ThinkModelDataSpecs' }) const props = defineProps<{ modelValue: any }>() const emits = defineEmits(['update:modelValue']) -const property = useVModel(props, 'modelValue', emits) as Ref +const property = useVModel(props, 'modelValue', emits) as Ref /** 属性值的数据类型切换时初始化相关数据 */ const handleChange = (dataType: any) => { @@ -106,6 +143,53 @@ const handleChange = (dataType: any) => { break } } + +/** 校验布尔值名称 */ +const validateBoolName = (_: any, value: string, callback: any) => { + if (isEmpty(value)) { + callback(new Error('布尔值名称不能为空')) + return + } + + // 检查开头字符 + if (!/^[\u4e00-\u9fa5a-zA-Z0-9]/.test(value)) { + callback(new Error('布尔值名称必须以中文、英文字母或数字开头')) + return + } + + // 检查整体格式 + if (!/^[\u4e00-\u9fa5a-zA-Z0-9][a-zA-Z0-9\u4e00-\u9fa5_-]*$/.test(value)) { + callback(new Error('布尔值名称只能包含中文、英文字母、数字、下划线和短划线')) + return + } + + // 检查长度(一个中文算一个字符) + if (value.length > 20) { + callback(new Error('布尔值名称长度不能超过20个字符')) + return + } + + callback() +} + +/** 校验文本长度 */ +const validateTextLength = (_: any, value: any, callback: any) => { + if (isEmpty(value)) { + callback(new Error('文本长度不能为空')) + return + } + if (isNaN(Number(value))) { + callback(new Error('文本长度必须是数字')) + return + } + callback() +} - + diff --git a/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue b/src/views/iot/thinkmodel/ThinkModelForm.vue similarity index 74% rename from src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue rename to src/views/iot/thinkmodel/ThinkModelForm.vue index 5820007287ee770de0b898e09684cb04f2f97028..985f930f6b335daf6468b4474313b54818e2f3f9 100644 --- a/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue +++ b/src/views/iot/thinkmodel/ThinkModelForm.vue @@ -9,10 +9,13 @@ > - - 属性 - 服务 - 事件 + + {{ dict.label }} + @@ -22,7 +25,7 @@ - @@ -37,30 +40,26 @@ diff --git a/src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue b/src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue new file mode 100644 index 0000000000000000000000000000000000000000..b8411e552dd96140a292706d94c3e7907ad98fcc --- /dev/null +++ b/src/views/iot/thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue @@ -0,0 +1,164 @@ + + + + + 参数值 + 参数描述 + + + + + + ~ + + + + 删除 + + +添加枚举项 + + + + + + + diff --git a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelNumberTypeDataSpecs.vue b/src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue similarity index 33% rename from src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelNumberTypeDataSpecs.vue rename to src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue index 6dfff8ad7eafeedfe0c0b10ec70b7a2be010a981..d3fe26b4563d6cb5ef81082009d502e78746e5a7 100644 --- a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelNumberTypeDataSpecs.vue +++ b/src/views/iot/thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue @@ -1,15 +1,44 @@ - + - + + + ~ - + + + - + - + () const emits = defineEmits(['update:modelValue']) @@ -45,6 +74,72 @@ const unitChange = (UnitSpecs: string) => { dataSpecs.value.unitName = unitName dataSpecs.value.unit = unit } + +/** 校验最小值 */ +const validateMin = (_: any, __: any, callback: any) => { + const min = Number(dataSpecs.value.min) + const max = Number(dataSpecs.value.max) + + if (isNaN(min)) { + callback(new Error('请输入有效的数值')) + return + } + + if (max !== undefined && !isNaN(max) && min >= max) { + callback(new Error('最小值必须小于最大值')) + return + } + + callback() +} + +/** 校验最大值 */ +const validateMax = (_: any, __: any, callback: any) => { + const min = Number(dataSpecs.value.min) + const max = Number(dataSpecs.value.max) + + if (isNaN(max)) { + callback(new Error('请输入有效的数值')) + return + } + + if (min !== undefined && !isNaN(min) && max <= min) { + callback(new Error('最大值必须大于最小值')) + return + } + + callback() +} + +/** 校验步长 */ +const validateStep = (_: any, __: any, callback: any) => { + const step = Number(dataSpecs.value.step) + const min = Number(dataSpecs.value.min) + const max = Number(dataSpecs.value.max) + + if (isNaN(step)) { + callback(new Error('请输入有效的数值')) + return + } + + if (step <= 0) { + callback(new Error('步长必须大于0')) + return + } + + if (!isNaN(min) && !isNaN(max) && step > max - min) { + callback(new Error('步长不能大于最大值和最小值的差值')) + return + } + + callback() +} - + diff --git a/src/views/iot/thinkmodel/dataSpecs/index.ts b/src/views/iot/thinkmodel/dataSpecs/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..de919f48127f606814cfb65f0b8c93f5286b006a --- /dev/null +++ b/src/views/iot/thinkmodel/dataSpecs/index.ts @@ -0,0 +1,5 @@ +import ThinkModelEnumTypeDataSpecs from './ThinkModelEnumTypeDataSpecs.vue' +import ThinkModelNumberTypeDataSpecs from './ThinkModelNumberTypeDataSpecs.vue' +import ThinkModelArrayTypeDataSpecs from './ThinkModelArrayTypeDataSpecs.vue' + +export { ThinkModelEnumTypeDataSpecs, ThinkModelNumberTypeDataSpecs, ThinkModelArrayTypeDataSpecs } diff --git a/src/views/iot/product/product/detail/ThingModel/index.vue b/src/views/iot/thinkmodel/index.vue similarity index 88% rename from src/views/iot/product/product/detail/ThingModel/index.vue rename to src/views/iot/thinkmodel/index.vue index 38bcd8fda4ef28e0d4ec017ef4f08d1ea15c5ba6..71f0082a3599e5e3bf048a2ee8e0a3145addc99c 100644 --- a/src/views/iot/product/product/detail/ThingModel/index.vue +++ b/src/views/iot/thinkmodel/index.vue @@ -17,7 +17,7 @@ placeholder="请选择功能类型" > - + @@ -97,23 +97,23 @@ - +