From 977625395b223f671a3165133fe7ee099fb2bfce Mon Sep 17 00:00:00 2001 From: ssongliu Date: Thu, 18 Aug 2022 18:51:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0ip=E3=80=81=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E7=AD=89=E6=A0=A1=E9=AA=8C=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/global/form-rues.ts | 41 +++++++++++++++++++++++++++++--- frontend/src/lang/modules/en.ts | 6 ++++- frontend/src/lang/modules/zh.ts | 6 ++++- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/frontend/src/global/form-rues.ts b/frontend/src/global/form-rues.ts index 78298ab1b..8704486a6 100644 --- a/frontend/src/global/form-rues.ts +++ b/frontend/src/global/form-rues.ts @@ -1,18 +1,40 @@ import i18n from '@/lang'; import { FormItemRule } from 'element-plus'; +const checkIp = (rule: any, value: any, callback: any) => { + if (value === '' || typeof value === 'undefined' || value == null) { + callback(new Error(i18n.global.t('commons.rule.requiredInput'))); + } else { + const reg = + /^(\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])$/; + if (!reg.test(value) && value !== '') { + callback(new Error(i18n.global.t('commons.rule.ip'))); + } else { + callback(); + } + } +}; + interface CommonRule { - required: FormItemRule; + requiredInput: FormItemRule; + requiredSelect: FormItemRule; name: FormItemRule; email: FormItemRule; + ip: FormItemRule; + port: FormItemRule; } export const Rules: CommonRule = { - required: { + requiredInput: { required: true, - message: i18n.global.t('commons.rule.required'), + message: i18n.global.t('commons.rule.requiredInput'), trigger: 'blur', }, + requiredSelect: { + required: true, + message: i18n.global.t('commons.rule.requiredSelect'), + trigger: 'change', + }, name: { type: 'regexp', min: 1, @@ -26,4 +48,17 @@ export const Rules: CommonRule = { message: i18n.global.t('commons.rule.email'), trigger: 'blur', }, + ip: { + validator: checkIp, + required: true, + trigger: 'blur', + }, + port: { + required: true, + trigger: 'blur', + min: 1, + max: 65535, + type: 'number', + message: i18n.global.t('commons.rule.port'), + }, }; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 2d9dafeac..9930b4f56 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -35,9 +35,12 @@ export default { rule: { username: 'Please enter a username', password: 'Please enter a password', - required: 'Please enter the required fields', + requiredInput: 'Please enter the required fields', + requiredSelect: 'Please select the required fields', commonName: 'Support English, Chinese, numbers, .-_, length 1-30', email: 'Email format error', + ip: 'Please enter the correct IP address', + port: 'Please enter the correct port', }, res: { paramError: 'The request failed, please try again later!', @@ -87,6 +90,7 @@ export default { operations: { detail: { users: 'User', + hosts: 'Host', auth: 'User', login: ' login', logout: ' logout', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 9899274c1..262fcbf39 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -35,9 +35,12 @@ export default { rule: { username: '请输入用户名', password: '请输入密码', - required: '请填写必填项', + requiredInput: '请填写必填项', + requiredSelect: '请选择必选项', commonName: '支持英文、中文、数字、.-_,长度1-30', email: '邮箱格式错误', + ip: '请输入正确的 IP 地址', + port: '请输入正确的端口', }, res: { paramError: '请求失败,请稍后重试!', @@ -88,6 +91,7 @@ export default { operations: { detail: { users: '用户', + hosts: '主机', auth: '用户', post: '创建', put: '更新',