refactor: 代码生成生成信息表单优化
parent
dc56f97bb6
commit
1da8726371
|
@ -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();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue