表单可个性化配置功能开发:
1.代码生成器-增加对列表中按钮的个性化配置控制 2.useFormConfig.ts-优化代码,增加对配置错误的捕获并弹出错误信息
This commit is contained in:
@ -3,41 +3,85 @@ import { FormSchema } from '/@/components/Form';
|
||||
import { BasicColumn } from "/@/components/Table";
|
||||
import { getFormTemplateUsingCache } from '/@/api/form/design';
|
||||
import { deepMerge } from '/@/utils';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
|
||||
const { t } = useI18n();
|
||||
const { notification } = useMessage();
|
||||
|
||||
export function useFormConfig() {
|
||||
async function mergeFormSchemas(formSchema: FormSchema[],formId:String){
|
||||
const formProps=await queryConfig(formId,'formProps');
|
||||
let fschemas=formProps?.schemas;
|
||||
if(fschemas&&fschemas.length>0){
|
||||
return deepMerge(formSchema,fschemas);
|
||||
}else{
|
||||
return formSchema;
|
||||
try{
|
||||
const formProps=await queryConfig(formId,'formProps');
|
||||
let fschemas=formProps?.schemas;
|
||||
if(fschemas&&fschemas.length>0){
|
||||
return deepMerge(formSchema,fschemas);
|
||||
}else{
|
||||
return formSchema;
|
||||
}
|
||||
}catch(e){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: '解析表单渲染覆盖配置出错[解析formProps发生异常]',
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function mergeColumns(columns: BasicColumn[],formId:String){
|
||||
const cols=await queryConfig(formId,'columns');
|
||||
if(cols&&cols.length>0){
|
||||
const filteredCol = cols.filter(colItem =>
|
||||
columns.some(column => column.dataIndex === colItem.dataIndex)
|
||||
);
|
||||
return filteredCol;
|
||||
}else{
|
||||
return columns;
|
||||
try{
|
||||
const cols=await queryConfig(formId,'columns');
|
||||
if(cols&&cols.length>0){
|
||||
const filteredCol = cols.filter(colItem =>
|
||||
columns.some(column => column.dataIndex === colItem.dataIndex)
|
||||
);
|
||||
return filteredCol;
|
||||
}else{
|
||||
return columns;
|
||||
}
|
||||
}catch(e){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: '解析表单渲染覆盖配置出错[解析columns发生异常]',
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function mergeSearchFormSchema(searchFormSchema: FormSchema[],formId:String){
|
||||
const sFormSchema=await queryConfig(formId,'searchFormSchema');
|
||||
if(sFormSchema&&sFormSchema.length>0){
|
||||
const filteredsFormSchema = sFormSchema.filter(sItem =>
|
||||
searchFormSchema.some( searchItem => searchItem.field === sItem.field)
|
||||
);
|
||||
return filteredsFormSchema;
|
||||
try{
|
||||
const sFormSchema=await queryConfig(formId,'searchFormSchema');
|
||||
if(sFormSchema&&sFormSchema.length>0){
|
||||
const filteredsFormSchema = sFormSchema.filter(sItem =>
|
||||
searchFormSchema.some( searchItem => searchItem.field === sItem.field)
|
||||
);
|
||||
return filteredsFormSchema;
|
||||
}else{
|
||||
return searchFormSchema;
|
||||
}
|
||||
}catch(e){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: '解析表单渲染覆盖配置出错[解析searchFormSchema发生异常]',
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function mergeButtons(buttons,formId:String){
|
||||
try{
|
||||
const btns=await queryConfig(formId,'buttons');
|
||||
if(btns&&btns.length>0){
|
||||
return btns;
|
||||
}else{
|
||||
return searchFormSchema;
|
||||
return buttons;
|
||||
}
|
||||
}catch(e){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: '解析表单渲染覆盖配置出错[解析buttons发生异常]',
|
||||
});
|
||||
return[];
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +97,6 @@ export function useFormConfig() {
|
||||
if(varName==configName) {
|
||||
try {
|
||||
const value = new Function(`return ${cleanCode}`)();
|
||||
// console.log(value);
|
||||
return value;
|
||||
} catch (e) {
|
||||
console.error(`Failed to parse ${varName}:`, e);
|
||||
@ -67,6 +110,7 @@ export function useFormConfig() {
|
||||
return {
|
||||
mergeFormSchemas,
|
||||
mergeColumns,
|
||||
mergeSearchFormSchema
|
||||
mergeSearchFormSchema,
|
||||
mergeButtons
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user