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 { import {
useGenerationInfoBaseFormSchema, useGenerationInfoBaseFormSchema,
useGenerationInfoSubTableFormSchema, useGenerationInfoSubTableFormSchema,
useGenerationInfoTreeFormSchema useGenerationInfoTreeFormSchema,
} from '../data'; } from '../data';
const props = defineProps<{ const props = defineProps<{
@ -59,14 +59,14 @@ const [SubForm, subFormApi] = useVbenForm({
/** 更新树表信息表单 schema */ /** 更新树表信息表单 schema */
function updateTreeSchema(): void { function updateTreeSchema(): void {
treeFormApi.setState({ treeFormApi.setState({
schema: useGenerationInfoTreeFormSchema(props.columns) schema: useGenerationInfoTreeFormSchema(props.columns),
}); });
} }
/** 更新主子表信息表单 schema */ /** 更新主子表信息表单 schema */
function updateSubSchema(): void { function updateSubSchema(): void {
subFormApi.setState({ 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(); const baseValues = await baseFormApi.getValues();
// //
// TODO @puhui999使
let extraValues = {}; let extraValues = {};
if (isTreeTable.value) { if (isTreeTable.value) {
extraValues = await treeFormApi.getValues(); extraValues = await treeFormApi.getValues();
@ -88,20 +87,18 @@ async function getAllFormValues(): Promise<Record<string, any>> {
/** 验证所有表单 */ /** 验证所有表单 */
async function validateAllForms() { async function validateAllForms() {
let validateResult: boolean;
// //
const { valid: baseFormValid } = await baseFormApi.validate(); const { valid: baseFormValid } = await baseFormApi.validate();
validateResult = baseFormValid;
// //
// TODO @puhui999 extraValid validateResult && extraValid let extraValid = true;
if (isTreeTable.value) { if (isTreeTable.value) {
const { valid: treeFormValid } = await treeFormApi.validate(); const { valid: treeFormValid } = await treeFormApi.validate();
validateResult = baseFormValid && treeFormValid; extraValid = treeFormValid;
} else if (isSubTable.value) { } else if (isSubTable.value) {
const { valid: subFormValid } = await subFormApi.validate(); 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)) { if (!val || isEmpty(val)) {
return; return;
} }
const table = val as InfraCodegenApi.CodegenTable;
// schema // schema
updateTreeSchema(); updateTreeSchema();
// //
setAllFormValues(val); setAllFormValues(table);
// //
if (typeof val.dataSourceConfigId === undefined) { const dataSourceConfigId = table.dataSourceConfigId;
if (dataSourceConfigId === undefined) {
return; return;
} }
tables.value = await getCodegenTableList(val.dataSourceConfigId); tables.value = await getCodegenTableList(dataSourceConfigId);
// schema // schema
updateSubSchema(); updateSubSchema();
}, },