From 5ecfe83c7415cf6e91a37e5562bea17e1c3d9d55 Mon Sep 17 00:00:00 2001 From: d3george Date: Tue, 5 Nov 2024 22:10:33 +0800 Subject: [PATCH] refactor: nav-vertical refactor --- src/layouts/dashboard/nav/nav-vertical.tsx | 45 ++++++++-------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/src/layouts/dashboard/nav/nav-vertical.tsx b/src/layouts/dashboard/nav/nav-vertical.tsx index 8f945e24..55579026 100644 --- a/src/layouts/dashboard/nav/nav-vertical.tsx +++ b/src/layouts/dashboard/nav/nav-vertical.tsx @@ -2,7 +2,7 @@ import { MenuUnfoldOutlined, MenuFoldOutlined } from '@ant-design/icons'; import { Menu, MenuProps } from 'antd'; import Color from 'color'; import { m } from 'framer-motion'; -import { CSSProperties, useEffect, useMemo, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import { useLocation, useMatches, useNavigate } from 'react-router-dom'; import MotionContainer from '@/components/animate/motion-container'; @@ -14,7 +14,7 @@ import { menuFilter } from '@/router/utils'; import { useSettingActions, useSettings } from '@/store/settingStore'; import { useThemeToken } from '@/theme/hooks'; -import { NAV_COLLAPSED_WIDTH, NAV_WIDTH } from '../config'; +import { NAV_COLLAPSED_WIDTH, NAV_WIDTH, HEADER_HEIGHT } from '../config'; import { ThemeLayout } from '#/enum'; @@ -31,21 +31,18 @@ export default function NavVertical(props: Props) { const { colorPrimary, colorTextBase, colorBgElevated, colorBorder } = useThemeToken(); const settings = useSettings(); + console.log('nav vertical render'); const { themeLayout } = settings; const { setSettings } = useSettingActions(); - const menuStyle: CSSProperties = { - background: colorBgElevated, - }; - const routeToMenuFn = useRouteToMenuFn(); const permissionRoutes = usePermissionRoutes(); + const menuList = useMemo(() => { const menuRoutes = menuFilter(permissionRoutes); return routeToMenuFn(menuRoutes); }, [routeToMenuFn, permissionRoutes]); - // 获取拍平后的路由菜单 const flattenedRoutes = useFlattenedRoutes(); /** @@ -53,27 +50,19 @@ export default function NavVertical(props: Props) { */ const [collapsed, setCollapsed] = useState(false); const [openKeys, setOpenKeys] = useState([]); - const [menuMode, setMenuMode] = useState('inline'); useEffect(() => { if (themeLayout === ThemeLayout.Vertical) { + setCollapsed(false); + const openKeys = matches .filter((match) => match.pathname !== '/') .map((match) => match.pathname); setOpenKeys(openKeys); - } - }, [matches, themeLayout]); - - useEffect(() => { - if (themeLayout === ThemeLayout.Vertical) { - setCollapsed(false); - setMenuMode('inline'); - } - if (themeLayout === ThemeLayout.Mini) { + } else if (themeLayout === ThemeLayout.Mini) { setCollapsed(true); - setMenuMode('inline'); } - }, [themeLayout]); + }, [themeLayout, matches]); /** * events @@ -121,7 +110,11 @@ export default function NavVertical(props: Props) { borderRight: `1px dashed ${Color(colorBorder).alpha(0.6).toString()}`, }} > -
+ {/* */} +
{themeLayout !== ThemeLayout.Mini && ( @@ -141,14 +134,10 @@ export default function NavVertical(props: Props) {
- - {/* */} + {/* */} +