diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index 98ff2632a..48467b41a 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -169,14 +169,14 @@ func (u *MysqlService) Create(mysqlDto dto.MysqlDBCreate) error { return errors.WithMessage(constant.ErrStructTransform, err.Error()) } - if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("create database if not exists %s character set=%s", mysqlDto.Name, mysqlDto.Format)); err != nil { + if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("create database if not exists `%s` character set=%s", mysqlDto.Name, mysqlDto.Format)); err != nil { return err } tmpPermission := mysqlDto.Permission if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("create user if not exists '%s'@'%s' identified by '%s';", mysqlDto.Username, tmpPermission, mysqlDto.Password)); err != nil { return err } - grantStr := fmt.Sprintf("grant all privileges on %s.* to '%s'@'%s'", mysqlDto.Name, mysqlDto.Username, tmpPermission) + grantStr := fmt.Sprintf("grant all privileges on `%s`.* to '%s'@'%s'", mysqlDto.Name, mysqlDto.Username, tmpPermission) if app.Version == "5.7.39" { grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, mysqlDto.Password) } diff --git a/frontend/src/global/form-rules.ts b/frontend/src/global/form-rules.ts index b99514909..463a77e8c 100644 --- a/frontend/src/global/form-rules.ts +++ b/frontend/src/global/form-rules.ts @@ -32,7 +32,7 @@ const checkName = (rule: any, value: any, callback: any) => { if (value === '' || typeof value === 'undefined' || value == null) { callback(new Error(i18n.global.t('commons.rule.commonName'))); } else { - const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9_]{0,30}$/; + const reg = /^[a-zA-Z0-9\u4e00-\u9fa5]{1}[a-zA-Z0-9_.\u4e00-\u9fa5-]{0,30}$/; if (!reg.test(value) && value !== '') { callback(new Error(i18n.global.t('commons.rule.commonName'))); } else { @@ -41,9 +41,35 @@ const checkName = (rule: any, value: any, callback: any) => { } }; +const checkSimpleName = (rule: any, value: any, callback: any) => { + if (value === '' || typeof value === 'undefined' || value == null) { + callback(new Error(i18n.global.t('commons.rule.simpleName'))); + } 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.simpleName'))); + } else { + callback(); + } + } +}; + +const checkDBName = (rule: any, value: any, callback: any) => { + if (value === '' || typeof value === 'undefined' || value == null) { + callback(new Error(i18n.global.t('commons.rule.dbName'))); + } 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.dbName'))); + } else { + callback(); + } + } +}; + const checkImageName = (rule: any, value: any, callback: any) => { if (value === '' || typeof value === 'undefined' || value == null) { - callback(new Error(i18n.global.t('commons.rule.commonName'))); + callback(new Error(i18n.global.t('commons.rule.imageName'))); } else { const reg = /^[a-zA-Z0-9\u4e00-\u9fa5]{1}[a-z:A-Z0-9_.\u4e00-\u9fa5-]{0,30}$/; if (!reg.test(value) && value !== '') { @@ -98,6 +124,8 @@ interface CommonRule { requiredSelect: FormItemRule; requiredSelectBusiness: FormItemRule; name: FormItemRule; + simpleName: FormItemRule; + dbName: FormItemRule; imageName: FormItemRule; linuxName: FormItemRule; password: FormItemRule; @@ -128,6 +156,16 @@ export const Rules: CommonRule = { message: i18n.global.t('commons.rule.requiredSelect'), trigger: 'change', }, + simpleName: { + required: true, + validator: checkSimpleName, + trigger: 'blur', + }, + dbName: { + required: true, + validator: checkDBName, + trigger: 'blur', + }, imageName: { required: true, validator: checkImageName, diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index a7ae2c433..6d8f7a56e 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -102,7 +102,9 @@ export default { rePassword: 'The passwords are inconsistent. Please check and re-enter the password', requiredInput: 'Please enter the required fields', requiredSelect: 'Please select the required fields', - commonName: 'Support English, numbers, _, length 1-30', + commonName: 'Support English, Chinese, numbers, .-, and _ length 1-30', + simpleName: 'Support English, numbers and _ length 1-30', + dbName: 'Support English, numbers, .-, and _ length 1-30', imageName: 'Support English, Chinese, numbers, :.-_, length 1-30', complexityPassword: 'Please enter a password with more than 8 characters and must contain letters, digits, and special symbols', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 14744dd47..19b32f3c5 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -102,7 +102,9 @@ export default { rePassword: '密码不一致,请检查后重新输入', requiredInput: '请填写必填项', requiredSelect: '请选择必选项', - commonName: '支持英文、数字、_,长度1-30', + commonName: '支持英文、中文、数字、.-和_,长度1-30', + simpleName: '支持英文、数字、_,长度1-30', + dbName: '支持英文、数字、:.-_,长度1-30', imageName: '支持英文、中文、数字、:.-_,长度1-30', complexityPassword: '请输入 8 位以上、必须含有字母、数字、特殊符号的密码', commonPassword: '请输入 6 位以上长度密码', diff --git a/frontend/src/views/app-store/detail/install/index.vue b/frontend/src/views/app-store/detail/install/index.vue index 6360a00e5..4b84dff82 100644 --- a/frontend/src/views/app-store/detail/install/index.vue +++ b/frontend/src/views/app-store/detail/install/index.vue @@ -46,7 +46,7 @@ const installData = ref({ let open = ref(false); let form = ref<{ [key: string]: any }>({}); let rules = ref({ - NAME: [Rules.requiredInput], + NAME: [Rules.simpleName], }); let loading = false; const paramForm = ref(); diff --git a/frontend/src/views/database/mysql/create/index.vue b/frontend/src/views/database/mysql/create/index.vue index 0e7dff737..f150b0696 100644 --- a/frontend/src/views/database/mysql/create/index.vue +++ b/frontend/src/views/database/mysql/create/index.vue @@ -69,7 +69,7 @@ const form = reactive({ description: '', }); const rules = reactive({ - name: [Rules.requiredInput, Rules.name], + name: [Rules.requiredInput, Rules.dbName], username: [Rules.requiredInput, Rules.name], password: [Rules.requiredInput], permission: [Rules.requiredSelect], diff --git a/frontend/src/views/database/mysql/index.vue b/frontend/src/views/database/mysql/index.vue index 5b838de2b..a51bf3fc3 100644 --- a/frontend/src/views/database/mysql/index.vue +++ b/frontend/src/views/database/mysql/index.vue @@ -10,7 +10,11 @@ /> - + {{ $t('commons.service.serviceNotStarted', ['Mysql']) }}
diff --git a/frontend/src/views/database/redis/index.vue b/frontend/src/views/database/redis/index.vue index a8457bc64..7950a3ad3 100644 --- a/frontend/src/views/database/redis/index.vue +++ b/frontend/src/views/database/redis/index.vue @@ -10,7 +10,11 @@ @is-exist="checkExist" v-model:loading="loading" > - + {{ $t('commons.service.serviceNotStarted', ['Redis']) }}