From d5f3d4006a94ca8128bcf67667e236e842cde031 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 23 Dec 2024 10:13:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=91IOT:=20ThingModel=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/{thinkmodel => thingmodel}/index.ts | 47 +++++++++---------- src/utils/dict.ts | 2 +- .../iot/product/product/detail/index.vue | 2 +- .../ThingModelDataSpecs.vue} | 18 +++---- .../ThingModelForm.vue} | 20 ++++---- .../iot/{thinkmodel => thingmodel}/config.ts | 0 .../ThingModelArrayTypeDataSpecs.vue} | 2 +- .../ThingModelEnumTypeDataSpecs.vue} | 2 +- .../ThingModelNumberTypeDataSpecs.vue} | 2 +- src/views/iot/thingmodel/dataSpecs/index.ts | 5 ++ .../iot/{thinkmodel => thingmodel}/index.vue | 20 ++++---- src/views/iot/thinkmodel/dataSpecs/index.ts | 5 -- 12 files changed, 62 insertions(+), 63 deletions(-) rename src/api/iot/{thinkmodel => thingmodel}/index.ts (52%) rename src/views/iot/{thinkmodel/ThinkModelDataSpecs.vue => thingmodel/ThingModelDataSpecs.vue} (94%) rename src/views/iot/{thinkmodel/ThinkModelForm.vue => thingmodel/ThingModelForm.vue} (90%) rename src/views/iot/{thinkmodel => thingmodel}/config.ts (100%) rename src/views/iot/{thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue => thingmodel/dataSpecs/ThingModelArrayTypeDataSpecs.vue} (96%) rename src/views/iot/{thinkmodel/dataSpecs/ThinkModelEnumTypeDataSpecs.vue => thingmodel/dataSpecs/ThingModelEnumTypeDataSpecs.vue} (98%) rename src/views/iot/{thinkmodel/dataSpecs/ThinkModelNumberTypeDataSpecs.vue => thingmodel/dataSpecs/ThingModelNumberTypeDataSpecs.vue} (98%) create mode 100644 src/views/iot/thingmodel/dataSpecs/index.ts rename src/views/iot/{thinkmodel => thingmodel}/index.vue (90%) delete mode 100644 src/views/iot/thinkmodel/dataSpecs/index.ts diff --git a/src/api/iot/thinkmodel/index.ts b/src/api/iot/thingmodel/index.ts similarity index 52% rename from src/api/iot/thinkmodel/index.ts rename to src/api/iot/thingmodel/index.ts index e1887048..8e2b69ad 100644 --- a/src/api/iot/thinkmodel/index.ts +++ b/src/api/iot/thingmodel/index.ts @@ -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 }) } } diff --git a/src/utils/dict.ts b/src/utils/dict.ts index 0f57ba4e..eae50a27 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -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 读写类型 diff --git a/src/views/iot/product/product/detail/index.vue b/src/views/iot/product/product/detail/index.vue index e3537642..d0c446e0 100644 --- a/src/views/iot/product/product/detail/index.vue +++ b/src/views/iot/product/product/detail/index.vue @@ -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' diff --git a/src/views/iot/thinkmodel/ThinkModelDataSpecs.vue b/src/views/iot/thingmodel/ThingModelDataSpecs.vue similarity index 94% rename from src/views/iot/thinkmodel/ThinkModelDataSpecs.vue rename to src/views/iot/thingmodel/ThingModelDataSpecs.vue index 2683242f..45eeb3e9 100644 --- a/src/views/iot/thinkmodel/ThinkModelDataSpecs.vue +++ b/src/views/iot/thingmodel/ThingModelDataSpecs.vue @@ -14,7 +14,7 @@ - - @@ -74,7 +74,7 @@ - @@ -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 +const property = useVModel(props, 'modelValue', emits) as Ref /** 属性值的数据类型切换时初始化相关数据 */ const handleChange = (dataType: any) => { diff --git a/src/views/iot/thinkmodel/ThinkModelForm.vue b/src/views/iot/thingmodel/ThingModelForm.vue similarity index 90% rename from src/views/iot/thinkmodel/ThinkModelForm.vue rename to src/views/iot/thingmodel/ThingModelForm.vue index 985f930f..a92495e4 100644 --- a/src/views/iot/thinkmodel/ThinkModelForm.vue +++ b/src/views/iot/thingmodel/ThingModelForm.vue @@ -10,7 +10,7 @@ @@ -25,7 +25,7 @@ - @@ -40,15 +40,15 @@ + + diff --git a/src/views/iot/thingmodel/config.ts b/src/views/iot/thingmodel/config.ts index eb651960..f37d7b7a 100644 --- a/src/views/iot/thingmodel/config.ts +++ b/src/views/iot/thingmodel/config.ts @@ -1,3 +1,5 @@ +import {isEmpty} from '@/utils/is' + /** dataSpecs 数值型数据结构 */ export interface DataSpecsNumberDataVO { dataType: 'int' | 'float' | 'double' // 数据类型,取值为 INT、FLOAT 或 DOUBLE @@ -48,3 +50,60 @@ export const dataTypeOptions = [ export const getDataTypeOptionsLabel = (value: string) => { return dataTypeOptions.find((option) => option.value === value)?.label } + +/** 公共校验规则 */ +export const ThingModelFormRules = { + name: [ + { required: true, message: '功能名称不能为空', trigger: 'blur' }, + { + pattern: /^[\u4e00-\u9fa5a-zA-Z0-9][\u4e00-\u9fa5a-zA-Z0-9\-_/\.]{0,29}$/, + message: + '支持中文、大小写字母、日文、数字、短划线、下划线、斜杠和小数点,必须以中文、英文或数字开头,不超过 30 个字符', + trigger: 'blur' + } + ], + type: [{ required: true, message: '功能类型不能为空', trigger: 'blur' }], + identifier: [ + { required: true, message: '标识符不能为空', trigger: 'blur' }, + { + pattern: /^[a-zA-Z0-9_]{1,50}$/, + message: '支持大小写字母、数字和下划线,不超过 50 个字符', + trigger: 'blur' + }, + { + validator: (_: any, value: string, callback: any) => { + const reservedKeywords = ['set', 'get', 'post', 'property', 'event', 'time', 'value'] + if (reservedKeywords.includes(value)) { + callback( + new Error( + 'set, get, post, property, event, time, value 是系统保留字段,不能用于标识符定义' + ) + ) + } else if (/^\d+$/.test(value)) { + callback(new Error('标识符不能是纯数字')) + } else { + callback() + } + }, + trigger: 'blur' + } + ], + 'property.dataSpecs.childDataType': [{ required: true, message: '元素类型不能为空' }], + 'property.dataSpecs.size': [ + { required: true, message: '元素个数不能为空' }, + { + validator: (_: any, value: any, callback: any) => { + if (isEmpty(value)) { + callback(new Error('元素个数不能为空')) + return + } + if (isNaN(Number(value))) { + callback(new Error('元素个数必须是数字')) + return + } + callback() + }, + trigger: 'blur' + } + ] +} diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelArrayTypeDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelArrayDataSpecs.vue similarity index 53% rename from src/views/iot/thingmodel/dataSpecs/ThingModelArrayTypeDataSpecs.vue rename to src/views/iot/thingmodel/dataSpecs/ThingModelArrayDataSpecs.vue index 1ccc9750..f0a10b50 100644 --- a/src/views/iot/thingmodel/dataSpecs/ThingModelArrayTypeDataSpecs.vue +++ b/src/views/iot/thingmodel/dataSpecs/ThingModelArrayDataSpecs.vue @@ -1,9 +1,5 @@