diff --git a/src/layouts/dashboard/nav-horizontal.tsx b/src/layouts/dashboard/nav-horizontal.tsx index 741a5363..17d562b3 100644 --- a/src/layouts/dashboard/nav-horizontal.tsx +++ b/src/layouts/dashboard/nav-horizontal.tsx @@ -18,6 +18,9 @@ export default function NavHorizontal() { const routeToMenuFn = useRouteToMenuFn(); const permissionRoutes = usePermissionRoutes(); + const menuRoutes = menuFilter(permissionRoutes); + const menus = routeToMenuFn(menuRoutes); + // 获取拍平后的路由菜单 const flattenedRoutes = useFlattenedRoutes(); @@ -26,18 +29,12 @@ export default function NavHorizontal() { */ const [openKeys, setOpenKeys] = useState([]); const [selectedKeys, setSelectedKeys] = useState(['']); - const [menuList, setMenuList] = useState([]); + const [menuList] = useState(menus); useEffect(() => { setSelectedKeys([pathname]); }, [pathname, matches]); - useEffect(() => { - const menuRoutes = menuFilter(permissionRoutes); - const menus = routeToMenuFn(menuRoutes); - setMenuList(menus); - }, [permissionRoutes, routeToMenuFn]); - /** * events */ diff --git a/src/layouts/dashboard/nav.tsx b/src/layouts/dashboard/nav.tsx index 69f2116d..60cc8a5b 100644 --- a/src/layouts/dashboard/nav.tsx +++ b/src/layouts/dashboard/nav.tsx @@ -41,6 +41,8 @@ export default function Nav(props: Props) { const routeToMenuFn = useRouteToMenuFn(); const permissionRoutes = usePermissionRoutes(); + const menuRoutes = menuFilter(permissionRoutes); + const menus = routeToMenuFn(menuRoutes); // 获取拍平后的路由菜单 const flattenedRoutes = useFlattenedRoutes(); @@ -50,7 +52,7 @@ export default function Nav(props: Props) { const [collapsed, setCollapsed] = useState(false); const [openKeys, setOpenKeys] = useState([]); const [selectedKeys, setSelectedKeys] = useState(['']); - const [menuList, setMenuList] = useState([]); + const [menuList] = useState(menus); const [menuMode, setMenuMode] = useState('inline'); useEffect(() => { @@ -63,13 +65,7 @@ export default function Nav(props: Props) { } setSelectedKeys([pathname]); } - }, [menuList,pathname, matches, collapsed, themeLayout]); - - useEffect(() => { - const menuRoutes = menuFilter(permissionRoutes); - const menus = routeToMenuFn(menuRoutes); - setMenuList(menus); - }, [permissionRoutes, routeToMenuFn]); + }, [menuList, pathname, matches, themeLayout]); useEffect(() => { if (themeLayout === ThemeLayout.Vertical) { @@ -165,7 +161,6 @@ export default function Nav(props: Props) { onClick={onClick} style={menuStyle} inlineCollapsed={collapsed} - inlineIndent={50} /> diff --git a/src/store/userStore.ts b/src/store/userStore.ts index a7704a91..88bead85 100644 --- a/src/store/userStore.ts +++ b/src/store/userStore.ts @@ -64,17 +64,17 @@ export const useSignIn = () => { setUserToken({ accessToken, refreshToken }); setUserInfo(user); navigatge(HOMEPAGE, { replace: true }); - - notification.success({ - message: t('sys.login.loginSuccessTitle'), - description: `${t('sys.login.loginSuccessDesc')}: ${data.username}`, - duration: 3, - }); } catch (err) { message.warning({ content: err.message, duration: 3, }); + } finally { + notification.success({ + message: t('sys.login.loginSuccessTitle'), + description: `${t('sys.login.loginSuccessDesc')}: ${data.username}`, + duration: 3, + }); } };