refactor: 完善代码生成器保存校验
parent
0f9ccbb955
commit
26c168afc3
|
|
@ -250,6 +250,7 @@ export function useTreeTableFormSchema(columns: InfraCodegenApi.CodegenColumn[]
|
||||||
value: column.id,
|
value: column.id,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
rules: 'selectRequired',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'Select',
|
component: 'Select',
|
||||||
|
|
@ -265,6 +266,7 @@ export function useTreeTableFormSchema(columns: InfraCodegenApi.CodegenColumn[]
|
||||||
value: column.id,
|
value: column.id,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
rules: 'selectRequired',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -300,6 +302,7 @@ export function useSubTableFormSchema(
|
||||||
value: table.id,
|
value: table.id,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
rules: 'selectRequired',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'Select',
|
component: 'Select',
|
||||||
|
|
@ -315,6 +318,7 @@ export function useSubTableFormSchema(
|
||||||
value: column.id,
|
value: column.id,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
rules: 'selectRequired',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'RadioGroup',
|
component: 'RadioGroup',
|
||||||
|
|
@ -336,6 +340,7 @@ export function useSubTableFormSchema(
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
rules: 'required',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,23 +43,25 @@ const getDetail = async () => {
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const submitForm = async () => {
|
const submitForm = async () => {
|
||||||
try {
|
// 表单验证
|
||||||
// 表单验证
|
const basicInfoValid = await basicInfoRef.value?.validate();
|
||||||
await basicInfoRef.value?.validate();
|
if (!basicInfoValid) {
|
||||||
await generateInfoRef.value?.validate();
|
message.warn('保存失败,原因:基本信息表单校验失败请检查!!!');
|
||||||
} catch {
|
return;
|
||||||
message.warn('保存失败,原因:存在表单校验失败请检查!!!');
|
}
|
||||||
|
const generateInfoValid = await generateInfoRef.value?.validate();
|
||||||
|
if (!generateInfoValid) {
|
||||||
|
message.warn('保存失败,原因:生成信息表单校验失败请检查!!!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 提交
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.updating'),
|
content: $t('ui.actionMessage.updating'),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
key: 'action_process_msg',
|
key: 'action_process_msg',
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
debugger;
|
|
||||||
// 获取相关信息
|
// 获取相关信息
|
||||||
const basicInfo = await basicInfoRef.value?.getValues();
|
const basicInfo = await basicInfoRef.value?.getValues();
|
||||||
const columns = columnInfoRef.value?.getData() || unref(formData).columns;
|
const columns = columnInfoRef.value?.getData() || unref(formData).columns;
|
||||||
|
|
@ -71,7 +73,6 @@ const submitForm = async () => {
|
||||||
});
|
});
|
||||||
close();
|
close();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.warn('保存失败!!!');
|
|
||||||
console.error('保存失败', error);
|
console.error('保存失败', error);
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,10 @@ watch(
|
||||||
|
|
||||||
/** 暴露出表单校验方法和表单值获取方法 */
|
/** 暴露出表单校验方法和表单值获取方法 */
|
||||||
defineExpose({
|
defineExpose({
|
||||||
validate: formApi.validate,
|
validate: async () => {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
return valid;
|
||||||
|
},
|
||||||
getValues: formApi.getValues,
|
getValues: formApi.getValues,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -85,14 +85,19 @@ async function getAllFormValues(): Promise<Record<string, any>> {
|
||||||
|
|
||||||
/** 验证所有表单 */
|
/** 验证所有表单 */
|
||||||
async function validateAllForms() {
|
async function validateAllForms() {
|
||||||
|
let validateResult: boolean;
|
||||||
// 验证基础表单
|
// 验证基础表单
|
||||||
await baseFormApi.validate();
|
const { valid: baseFormValid } = await baseFormApi.validate();
|
||||||
|
validateResult = baseFormValid;
|
||||||
// 根据模板类型验证对应的额外表单
|
// 根据模板类型验证对应的额外表单
|
||||||
if (isTreeTable.value) {
|
if (isTreeTable.value) {
|
||||||
await treeFormApi.validate();
|
const { valid: treeFormValid } = await treeFormApi.validate();
|
||||||
|
validateResult = baseFormValid && treeFormValid;
|
||||||
} else if (isSubTable.value) {
|
} else if (isSubTable.value) {
|
||||||
await subFormApi.validate();
|
const { valid: subFormValid } = await subFormApi.validate();
|
||||||
|
validateResult = baseFormValid && subFormValid;
|
||||||
}
|
}
|
||||||
|
return validateResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置表单值 */
|
/** 设置表单值 */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue