更新数据库管理
This commit is contained in:
@@ -45,9 +45,62 @@ const createDefaultField = (): FieldType => ({
|
||||
|
||||
/**
|
||||
* JSON模式数据转换
|
||||
* 支持单个对象或对象数组(批量生成)
|
||||
*/
|
||||
export function transformJsonToStandard(json: any): CodeGenData {
|
||||
// 如果JSON包含完整结构,直接使用
|
||||
export function transformJsonToStandard(json: any): CodeGenData | CodeGenData[] {
|
||||
// 如果输入是数组(批量生成多个模块)
|
||||
if (Array.isArray(json) && json.length > 0) {
|
||||
// 检查第一个元素是否是完整的模块配置
|
||||
if (json[0] && json[0].class_name && json[0].field) {
|
||||
// 数组中的每个元素都是完整的模块配置
|
||||
return json.map((item: any) => ({
|
||||
class_name: item.class_name || '',
|
||||
class_comment: item.class_comment || '',
|
||||
icon: item.icon || '',
|
||||
sort: item.sort ?? 9999,
|
||||
pid: item.pid ?? 0,
|
||||
field: Array.isArray(item.field)
|
||||
? item.field.map((f: any) => ({
|
||||
name: f.name || '',
|
||||
type: f.type || 'varchar',
|
||||
type_length: f.type_length || '',
|
||||
default: f.default || '',
|
||||
comment: f.comment || '',
|
||||
not_null: f.not_null !== undefined ? f.not_null : true,
|
||||
formShow: f.formShow !== undefined ? f.formShow : true,
|
||||
tableShow: f.tableShow !== undefined ? f.tableShow : true,
|
||||
formType: f.formType || 'VbenInput',
|
||||
search: f.search !== undefined ? f.search : true,
|
||||
searchValue: f.searchValue || '=',
|
||||
}))
|
||||
: [],
|
||||
}));
|
||||
} else {
|
||||
// 数组中的元素只是字段数组,需要用户补充基础信息
|
||||
return {
|
||||
class_name: '',
|
||||
class_comment: '',
|
||||
icon: '',
|
||||
sort: 9999,
|
||||
pid: 0,
|
||||
field: json.map((f: any) => ({
|
||||
name: f.name || '',
|
||||
type: f.type || 'varchar',
|
||||
type_length: f.type_length || '',
|
||||
default: f.default || '',
|
||||
comment: f.comment || '',
|
||||
not_null: f.not_null !== undefined ? f.not_null : true,
|
||||
formShow: f.formShow !== undefined ? f.formShow : true,
|
||||
tableShow: f.tableShow !== undefined ? f.tableShow : true,
|
||||
formType: f.formType || 'VbenInput',
|
||||
search: f.search !== undefined ? f.search : true,
|
||||
searchValue: f.searchValue || '=',
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 如果JSON包含完整结构,直接使用(单个模块)
|
||||
if (json.class_name && json.field) {
|
||||
return {
|
||||
class_name: json.class_name || '',
|
||||
@@ -73,30 +126,6 @@ export function transformJsonToStandard(json: any): CodeGenData {
|
||||
};
|
||||
}
|
||||
|
||||
// 如果只有字段数组,需要用户补充基础信息
|
||||
if (Array.isArray(json)) {
|
||||
return {
|
||||
class_name: '',
|
||||
class_comment: '',
|
||||
icon: '',
|
||||
sort: 9999,
|
||||
pid: 0,
|
||||
field: json.map((f: any) => ({
|
||||
name: f.name || '',
|
||||
type: f.type || 'varchar',
|
||||
type_length: f.type_length || '',
|
||||
default: f.default || '',
|
||||
comment: f.comment || '',
|
||||
not_null: f.not_null !== undefined ? f.not_null : true,
|
||||
formShow: f.formShow !== undefined ? f.formShow : true,
|
||||
tableShow: f.tableShow !== undefined ? f.tableShow : true,
|
||||
formType: f.formType || 'VbenInput',
|
||||
search: f.search !== undefined ? f.search : true,
|
||||
searchValue: f.searchValue || '=',
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
// 默认返回空结构
|
||||
return {
|
||||
class_name: '',
|
||||
|
||||
Reference in New Issue
Block a user