From 77a1bc3faa05f064ef67dcc3a894fc266225e099 Mon Sep 17 00:00:00 2001 From: hwj Date: Fri, 27 Mar 2026 17:39:38 +0800 Subject: [PATCH] =?UTF-8?q?style=EF=BC=9A=E9=87=87=E9=9B=86=E8=AE=BE?= =?UTF-8?q?=E5=A4=87-=E8=AE=BE=E5=A4=87=E5=B1=9E=E6=80=A7-=E6=96=B0?= =?UTF-8?q?=E5=A2=9E-=E7=82=B9=E4=BD=8D=E7=BC=96=E7=A0=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A0=BC=E5=BC=8F=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/iot/device/components/DeviceAttributeForm.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/views/iot/device/components/DeviceAttributeForm.vue b/src/views/iot/device/components/DeviceAttributeForm.vue index f01bd941..31b3a270 100644 --- a/src/views/iot/device/components/DeviceAttributeForm.vue +++ b/src/views/iot/device/components/DeviceAttributeForm.vue @@ -123,7 +123,8 @@ watch( ) const handleAttributeCodeInput = (val: string) => { - formData.value.attributeCode = val?.replace(/[\u4e00-\u9fa5]/g, '') + const sanitized = (val || '').replace(/[^A-Za-z0-9_]/g, '') + formData.value.attributeCode = sanitized.replace(/^[0-9]+/, '') } @@ -147,6 +148,10 @@ const formRules = reactive({ callback(new Error(t('DataCollection.Device.attributeValidatorCodeNoChinese'))) return } + if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(value)) { + callback(new Error('仅支持英文字母、数字和下划线,且必须以字母或下划线开头')) + return + } callback() }, trigger: ['blur', 'change']