fix: 修改数据库名称校验

This commit is contained in:
zhengkunwang223 2022-12-20 23:18:33 +08:00 committed by zhengkunwang223
parent 1787261727
commit 168ff2ded3
3 changed files with 21 additions and 1 deletions

View File

@ -80,6 +80,19 @@ const checkDomain = (rule: any, value: any, callback: any) => {
}
};
const checkDatabaseName = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.databaseName')));
} else {
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9_]{0,30}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.databaseName')));
} else {
callback();
}
}
};
interface CommonRule {
requiredInput: FormItemRule;
requiredSelect: FormItemRule;
@ -93,6 +106,7 @@ interface CommonRule {
ip: FormItemRule;
port: FormItemRule;
domain: FormItemRule;
databaseName: FormItemRule;
}
export const Rules: CommonRule = {
@ -129,6 +143,11 @@ export const Rules: CommonRule = {
validator: checkLinuxName,
trigger: 'blur',
},
databaseName: {
required: true,
validator: checkDatabaseName,
trigger: 'blur',
},
password: {
validator: complexityPassword,
trigger: 'blur',

View File

@ -113,6 +113,7 @@ export default {
port: '请输入正确的端口',
selectHelper: '请选择正确的 {0} 文件',
domain: '域名格式错误',
databaseName: '支持英文数字_,长度1-30',
},
res: {
paramError: '请求失败,请稍后重试!',

View File

@ -108,7 +108,7 @@ const handleParams = () => {
} else {
rules[p.envKey] = [Rules.requiredInput];
if (p.envKey === 'PANEL_DB_NAME') {
rules[p.envKey].push(Rules.linuxName);
rules[p.envKey].push(Rules.databaseName);
}
}
}