diff --git a/frontend/src/global/form-rules.ts b/frontend/src/global/form-rules.ts index 5844246be..0194a5d52 100644 --- a/frontend/src/global/form-rules.ts +++ b/frontend/src/global/form-rules.ts @@ -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', + }, }; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 77cd65e80..1cebd52ed 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -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!', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 7f4983c0d..e396ccdb1 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -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: '请求失败,请稍后重试!', diff --git a/frontend/src/views/app-store/detail/params/index.vue b/frontend/src/views/app-store/detail/params/index.vue index d5874bf5c..880616586 100644 --- a/frontend/src/views/app-store/detail/params/index.vue +++ b/frontend/src/views/app-store/detail/params/index.vue @@ -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]); } } }