mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-22 23:28:43 +00:00
feat(CRUD):增加字段名称检查
This commit is contained in:
parent
f5ec3e3849
commit
bff475dc72
@ -113,4 +113,6 @@ export default {
|
||||
'If it is left blank, the model of the associated table will be generated automatically If the table already has a model, it is recommended to select it to avoid repeated generation',
|
||||
'The field comment will be used as the CRUD dictionary, and will be identified as the field title before the colon, and as the data dictionary after the colon':
|
||||
'The field comment will be used as the CRUD dictionary, and will be identified as the field title before the colon, and as the data dictionary after the colon',
|
||||
'Field name is invalid It starts with a letter or underscore and cannot contain any character other than letters, digits, or underscores':
|
||||
'Field name {field} is invalid. It starts with a letter or underscore and cannot contain any character other than letters, digits, or underscores',
|
||||
}
|
||||
|
@ -112,4 +112,6 @@ export default {
|
||||
'留空则自动生成关联表的模型,若该表已有模型,建议选择好以免重复生成',
|
||||
'The field comment will be used as the CRUD dictionary, and will be identified as the field title before the colon, and as the data dictionary after the colon':
|
||||
'字段注释将作为 CRUD字典,冒号前将识别为字段标题,冒号后识别为数据字典',
|
||||
'Field name is invalid It starts with a letter or underscore and cannot contain any character other than letters, digits, or underscores':
|
||||
'字段名 {field} 不符合规范,请以 字母、_ 开头,不能出现 字母、数字、下划线 以外的字符',
|
||||
}
|
||||
|
@ -48,11 +48,14 @@ export function validatorPassword(rule: any, val: string, callback: Function) {
|
||||
/**
|
||||
* 变量名验证
|
||||
*/
|
||||
export function regularVarName(val: string) {
|
||||
return /^([^\x00-\xff]|[a-zA-Z_$])([^\x00-\xff]|[a-zA-Z0-9_$])*$/.test(val)
|
||||
}
|
||||
export function validatorVarName(rule: any, val: string, callback: Function) {
|
||||
if (!val) {
|
||||
return callback()
|
||||
}
|
||||
if (!/^([^\x00-\xff]|[a-zA-Z_$])([^\x00-\xff]|[a-zA-Z0-9_$])*$/.test(val)) {
|
||||
if (!regularVarName(val)) {
|
||||
return callback(new Error(i18n.global.t('validate.Please enter the correct name')))
|
||||
}
|
||||
return callback()
|
||||
|
@ -494,7 +494,7 @@ import { changeStep, state as crudState, getTableAttr } from '/@/views/backend/c
|
||||
import { ElNotification, FormItemRule, FormInstance, ElMessageBox } from 'element-plus'
|
||||
import { getDatabaseList, getFileData, generateCheck, generate, parseFieldData, postLogStart } from '/@/api/backend/crud'
|
||||
import { getTableFieldList } from '/@/api/common'
|
||||
import { buildValidatorData } from '/@/utils/validate'
|
||||
import { buildValidatorData, regularVarName } from '/@/utils/validate'
|
||||
import { getArrayKey } from '/@/utils/common'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@ -706,13 +706,29 @@ const startGenerate = () => {
|
||||
|
||||
const onGenerate = () => {
|
||||
let msg = ''
|
||||
if (!state.table.name) msg = t('crud.crud.Please enter the data table name!')
|
||||
|
||||
// 字段名检查
|
||||
state.fields.find((item) => {
|
||||
if (!regularVarName(item.name)) {
|
||||
msg = t(
|
||||
'crud.crud.Field name is invalid It starts with a letter or underscore and cannot contain any character other than letters, digits, or underscores',
|
||||
{ field: item.name }
|
||||
)
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
// 主键检查
|
||||
const pkIndex = state.fields.findIndex((item) => {
|
||||
return item.primaryKey
|
||||
})
|
||||
if (pkIndex === -1) {
|
||||
msg = t('crud.crud.Please design the primary key field!')
|
||||
}
|
||||
|
||||
// 表名检查
|
||||
if (!state.table.name) msg = t('crud.crud.Please enter the data table name!')
|
||||
|
||||
if (msg) {
|
||||
ElNotification({
|
||||
type: 'error',
|
||||
|
Loading…
Reference in New Issue
Block a user