From d5dc4e32d5978fcd271e841832c9cbf1e0c87db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=B4=A2=E5=AF=8C?= <1501583478@qq.com> Date: Tue, 6 Feb 2024 10:00:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DMenu=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=BC=A9=E7=95=A5=E8=8F=9C=E5=8D=95=E5=BC=B9=E7=AA=97=E5=86=85?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=B8=8D=E7=BB=9F=E4=B8=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Menu/src/Menu.vue | 7 +- .../Menu/src/components/useRenderMenuItem.tsx | 84 +++++++++---------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/components/Menu/src/Menu.vue b/src/components/Menu/src/Menu.vue index efd0dd918..195082401 100644 --- a/src/components/Menu/src/Menu.vue +++ b/src/components/Menu/src/Menu.vue @@ -89,11 +89,16 @@ export default defineComponent({ backgroundColor="var(--left-menu-bg-color)" textColor="var(--left-menu-text-color)" activeTextColor="var(--left-menu-text-active-color)" + popperClass={ + unref(menuMode) === 'vertical' + ? `${prefixCls}-popper--vertical` + : `${prefixCls}-popper--horizontal` + } onSelect={menuSelect} > {{ default: () => { - const { renderMenuItem } = useRenderMenuItem(unref(menuMode)) + const { renderMenuItem } = useRenderMenuItem() return renderMenuItem(unref(routers)) } }} diff --git a/src/components/Menu/src/components/useRenderMenuItem.tsx b/src/components/Menu/src/components/useRenderMenuItem.tsx index 3a3392233..301313fe3 100644 --- a/src/components/Menu/src/components/useRenderMenuItem.tsx +++ b/src/components/Menu/src/components/useRenderMenuItem.tsx @@ -2,57 +2,49 @@ import { ElSubMenu, ElMenuItem } from 'element-plus' import { hasOneShowingChild } from '../helper' import { isUrl } from '@/utils/is' import { useRenderMenuTitle } from './useRenderMenuTitle' -import { useDesign } from '@/hooks/web/useDesign' import { pathResolve } from '@/utils/routerHelper' const { renderMenuTitle } = useRenderMenuTitle() -export const useRenderMenuItem = ( +export const useRenderMenuItem = () => // allRouters: AppRouteRecordRaw[] = [], - menuMode: 'vertical' | 'horizontal' -) => { - const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => { - return routers - .filter((v) => !v.meta?.hidden) - .map((v) => { - const meta = v.meta ?? {} - const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v) - const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath(allRouters, v.path).join('/') + { + const renderMenuItem = (routers: AppRouteRecordRaw[], parentPath = '/') => { + return routers + .filter((v) => !v.meta?.hidden) + .map((v) => { + const meta = v.meta ?? {} + const { oneShowingChild, onlyOneChild } = hasOneShowingChild(v.children, v) + const fullPath = isUrl(v.path) ? v.path : pathResolve(parentPath, v.path) // getAllParentPath(allRouters, v.path).join('/') - if ( - oneShowingChild && - (!onlyOneChild?.children || onlyOneChild?.noShowingChildren) && - !meta?.alwaysShow - ) { - return ( - - {{ - default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta) - }} - - ) - } else { - const { getPrefixCls } = useDesign() + if ( + oneShowingChild && + (!onlyOneChild?.children || onlyOneChild?.noShowingChildren) && + !meta?.alwaysShow + ) { + return ( + + {{ + default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta) + }} + + ) + } else { + return ( + + {{ + title: () => renderMenuTitle(meta), + default: () => renderMenuItem(v.children!, fullPath) + }} + + ) + } + }) + } - const preFixCls = getPrefixCls('menu-popper') - return ( - - {{ - title: () => renderMenuTitle(meta), - default: () => renderMenuItem(v.children!, fullPath) - }} - - ) - } - }) + return { + renderMenuItem + } } - - return { - renderMenuItem - } -}