mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2024-11-29 18:37:41 +08:00
feat: 应用参数增加规则校验
This commit is contained in:
parent
f941cd9751
commit
cd921e7682
@ -146,6 +146,46 @@ const checkDomain = (rule: any, value: any, callback: any) => {
|
||||
}
|
||||
};
|
||||
|
||||
const checkParamCommon = (rule: any, value: any, callback: any) => {
|
||||
if (value === '' || typeof value === 'undefined' || value == null) {
|
||||
callback(new Error(i18n.global.t('commons.rule.paramName')));
|
||||
} else {
|
||||
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9._-]{6,30}$/;
|
||||
if (!reg.test(value) && value !== '') {
|
||||
callback(new Error(i18n.global.t('commons.rule.paramName')));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const checkParamComplexity = (rule: any, value: any, callback: any) => {
|
||||
if (value === '' || typeof value === 'undefined' || value == null) {
|
||||
callback(new Error(i18n.global.t('commons.rule.paramComplexity', ['.%@$!&~_'])));
|
||||
} else {
|
||||
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9.%@$!&~_]{6,30}$/;
|
||||
if (!reg.test(value) && value !== '') {
|
||||
callback(new Error(i18n.global.t('commons.rule.paramComplexity', ['.%@$!&~_'])));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const checkParamUrlAndPort = (rule: any, value: any, callback: any) => {
|
||||
if (value === '' || typeof value === 'undefined' || value == null) {
|
||||
callback(new Error(i18n.global.t('commons.rule.paramUrlAndPort')));
|
||||
} else {
|
||||
const reg =
|
||||
/^(https?:\/\/)?((localhost)|([a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+)(:[1-9]\d{0,3}|:[1-5]\d{4}|:6[0-4]\d{3}|:65[0-4]\d{2}|:655[0-2]\d|:6553[0-5])?(\/\S*)?$/;
|
||||
if (!reg.test(value) && value !== '') {
|
||||
callback(new Error(i18n.global.t('commons.rule.paramUrlAndPort')));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
interface CommonRule {
|
||||
requiredInput: FormItemRule;
|
||||
requiredSelect: FormItemRule;
|
||||
@ -164,6 +204,11 @@ interface CommonRule {
|
||||
port: FormItemRule;
|
||||
domain: FormItemRule;
|
||||
databaseName: FormItemRule;
|
||||
|
||||
paramCommon: FormItemRule;
|
||||
paramComplexity: FormItemRule;
|
||||
paramPort: FormItemRule;
|
||||
paramExtUrl: FormItemRule;
|
||||
}
|
||||
|
||||
export const Rules: CommonRule = {
|
||||
@ -260,4 +305,27 @@ export const Rules: CommonRule = {
|
||||
validator: checkDomain,
|
||||
trigger: 'blur',
|
||||
},
|
||||
paramCommon: {
|
||||
required: true,
|
||||
validator: checkParamCommon,
|
||||
trigger: 'blur',
|
||||
},
|
||||
paramComplexity: {
|
||||
required: true,
|
||||
validator: checkParamComplexity,
|
||||
trigger: 'blur',
|
||||
},
|
||||
paramPort: {
|
||||
required: true,
|
||||
trigger: 'blur',
|
||||
min: 1,
|
||||
max: 65535,
|
||||
type: 'number',
|
||||
message: i18n.global.t('commons.rule.port'),
|
||||
},
|
||||
paramExtUrl: {
|
||||
required: true,
|
||||
validator: checkParamUrlAndPort,
|
||||
trigger: 'blur',
|
||||
},
|
||||
};
|
||||
|
@ -133,6 +133,11 @@ export default {
|
||||
ip: 'Please enter the correct IP address',
|
||||
port: 'Please enter the correct port',
|
||||
selectHelper: 'Please select the correct {0} file',
|
||||
domain: 'domain name format error',
|
||||
databaseName: 'Support English, numbers, _, length 1-30',
|
||||
ipErr: 'IP [{0}] format error, please check',
|
||||
paramName: 'Support English, numbers, .- and _, length 6-30',
|
||||
paramComplexity: 'Support English, numbers, {0}, length 6-30',
|
||||
},
|
||||
res: {
|
||||
paramError: 'The request failed, please try again later!',
|
||||
|
@ -136,11 +136,14 @@ export default {
|
||||
email: '请输入正确的邮箱',
|
||||
number: '请输入正确的数字',
|
||||
ip: '请输入正确的 IP 地址',
|
||||
port: '请输入正确的端口',
|
||||
port: '请输入正确的端口,1-65535',
|
||||
selectHelper: '请选择正确的 {0} 文件',
|
||||
domain: '域名格式错误',
|
||||
databaseName: '支持英文、数字、_,长度1-30',
|
||||
ipErr: 'IP [{0}] 格式错误,请检查',
|
||||
paramName: '支持英文、数字、.-和_,长度6-30',
|
||||
paramComplexity: '支持英文、数字、{0},长度6-30',
|
||||
paramUrlAndPort: '格式为 http(s)://(域名/ip):(端口)',
|
||||
},
|
||||
res: {
|
||||
paramError: '请求失败,请稍后重试!',
|
||||
|
@ -114,8 +114,8 @@ const handleParams = () => {
|
||||
pObj.prop = propStart.value + p.envKey;
|
||||
pObj.disabled = p.disabled;
|
||||
paramObjs.value.push(pObj);
|
||||
if (p.default == 'random') {
|
||||
form[p.envKey] = getRandomStr(6);
|
||||
if (p.random) {
|
||||
form[p.envKey] = p.default + '_' + getRandomStr(6);
|
||||
} else {
|
||||
form[p.envKey] = p.default;
|
||||
}
|
||||
@ -124,8 +124,8 @@ const handleParams = () => {
|
||||
rules[p.envKey] = [Rules.requiredSelect];
|
||||
} else {
|
||||
rules[p.envKey] = [Rules.requiredInput];
|
||||
if (p.envKey === 'PANEL_DB_NAME') {
|
||||
rules[p.envKey].push(Rules.dbName);
|
||||
if (p.rule && p.rule != '') {
|
||||
rules[p.envKey].push(Rules[p.rule]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user