diff --git a/src/views/iot/product/product/detail/index.vue b/src/views/iot/product/product/detail/index.vue index d0c446e0..c9fa2f72 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 IoTProductThinkModel from '@/views/iot/thingmodel/index.vue' +import IoTProductThingModel 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/product/product/index.vue b/src/views/iot/product/product/index.vue index e2b6447a..1518c161 100644 --- a/src/views/iot/product/product/index.vue +++ b/src/views/iot/product/product/index.vue @@ -97,7 +97,9 @@
产品标识 - {{ item.productKey }} + + {{ item.productKey }} +
@@ -309,7 +311,7 @@ const openObjectModel = (item: ProductVO) => { push({ name: 'IoTProductDetail', params: { id: item.id }, - query: { tab: 'thinkModel' } + query: { tab: 'thingModel' } }) } diff --git a/src/views/iot/thingmodel/ThingModelDataSpecs.vue b/src/views/iot/thingmodel/ThingModelDataSpecs.vue index 45eeb3e9..6f0a00f9 100644 --- a/src/views/iot/thingmodel/ThingModelDataSpecs.vue +++ b/src/views/iot/thingmodel/ThingModelDataSpecs.vue @@ -5,8 +5,9 @@ prop="property.dataType" > + - - @@ -74,12 +75,17 @@ - - + + () +const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean }>() const emits = defineEmits(['update:modelValue']) const property = useVModel(props, 'modelValue', emits) as Ref - +const getDataTypeOptions = computed(() => { + return !props.isStructDataSpecs + ? dataTypeOptions + : dataTypeOptions.filter( + (item) => + !([DataSpecsDataType.STRUCT, DataSpecsDataType.ARRAY] as any[]).includes(item.value) + ) +}) // 获得数据类型列表 /** 属性值的数据类型切换时初始化相关数据 */ const handleChange = (dataType: any) => { property.value.dataSpecsList = [] diff --git a/src/views/iot/thingmodel/ThingModelForm.vue b/src/views/iot/thingmodel/ThingModelForm.vue index a92495e4..173dab34 100644 --- a/src/views/iot/thingmodel/ThingModelForm.vue +++ b/src/views/iot/thingmodel/ThingModelForm.vue @@ -4,7 +4,7 @@ ref="formRef" v-loading="formLoading" :model="formData" - :rules="formRules" + :rules="ThingModelFormRules" label-width="100px" > @@ -41,9 +41,9 @@ + + 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 @@