From ff59fc7e133202945360a7e210f9cdf3a4a89dd7 Mon Sep 17 00:00:00 2001 From: kailong321200875 <321200875@qq.com> Date: Sat, 30 Jul 2022 10:49:16 +0800 Subject: [PATCH] fix: fix menu active bug --- src/components/Menu/src/Menu.vue | 4 ++-- .../Menu/src/components/useRenderMenuItem.tsx | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/components/Menu/src/Menu.vue b/src/components/Menu/src/Menu.vue index 78cede0..9fc7996 100644 --- a/src/components/Menu/src/Menu.vue +++ b/src/components/Menu/src/Menu.vue @@ -94,8 +94,8 @@ export default defineComponent({ > {{ default: () => { - const { renderMenuItem } = useRenderMenuItem(unref(routers), unref(menuMode)) - return renderMenuItem() + const { renderMenuItem } = useRenderMenuItem(unref(menuMode)) + return renderMenuItem(unref(routers)) } }} diff --git a/src/components/Menu/src/components/useRenderMenuItem.tsx b/src/components/Menu/src/components/useRenderMenuItem.tsx index 4e785d2..17a520a 100644 --- a/src/components/Menu/src/components/useRenderMenuItem.tsx +++ b/src/components/Menu/src/components/useRenderMenuItem.tsx @@ -1,23 +1,21 @@ import { ElSubMenu, ElMenuItem } from 'element-plus' import type { RouteMeta } from 'vue-router' -import { getAllParentPath, hasOneShowingChild } from '../helper' +import { hasOneShowingChild } from '../helper' import { isUrl } from '@/utils/is' import { useRenderMenuTitle } from './useRenderMenuTitle' import { useDesign } from '@/hooks/web/useDesign' import { pathResolve } from '@/utils/routerHelper' export const useRenderMenuItem = ( - allRouters: AppRouteRecordRaw[] = [], + // allRouters: AppRouteRecordRaw[] = [], menuMode: 'vertical' | 'horizontal' ) => { - const renderMenuItem = (routers?: AppRouteRecordRaw[]) => { - return (routers || allRouters).map((v) => { + const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => { + return routers.map((v) => { const meta = (v.meta ?? {}) as RouteMeta if (!meta.hidden) { const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v) - const fullPath = isUrl(v.path) - ? v.path - : getAllParentPath(allRouters, v.path).join('/') + const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath(allRouters, v.path).join('/') const { renderMenuTitle } = useRenderMenuTitle() @@ -46,7 +44,7 @@ export const useRenderMenuItem = ( > {{ title: () => renderMenuTitle(meta), - default: () => renderMenuItem(v.children) + default: () => renderMenuItem(v.children!, fullPath) }} )