mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 增加ip、端口等校验规则
This commit is contained in:
parent
e68a62c925
commit
977625395b
@ -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'),
|
||||
},
|
||||
};
|
||||
|
@ -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',
|
||||
|
@ -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: '更新',
|
||||
|
Loading…
x
Reference in New Issue
Block a user