From 1111b6b494a94872a0bc00637eb97a6d2acdbc60 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Fri, 17 Mar 2023 10:54:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=20ip=20=E6=88=96=20?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E6=AD=A3=E5=88=99=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/global/form-rules.ts | 21 +++++++++++++++++++ frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../host/terminal/host/operate/index.vue | 2 +- .../host/terminal/terminal/host-create.vue | 2 +- .../setting/backup-account/operate/index.vue | 2 +- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/frontend/src/global/form-rules.ts b/frontend/src/global/form-rules.ts index 1544e7d31..9f7eead18 100644 --- a/frontend/src/global/form-rules.ts +++ b/frontend/src/global/form-rules.ts @@ -15,6 +15,21 @@ const checkIp = (rule: any, value: any, callback: any) => { } }; +const checkHost = (rule: any, value: any, callback: any) => { + if (value === '' || typeof value === 'undefined' || value == null) { + callback(new Error(i18n.global.t('commons.rule.requiredInput'))); + } else { + const regIP = + /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/; + const regHost = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/; + if (!regIP.test(value) && !regHost.test(value)) { + callback(new Error(i18n.global.t('commons.rule.host'))); + } else { + callback(); + } + } +}; + const complexityPassword = (rule: any, value: any, callback: any) => { if (value === '' || typeof value === 'undefined' || value == null) { callback(new Error(i18n.global.t('commons.rule.complexityPassword'))); @@ -265,6 +280,7 @@ interface CommonRule { number: FormItemRule; integerNumber: FormItemRule; ip: FormItemRule; + host: FormItemRule; port: FormItemRule; domain: FormItemRule; databaseName: FormItemRule; @@ -363,6 +379,11 @@ export const Rules: CommonRule = { required: true, trigger: 'blur', }, + host: { + validator: checkHost, + required: true, + trigger: 'blur', + }, port: { required: true, trigger: 'blur', diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 2641238ab..853901f29 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -140,6 +140,7 @@ export default { number: 'Please enter the correct number', integer: 'Please enter the correct positive integer', ip: 'Please enter the correct IP address', + host: 'Enter the correct IP address or domain name', port: 'Please enter the correct port', selectHelper: 'Please select the correct {0} file', domain: 'domain name format error', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index c18813d8e..cad311ca2 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -144,6 +144,7 @@ export default { number: '请输入正确的数字', integer: '请输入正确的正整数', ip: '请输入正确的 IP 地址', + host: '请输入正确的 IP 或者域名', port: '请输入正确的端口,1-65535', selectHelper: '请选择正确的 {0} 文件', domain: '域名格式错误', diff --git a/frontend/src/views/host/terminal/host/operate/index.vue b/frontend/src/views/host/terminal/host/operate/index.vue index a010cc8d7..db8a095cd 100644 --- a/frontend/src/views/host/terminal/host/operate/index.vue +++ b/frontend/src/views/host/terminal/host/operate/index.vue @@ -109,7 +109,7 @@ type FormInstance = InstanceType; const hostInfoRef = ref(); const rules = reactive({ groupID: [Rules.requiredSelect], - addr: [Rules.requiredInput], + addr: [Rules.host], port: [Rules.requiredInput, Rules.port], user: [Rules.requiredInput], authMode: [Rules.requiredSelect], diff --git a/frontend/src/views/host/terminal/terminal/host-create.vue b/frontend/src/views/host/terminal/terminal/host-create.vue index 6fbed605e..3f4662120 100644 --- a/frontend/src/views/host/terminal/terminal/host-create.vue +++ b/frontend/src/views/host/terminal/terminal/host-create.vue @@ -95,7 +95,7 @@ let hostInfo = reactive({ }); const rules = reactive({ - addr: [Rules.ip], + addr: [Rules.host], port: [Rules.requiredInput, Rules.port], user: [Rules.requiredInput], authMode: [Rules.requiredSelect], diff --git a/frontend/src/views/setting/backup-account/operate/index.vue b/frontend/src/views/setting/backup-account/operate/index.vue index ceda34dfc..32ce9075e 100644 --- a/frontend/src/views/setting/backup-account/operate/index.vue +++ b/frontend/src/views/setting/backup-account/operate/index.vue @@ -93,7 +93,7 @@ {{ $t('commons.rule.requiredSelect') }}
- +