mirror of https://github.com/1Panel-dev/1Panel
feat: 增加ip、端口等校验规则
parent
e68a62c925
commit
977625395b
|
@ -1,18 +1,40 @@
|
||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { FormItemRule } from 'element-plus';
|
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 {
|
interface CommonRule {
|
||||||
required: FormItemRule;
|
requiredInput: FormItemRule;
|
||||||
|
requiredSelect: FormItemRule;
|
||||||
name: FormItemRule;
|
name: FormItemRule;
|
||||||
email: FormItemRule;
|
email: FormItemRule;
|
||||||
|
ip: FormItemRule;
|
||||||
|
port: FormItemRule;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Rules: CommonRule = {
|
export const Rules: CommonRule = {
|
||||||
required: {
|
requiredInput: {
|
||||||
required: true,
|
required: true,
|
||||||
message: i18n.global.t('commons.rule.required'),
|
message: i18n.global.t('commons.rule.requiredInput'),
|
||||||
trigger: 'blur',
|
trigger: 'blur',
|
||||||
},
|
},
|
||||||
|
requiredSelect: {
|
||||||
|
required: true,
|
||||||
|
message: i18n.global.t('commons.rule.requiredSelect'),
|
||||||
|
trigger: 'change',
|
||||||
|
},
|
||||||
name: {
|
name: {
|
||||||
type: 'regexp',
|
type: 'regexp',
|
||||||
min: 1,
|
min: 1,
|
||||||
|
@ -26,4 +48,17 @@ export const Rules: CommonRule = {
|
||||||
message: i18n.global.t('commons.rule.email'),
|
message: i18n.global.t('commons.rule.email'),
|
||||||
trigger: 'blur',
|
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'),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,9 +35,12 @@ export default {
|
||||||
rule: {
|
rule: {
|
||||||
username: 'Please enter a username',
|
username: 'Please enter a username',
|
||||||
password: 'Please enter a password',
|
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',
|
commonName: 'Support English, Chinese, numbers, .-_, length 1-30',
|
||||||
email: 'Email format error',
|
email: 'Email format error',
|
||||||
|
ip: 'Please enter the correct IP address',
|
||||||
|
port: 'Please enter the correct port',
|
||||||
},
|
},
|
||||||
res: {
|
res: {
|
||||||
paramError: 'The request failed, please try again later!',
|
paramError: 'The request failed, please try again later!',
|
||||||
|
@ -87,6 +90,7 @@ export default {
|
||||||
operations: {
|
operations: {
|
||||||
detail: {
|
detail: {
|
||||||
users: 'User',
|
users: 'User',
|
||||||
|
hosts: 'Host',
|
||||||
auth: 'User',
|
auth: 'User',
|
||||||
login: ' login',
|
login: ' login',
|
||||||
logout: ' logout',
|
logout: ' logout',
|
||||||
|
|
|
@ -35,9 +35,12 @@ export default {
|
||||||
rule: {
|
rule: {
|
||||||
username: '请输入用户名',
|
username: '请输入用户名',
|
||||||
password: '请输入密码',
|
password: '请输入密码',
|
||||||
required: '请填写必填项',
|
requiredInput: '请填写必填项',
|
||||||
|
requiredSelect: '请选择必选项',
|
||||||
commonName: '支持英文、中文、数字、.-_,长度1-30',
|
commonName: '支持英文、中文、数字、.-_,长度1-30',
|
||||||
email: '邮箱格式错误',
|
email: '邮箱格式错误',
|
||||||
|
ip: '请输入正确的 IP 地址',
|
||||||
|
port: '请输入正确的端口',
|
||||||
},
|
},
|
||||||
res: {
|
res: {
|
||||||
paramError: '请求失败,请稍后重试!',
|
paramError: '请求失败,请稍后重试!',
|
||||||
|
@ -88,6 +91,7 @@ export default {
|
||||||
operations: {
|
operations: {
|
||||||
detail: {
|
detail: {
|
||||||
users: '用户',
|
users: '用户',
|
||||||
|
hosts: '主机',
|
||||||
auth: '用户',
|
auth: '用户',
|
||||||
post: '创建',
|
post: '创建',
|
||||||
put: '更新',
|
put: '更新',
|
||||||
|
|
Loading…
Reference in New Issue