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

pull/75/head
puhui999 2025-04-16 14:28:32 +08:00
parent dc56f97bb6
commit 1da8726371
1 changed files with 13 additions and 13 deletions

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();
},