diff --git a/src/api/system/menu/index.ts b/src/api/system/menu/index.ts index 7e620e6..1dd879a 100644 --- a/src/api/system/menu/index.ts +++ b/src/api/system/menu/index.ts @@ -11,6 +11,7 @@ enum Api { SimpleTree = '/system/menu/simple-tree', TenantSimpleTree = '/system/menu/tenant-auth-tree', Menu = '/system/menu', + MenuInfoByComponentPath = '/system/menu/info-by-component-path', Button = '/system/menu/button', Column = '/system/menu-colum/list', Form = '/system/menu-form/list', @@ -197,3 +198,21 @@ export async function getMenuFormById(params, mode: ErrorMessageMode = 'modal') }, ); } + +/** + * @description: 根据组件路径查询菜单 + */ +export async function getMenuByIdComponentPath(componentPath:String, mode: ErrorMessageMode = 'modal') { + return defHttp.get( + { + url: Api.MenuInfoByComponentPath, + params:{componentPath} + }, + { + errorMessageMode: mode, + }, + ); +} + + + diff --git a/src/hooks/web/useFormConfig.ts b/src/hooks/web/useFormConfig.ts index be1f517..d93b729 100644 --- a/src/hooks/web/useFormConfig.ts +++ b/src/hooks/web/useFormConfig.ts @@ -2,6 +2,7 @@ import { FormSchema } from '/@/components/Form'; import { BasicColumn } from "/@/components/Table"; import { getFormTemplateUsingCache } from '/@/api/form/design'; +import { getMenuByIdComponentPath } from '/@/api/system/menu'; import { deepMerge } from '/@/utils'; import { useI18n } from '/@/hooks/web/useI18n'; import { useMessage } from '/@/hooks/web/useMessage'; @@ -10,9 +11,9 @@ const { t } = useI18n(); const { notification } = useMessage(); export function useFormConfig() { - async function mergeFormSchemas(formSchema: FormSchema[],formId:String){ + async function mergeFormSchemas(formSchema: FormSchema[],formPath:String){ try{ - const formProps=await queryConfig(formId,'formProps'); + const formProps=await queryConfigByFormPath(formPath,'formProps'); let fschemas=formProps?.schemas; if(fschemas&&fschemas.length>0){ return deepMerge(formSchema,fschemas); @@ -20,14 +21,20 @@ export function useFormConfig() { return formSchema; } }catch(e){ - notification.error({ - message: t('提示'), - description: '解析表单渲染覆盖配置出错[解析formProps发生异常]', - }); return []; } } + async function mergeFormEventConfigs(formEventConfigs,componentPath:String){ + try{ + const fEConfigs=await queryConfigByFormPath(componentPath,'formEventConfigs'); + return deepMerge(formEventConfigs,fEConfigs); + }catch(e){ + return {}; + } + } + + async function mergeColumns(columns: BasicColumn[],formId:String){ try{ const cols=await queryConfig(formId,'columns'); @@ -40,10 +47,6 @@ export function useFormConfig() { return columns; } }catch(e){ - notification.error({ - message: t('提示'), - description: '解析表单渲染覆盖配置出错[解析columns发生异常]', - }); return []; } } @@ -60,10 +63,6 @@ export function useFormConfig() { return searchFormSchema; } }catch(e){ - notification.error({ - message: t('提示'), - description: '解析表单渲染覆盖配置出错[解析searchFormSchema发生异常]', - }); return []; } } @@ -77,14 +76,31 @@ export function useFormConfig() { return buttons; } }catch(e){ - notification.error({ - message: t('提示'), - description: '解析表单渲染覆盖配置出错[解析buttons发生异常]', - }); return[]; } } + async function queryConfigByFormPath(componentPath:String,configName:String){ + if(componentPath==null){ + notification.error({ + message: t('提示'), + description: `发生异常,组件路径不能为空!`, + }); + throw new Error('发生异常,组件路径不能为空!'); + } + const menu=await getMenuByIdComponentPath("/"+componentPath+"/index"); + if(menu==null){ + notification.error({ + message: t('提示'), + description: `发生异常,根据组件路径找不到菜单!`, + }); + throw new Error('发生异常,根据组件路径找不到菜单!'); + } + const formId=menu.formId; + + return await queryConfig(formId,configName); + + } async function queryConfig(formId:String,configName:String){ const formTemplate = await getFormTemplateUsingCache(formId); @@ -100,6 +116,10 @@ export function useFormConfig() { return value; } catch (e) { console.error(`Failed to parse ${varName}:`, e); + notification.error({ + message: t('提示'), + description: `解析表单渲染覆盖配置出错[解析${configName}发生异常]`, + }); throw new Error('解析表单渲染覆盖配置出错,请联系管理员处理'); } } @@ -111,6 +131,7 @@ export function useFormConfig() { mergeFormSchemas, mergeColumns, mergeSearchFormSchema, - mergeButtons + mergeButtons, + mergeFormEventConfigs }; } diff --git a/src/utils/helper/generatorHelper.ts b/src/utils/helper/generatorHelper.ts index 382dbbd..d06e09b 100644 --- a/src/utils/helper/generatorHelper.ts +++ b/src/utils/helper/generatorHelper.ts @@ -1453,9 +1453,9 @@ ${hasTemplatePrint ? ' reactive ' : ''} } else { bus.on(FORM_LIST_MODIFIED, handleRefresh); } - setCustomConfigColumns(); - setCustomSearchFormSchema(); - setCustomButtons(); + + // 合并渲染覆盖配置中的列表配置,包括展示字段配置、搜索字段配置、按钮配置 + mergeCustomListRenderConfig(); }); onUnmounted(() => { if (schemaIdComputedRef.value) { @@ -1604,26 +1604,20 @@ ${hasTemplatePrint ? ' reactive ' : ''} : '' } - async function setCustomConfigColumns(){ + async function mergeCustomListRenderConfig(){ if (formConfig.useCustomConfig) { - const cols= await mergeColumns(customConfigColums.value,currentRoute.value.meta.formId); - customConfigColums.value=cols; + let formId=currentRoute.value.meta.formId; + //1.合并展示字段配置 + let cols= await mergeColumns(customConfigColums.value,formId); + customConfigColums.value=cols; + //2.合并搜索字段配置 + let sFormSchema= await mergeSearchFormSchema(customSearchFormSchema.value,formId); + customSearchFormSchema.value=sFormSchema; + //3.合并按钮配置 + let btns= await mergeButtons(buttons.value,formId); + buttons.value=btns; } }; - - async function setCustomSearchFormSchema(){ - if (formConfig.useCustomConfig) { - const cols= await mergeSearchFormSchema(customSearchFormSchema.value,currentRoute.value.meta.formId); - customSearchFormSchema.value=cols; - } - }; - - async function setCustomButtons(){ - if (formConfig.useCustomConfig) { - const btns= await mergeButtons(buttons.value,currentRoute.value.meta.formId); - buttons.value=btns; - } - };