-
+
+
@@ -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 @@
-
+
-
+
@@ -34,29 +23,13 @@
diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelEnumTypeDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelEnumDataSpecs.vue
similarity index 98%
rename from src/views/iot/thingmodel/dataSpecs/ThingModelEnumTypeDataSpecs.vue
rename to src/views/iot/thingmodel/dataSpecs/ThingModelEnumDataSpecs.vue
index 425a8020..88b24901 100644
--- a/src/views/iot/thingmodel/dataSpecs/ThingModelEnumTypeDataSpecs.vue
+++ b/src/views/iot/thingmodel/dataSpecs/ThingModelEnumDataSpecs.vue
@@ -48,7 +48,7 @@ import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
import { isEmpty } from '@/utils/is'
/** 枚举型的 dataSpecs 配置组件 */
-defineOptions({ name: 'ThingModelEnumTypeDataSpecs' })
+defineOptions({ name: 'ThingModelEnumDataSpecs' })
const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue'])
@@ -113,7 +113,6 @@ const validateEnumName = (_: any, value: string, callback: any) => {
callback(new Error('枚举描述长度不能超过20个字符'))
return
}
-
callback()
}
@@ -147,7 +146,6 @@ const validateEnumList = (_: any, __: any, callback: any) => {
callback(new Error('存在重复的枚举值'))
return
}
-
callback()
}
diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelNumberTypeDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelNumberDataSpecs.vue
similarity index 98%
rename from src/views/iot/thingmodel/dataSpecs/ThingModelNumberTypeDataSpecs.vue
rename to src/views/iot/thingmodel/dataSpecs/ThingModelNumberDataSpecs.vue
index 62f09cb0..bd60d6a4 100644
--- a/src/views/iot/thingmodel/dataSpecs/ThingModelNumberTypeDataSpecs.vue
+++ b/src/views/iot/thingmodel/dataSpecs/ThingModelNumberDataSpecs.vue
@@ -62,7 +62,7 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
import { DataSpecsNumberDataVO } from '../config'
/** 数值型的 dataSpecs 配置组件 */
-defineOptions({ name: 'ThingModelNumberTypeDataSpecs' })
+defineOptions({ name: 'ThingModelNumberDataSpecs' })
const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue'])
diff --git a/src/views/iot/thingmodel/dataSpecs/index.ts b/src/views/iot/thingmodel/dataSpecs/index.ts
index f2e1daaf..b9883dd2 100644
--- a/src/views/iot/thingmodel/dataSpecs/index.ts
+++ b/src/views/iot/thingmodel/dataSpecs/index.ts
@@ -1,5 +1,5 @@
-import ThingModelEnumTypeDataSpecs from './ThingModelEnumTypeDataSpecs.vue'
-import ThingModelNumberTypeDataSpecs from './ThingModelNumberTypeDataSpecs.vue'
-import ThingModelArrayTypeDataSpecs from './ThingModelArrayTypeDataSpecs.vue'
+import ThingModelEnumDataSpecs from './ThingModelEnumDataSpecs.vue'
+import ThingModelNumberDataSpecs from './ThingModelNumberDataSpecs.vue'
+import ThingModelArrayDataSpecs from './ThingModelArrayDataSpecs.vue'
-export { ThingModelEnumTypeDataSpecs, ThingModelNumberTypeDataSpecs, ThingModelArrayTypeDataSpecs }
+export { ThingModelEnumDataSpecs, ThingModelNumberDataSpecs, ThingModelArrayDataSpecs }
diff --git a/src/views/iot/thingmodel/index.vue b/src/views/iot/thingmodel/index.vue
index b1160958..ed2fd7f7 100644
--- a/src/views/iot/thingmodel/index.vue
+++ b/src/views/iot/thingmodel/index.vue
@@ -1,4 +1,3 @@
-
@@ -100,7 +99,7 @@