From 4b2800f723a3c39dbc8efe496ab78920120d5a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=B5=A9=E6=B5=A9?= <1036606149@qq.com> Date: Mon, 30 Sep 2024 12:19:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=91=20IOT=20=E7=89=A9=E6=A8=A1=E5=9E=8B=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/product/detail/ThinkModelFunction.vue | 6 +- .../product/detail/ThinkModelFunctionForm.vue | 106 ++++++++++++------ 2 files changed, 75 insertions(+), 37 deletions(-) diff --git a/src/views/iot/product/detail/ThinkModelFunction.vue b/src/views/iot/product/detail/ThinkModelFunction.vue index 95089c62..cc2119c5 100644 --- a/src/views/iot/product/detail/ThinkModelFunction.vue +++ b/src/views/iot/product/detail/ThinkModelFunction.vue @@ -40,7 +40,11 @@ - + + + diff --git a/src/views/iot/product/detail/ThinkModelFunctionForm.vue b/src/views/iot/product/detail/ThinkModelFunctionForm.vue index 976ca717..0ea2a756 100644 --- a/src/views/iot/product/detail/ThinkModelFunctionForm.vue +++ b/src/views/iot/product/detail/ThinkModelFunctionForm.vue @@ -8,35 +8,40 @@ v-loading="formLoading" > - - - + + 属性 + 服务 + 事件 + - + - - + + - - - - - - + + + + + + - + ~ @@ -46,14 +51,7 @@ - - - + @@ -61,8 +59,12 @@ 只读 - - + + @@ -96,11 +98,11 @@ const formData = ref({ identifier: undefined, name: undefined, description: undefined, - type: undefined, + type: '1', property: { identifier: undefined, name: undefined, - accessMode: undefined, + accessMode: 'rw', required: true, dataType: { type: undefined, @@ -110,13 +112,44 @@ const formData = ref({ step: undefined, unit: undefined } - } + }, + description: undefined // 添加这一行 } }) const formRules = reactive({ - name: [{ required: true, message: '功能名称不能为空', trigger: 'blur' }], + 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' }], + identifier: [ + { required: true, message: '标识符不能为空', trigger: 'blur' }, + { + pattern: /^[a-zA-Z0-9_]{1,50}$/, + message: '支持大小写字母、数字和下划线,不超过 50 个字符', + trigger: 'blur' + }, + { + validator: (rule, value, callback) => { + const reservedKeywords = ['set', 'get', 'post', 'property', 'event', 'time', 'value'] + if (reservedKeywords.includes(value)) { + callback( + new Error( + 'set, get, post, property, event, time, value 是系统保留字段,不能用于标识符定义' + ) + ) + } else { + callback() + } + }, + trigger: 'blur' + } + ], property: { dataType: { type: [{ required: true, message: '数据类型不能为空', trigger: 'blur' }] @@ -172,11 +205,11 @@ const resetForm = () => { identifier: undefined, name: undefined, description: undefined, - type: undefined, + type: '1', property: { identifier: undefined, name: undefined, - accessMode: undefined, + accessMode: 'rw', required: true, dataType: { type: undefined, @@ -186,7 +219,8 @@ const resetForm = () => { step: undefined, unit: undefined } - } + }, + description: undefined // 确保重置 description 字段 } } formRef.value?.resetFields()