Skip to content

Commit

Permalink
fix: #68
Browse files Browse the repository at this point in the history
  • Loading branch information
d3george committed Jun 20, 2024
1 parent 9bbedee commit af1a77c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/layouts/dashboard/nav-horizontal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Menu, MenuProps } from 'antd';
import { ItemType } from 'antd/es/menu/hooks/useItems';
import { useState, useEffect, CSSProperties } from 'react';
import { useNavigate, useMatches, useLocation } from 'react-router-dom';

Expand All @@ -19,7 +18,7 @@ export default function NavHorizontal() {
const routeToMenuFn = useRouteToMenuFn();
const permissionRoutes = usePermissionRoutes();
const menuRoutes = menuFilter(permissionRoutes);
const menus = routeToMenuFn(menuRoutes);
const menuList = routeToMenuFn(menuRoutes);

// 获取拍平后的路由菜单
const flattenedRoutes = useFlattenedRoutes();
Expand All @@ -29,7 +28,6 @@ export default function NavHorizontal() {
*/
const [openKeys, setOpenKeys] = useState<string[]>([]);
const [selectedKeys, setSelectedKeys] = useState<string[]>(['']);
const [menuList] = useState<ItemType[]>(menus);

useEffect(() => {
setSelectedKeys([pathname]);
Expand Down
25 changes: 10 additions & 15 deletions src/layouts/dashboard/nav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MenuUnfoldOutlined, MenuFoldOutlined } from '@ant-design/icons';
import { Menu, MenuProps } from 'antd';
import { ItemType } from 'antd/es/menu/hooks/useItems';
import Color from 'color';
import { m } from 'framer-motion';
import { CSSProperties, useEffect, useState } from 'react';
Expand Down Expand Up @@ -42,7 +41,8 @@ export default function Nav(props: Props) {
const routeToMenuFn = useRouteToMenuFn();
const permissionRoutes = usePermissionRoutes();
const menuRoutes = menuFilter(permissionRoutes);
const menus = routeToMenuFn(menuRoutes);
const menuList = routeToMenuFn(menuRoutes);

// 获取拍平后的路由菜单
const flattenedRoutes = useFlattenedRoutes();

Expand All @@ -51,21 +51,16 @@ export default function Nav(props: Props) {
*/
const [collapsed, setCollapsed] = useState(false);
const [openKeys, setOpenKeys] = useState<string[]>([]);
const [selectedKeys, setSelectedKeys] = useState<string[]>(['']);
const [menuList] = useState<ItemType[]>(menus);
const [menuMode, setMenuMode] = useState<MenuProps['mode']>('inline');

useEffect(() => {
if (menuList?.length > 0) {
if (themeLayout === ThemeLayout.Vertical) {
const openKeys = matches
.filter((match) => match.pathname !== '/')
.map((match) => match.pathname);
setOpenKeys(openKeys);
}
setSelectedKeys([pathname]);
if (themeLayout === ThemeLayout.Vertical) {
const openKeys = matches
.filter((match) => match.pathname !== '/')
.map((match) => match.pathname);
setOpenKeys(openKeys);
}
}, [menuList, pathname, matches, themeLayout]);
}, [matches, themeLayout]);

useEffect(() => {
if (themeLayout === ThemeLayout.Vertical) {
Expand Down Expand Up @@ -154,8 +149,8 @@ export default function Nav(props: Props) {
items={menuList}
className="h-full !border-none"
defaultOpenKeys={openKeys}
defaultSelectedKeys={selectedKeys}
selectedKeys={selectedKeys}
defaultSelectedKeys={[pathname]}
selectedKeys={[pathname]}
openKeys={openKeys}
onOpenChange={onOpenChange}
onClick={onClick}
Expand Down

0 comments on commit af1a77c

Please sign in to comment.