refactor: 代码生成生成信息表单
parent
54152d65f2
commit
01a4c9dfe1
|
|
@ -243,8 +243,6 @@ export function useTreeTableFormSchema(columns: InfraCodegenApi.CodegenColumn[]
|
||||||
export function useSubTableFormSchema(
|
export function useSubTableFormSchema(
|
||||||
columns: InfraCodegenApi.CodegenColumn[] = [],
|
columns: InfraCodegenApi.CodegenColumn[] = [],
|
||||||
tables: InfraCodegenApi.CodegenTable[] = [],
|
tables: InfraCodegenApi.CodegenTable[] = [],
|
||||||
subColumns: InfraCodegenApi.CodegenColumn[] = [],
|
|
||||||
onSubTableNameSelected: (value: string) => void,
|
|
||||||
): VbenFormSchema[] {
|
): VbenFormSchema[] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
@ -258,87 +256,55 @@ export function useSubTableFormSchema(
|
||||||
},
|
},
|
||||||
formItemClass: 'md:col-span-2',
|
formItemClass: 'md:col-span-2',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'subJoinColumnId',
|
|
||||||
label: '关联子表的成员变量名',
|
|
||||||
help: '子表的成员变量名,默认为子表的名称',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请输入',
|
|
||||||
},
|
|
||||||
formItemClass: 'md:col-span-2',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
component: 'Select',
|
component: 'Select',
|
||||||
fieldName: 'subTableName',
|
fieldName: 'masterTableId',
|
||||||
label: '子表的表名',
|
label: '关联的主表',
|
||||||
help: '关联的子表的表名, 如:sys_user_post',
|
help: '关联主表(父表)的表名, 如:system_user',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
class: 'w-full',
|
class: 'w-full',
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
placeholder: '请选择',
|
placeholder: '请选择',
|
||||||
options: tables.map((table) => ({
|
options: tables.map((table) => ({
|
||||||
label: `${table.tableName}:${table.tableComment}`,
|
label: `${table.tableName}:${table.tableComment}`,
|
||||||
value: table.tableName,
|
value: table.id,
|
||||||
})),
|
|
||||||
onChange: onSubTableNameSelected,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'subTableClassName',
|
|
||||||
label: '子表的类名',
|
|
||||||
help: '子表的类名, 如:SysUserPost',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请输入',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Select',
|
|
||||||
fieldName: 'subTableFkColumnId',
|
|
||||||
label: '子表的外键字段',
|
|
||||||
help: '子表的外键字段的编号,对应主表的主键',
|
|
||||||
componentProps: {
|
|
||||||
class: 'w-full',
|
|
||||||
allowClear: true,
|
|
||||||
placeholder: '请选择',
|
|
||||||
options: subColumns.map((column) => ({
|
|
||||||
label: column.columnName,
|
|
||||||
value: column.id,
|
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'mainTableClassName',
|
|
||||||
label: '主表的类名',
|
|
||||||
help: '主表的类名, 如:SysUser',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '请输入',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
component: 'Select',
|
component: 'Select',
|
||||||
fieldName: 'mainTableFKColumnId',
|
fieldName: 'subJoinColumnId',
|
||||||
label: '主表的外键字段',
|
label: '子表关联的字段',
|
||||||
help: '子表的外键关联到主表的主键字段编号',
|
help: '子表关联的字段, 如:user_id',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
class: 'w-full',
|
class: 'w-full',
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
placeholder: '请选择',
|
placeholder: '请选择',
|
||||||
options: columns.map((column) => ({
|
options: columns.map((column) => ({
|
||||||
label: column.columnName,
|
label: `${column.columnName}:${column.columnComment}`,
|
||||||
value: column.id,
|
value: column.id,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'Input',
|
component: 'RadioGroup',
|
||||||
fieldName: 'subTableClassComment',
|
fieldName: 'subJoinMany',
|
||||||
label: '子表的类描述',
|
label: '关联关系',
|
||||||
help: '子表的描述,例如 用户岗位',
|
help: '主表与子表的关联关系',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: '请输入',
|
class: 'w-full',
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '请选择',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '一对多',
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '一对一',
|
||||||
|
value: 'false',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ const props = defineProps<{
|
||||||
table?: InfraCodegenApi.CodegenTable;
|
table?: InfraCodegenApi.CodegenTable;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const subColumns = ref<InfraCodegenApi.CodegenColumn[]>([]);
|
|
||||||
const tables = ref<InfraCodegenApi.CodegenTable[]>([]);
|
const tables = ref<InfraCodegenApi.CodegenTable[]>([]);
|
||||||
const menus = ref<SystemMenuApi.SystemMenu[]>([]);
|
const menus = ref<SystemMenuApi.SystemMenu[]>([]);
|
||||||
const currentTemplateType = ref<number>();
|
const currentTemplateType = ref<number>();
|
||||||
|
|
@ -56,48 +55,21 @@ const [SubForm, subFormApi] = useVbenForm({
|
||||||
schema: [],
|
schema: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 子表名称选中事件 */
|
/** 更新基础表单 schema */
|
||||||
async function subTableNameSelected(value: string): Promise<void> {
|
|
||||||
// 使用表ID获取子表的字段
|
|
||||||
const subTableColumns = await getSubCodegenColumns(props.table?.dataSourceConfigId, value);
|
|
||||||
subColumns.value = subTableColumns;
|
|
||||||
// 重置已经选择的子表字段
|
|
||||||
await subFormApi.setFieldValue('subTableFkColumnId', undefined);
|
|
||||||
await subFormApi.setFieldValue('mainTableFKColumnId', undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取子表的列 */
|
|
||||||
async function getSubCodegenColumns(
|
|
||||||
dataSourceConfigId: number | undefined,
|
|
||||||
tableName: string,
|
|
||||||
): Promise<InfraCodegenApi.CodegenColumn[]> {
|
|
||||||
if (!dataSourceConfigId || !tableName) return [];
|
|
||||||
|
|
||||||
const tableList = await getCodegenTableList(dataSourceConfigId);
|
|
||||||
const subTable = tableList.find((item) => item.tableName === tableName);
|
|
||||||
if (subTable) {
|
|
||||||
// 这里需要实际API来获取子表的列信息
|
|
||||||
// 由于没有完整接口信息,这里仅模拟返回
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 更新基础表单schema */
|
|
||||||
function updateBaseSchema(): void {
|
function updateBaseSchema(): void {
|
||||||
const schema = useGenerationInfoBaseFormSchema(menus.value);
|
const schema = useGenerationInfoBaseFormSchema(menus.value);
|
||||||
baseFormApi.setState({ schema });
|
baseFormApi.setState({ schema });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 更新树表信息表单schema */
|
/** 更新树表信息表单 schema */
|
||||||
function updateTreeSchema(): void {
|
function updateTreeSchema(): void {
|
||||||
const schema = useTreeTableFormSchema(props.columns);
|
const schema = useTreeTableFormSchema(props.columns);
|
||||||
treeFormApi.setState({ schema });
|
treeFormApi.setState({ schema });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 更新主子表信息表单schema */
|
/** 更新主子表信息表单 schema */
|
||||||
function updateSubSchema(): void {
|
function updateSubSchema(): void {
|
||||||
const schema = useSubTableFormSchema(props.columns, tables.value, subColumns.value, subTableNameSelected);
|
const schema = useSubTableFormSchema(props.columns, tables.value);
|
||||||
subFormApi.setState({ schema });
|
subFormApi.setState({ schema });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,16 +123,18 @@ function setAllFormValues(values: Record<string, any>): void {
|
||||||
/** 监听表格数据变化 */
|
/** 监听表格数据变化 */
|
||||||
watch(
|
watch(
|
||||||
() => props.table,
|
() => props.table,
|
||||||
(val) => {
|
async (val) => {
|
||||||
if (!val) return;
|
if (!val) return;
|
||||||
|
// 初始化树表的schema
|
||||||
// 初始化所有表单的schema
|
|
||||||
updateBaseSchema();
|
|
||||||
updateTreeSchema();
|
updateTreeSchema();
|
||||||
updateSubSchema();
|
|
||||||
|
|
||||||
// 设置表单值
|
// 设置表单值
|
||||||
setAllFormValues(val);
|
setAllFormValues(val);
|
||||||
|
// 获取表数据,用于主子表选择
|
||||||
|
if (typeof val.dataSourceConfigId !== undefined) {
|
||||||
|
tables.value = await getCodegenTableList(val.dataSourceConfigId);
|
||||||
|
// 初始化子表 schema
|
||||||
|
updateSubSchema();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
@ -169,21 +143,8 @@ watch(
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 获取菜单列表
|
// 获取菜单列表
|
||||||
menus.value = await getSimpleMenusList();
|
menus.value = await getSimpleMenusList();
|
||||||
|
// 初始基础信息 schema
|
||||||
// 获取表数据,用于主子表选择
|
|
||||||
if (props.table?.dataSourceConfigId) {
|
|
||||||
tables.value = await getCodegenTableList(props.table.dataSourceConfigId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化所有表单的schema
|
|
||||||
updateBaseSchema();
|
updateBaseSchema();
|
||||||
updateTreeSchema();
|
|
||||||
updateSubSchema();
|
|
||||||
|
|
||||||
// 如果有初始数据,设置表单值
|
|
||||||
if (props.table) {
|
|
||||||
setAllFormValues(props.table);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 暴露出表单校验方法和表单值获取方法 */
|
/** 暴露出表单校验方法和表单值获取方法 */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue