From 31943d17c6d5840d041352d8bcfbab2e6a68ad6d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 1 Mar 2024 00:14:23 +0800 Subject: [PATCH] =?UTF-8?q?2024-02-06=20fix:=20=E4=BF=AE=E5=A4=8DMenu?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=BC=A9=E7=95=A5=E8=8F=9C=E5=8D=95=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E5=86=85=E6=A0=B7=E5=BC=8F=E4=B8=8D=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit ff0566bb7fd2b571b8c617531b1f1a7af6bb1603) --- .../Menu/src/components/useRenderMenuItem.tsx | 89 +++++++++---------- .../src/components/useRenderMenuTitle.tsx | 9 +- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/layout/components/Menu/src/components/useRenderMenuItem.tsx b/src/layout/components/Menu/src/components/useRenderMenuItem.tsx index 17a520a6..301313fe 100644 --- a/src/layout/components/Menu/src/components/useRenderMenuItem.tsx +++ b/src/layout/components/Menu/src/components/useRenderMenuItem.tsx @@ -1,59 +1,50 @@ import { ElSubMenu, ElMenuItem } from 'element-plus' -import type { RouteMeta } from 'vue-router' 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 = ( +const { renderMenuTitle } = useRenderMenuTitle() + +export const useRenderMenuItem = () => // allRouters: AppRouteRecordRaw[] = [], - menuMode: 'vertical' | 'horizontal' -) => { - 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 : 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('/') - const { renderMenuTitle } = useRenderMenuTitle() + 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) + }} + + ) + } + }) + } - if ( - oneShowingChild && - (!onlyOneChild?.children || onlyOneChild?.noShowingChildren) && - !meta?.alwaysShow - ) { - return ( - - {{ - default: () => renderMenuTitle(onlyOneChild ? onlyOneChild?.meta : meta) - }} - - ) - } else { - const { getPrefixCls } = useDesign() - - const preFixCls = getPrefixCls('menu-popper') - return ( - - {{ - title: () => renderMenuTitle(meta), - default: () => renderMenuItem(v.children!, fullPath) - }} - - ) - } - } - }) + return { + renderMenuItem + } } - - return { - renderMenuItem - } -} diff --git a/src/layout/components/Menu/src/components/useRenderMenuTitle.tsx b/src/layout/components/Menu/src/components/useRenderMenuTitle.tsx index fc30b900..8941d9d7 100644 --- a/src/layout/components/Menu/src/components/useRenderMenuTitle.tsx +++ b/src/layout/components/Menu/src/components/useRenderMenuTitle.tsx @@ -1,5 +1,6 @@ import type { RouteMeta } from 'vue-router' import { Icon } from '@/components/Icon' +import { useI18n } from '@/hooks/web/useI18n' export const useRenderMenuTitle = () => { const renderMenuTitle = (meta: RouteMeta) => { @@ -9,10 +10,14 @@ export const useRenderMenuTitle = () => { return icon ? ( <> - {t(title as string)} + + {t(title as string)} + ) : ( - {t(title as string)} + + {t(title as string)} + ) }