refactor: 代码生成生成信息表单优化

This commit is contained in:
puhui999
2025-04-16 14:28:32 +08:00
parent dc56f97bb6
commit 1da8726371

View File

@@ -11,7 +11,7 @@ import { isEmpty } from '@vben/utils';
import {
useGenerationInfoBaseFormSchema,
useGenerationInfoSubTableFormSchema,
useGenerationInfoTreeFormSchema
useGenerationInfoTreeFormSchema,
} from '../data';
const props = defineProps<{
@@ -59,14 +59,14 @@ const [SubForm, subFormApi] = useVbenForm({
/** 更新树表信息表单 schema */
function updateTreeSchema(): void {
treeFormApi.setState({
schema: useGenerationInfoTreeFormSchema(props.columns)
schema: useGenerationInfoTreeFormSchema(props.columns),
});
}
/** 更新主子表信息表单 schema */
function updateSubSchema(): void {
subFormApi.setState({
schema: useGenerationInfoSubTableFormSchema(props.columns, tables.value)
schema: useGenerationInfoSubTableFormSchema(props.columns, tables.value),
});
}
@@ -75,7 +75,6 @@ async function getAllFormValues(): Promise<Record<string, any>> {
// 基础表单值
const baseValues = await baseFormApi.getValues();
// 根据模板类型获取对应的额外表单值
// TODO @puhui999使用二元表达式
let extraValues = {};
if (isTreeTable.value) {
extraValues = await treeFormApi.getValues();
@@ -88,20 +87,18 @@ async function getAllFormValues(): Promise<Record<string, any>> {
/** 验证所有表单 */
async function validateAllForms() {
let validateResult: boolean;
// 验证基础表单
const { valid: baseFormValid } = await baseFormApi.validate();
validateResult = baseFormValid;
// 根据模板类型验证对应的额外表单
// TODO @puhui999可以类似上面抽个类似 extraValid然后最后 validateResult && extraValid 类似这种哇?
let extraValid = true;
if (isTreeTable.value) {
const { valid: treeFormValid } = await treeFormApi.validate();
validateResult = baseFormValid && treeFormValid;
extraValid = treeFormValid;
} else if (isSubTable.value) {
const { valid: subFormValid } = await subFormApi.validate();
validateResult = baseFormValid && subFormValid;
extraValid = subFormValid;
}
return validateResult;
return baseFormValid && extraValid;
}
/** 设置表单值 */
@@ -130,15 +127,18 @@ watch(
if (!val || isEmpty(val)) {
return;
}
const table = val as InfraCodegenApi.CodegenTable;
// 初始化树表的 schema
updateTreeSchema();
// 设置表单值
setAllFormValues(val);
setAllFormValues(table);
// 获取表数据,用于主子表选择
if (typeof val.dataSourceConfigId === undefined) {
const dataSourceConfigId = table.dataSourceConfigId;
if (dataSourceConfigId === undefined) {
return;
}
tables.value = await getCodegenTableList(val.dataSourceConfigId);
tables.value = await getCodegenTableList(dataSourceConfigId);
// 初始化子表 schema
updateSubSchema();
},