Skip to content

Commit

Permalink
refactor: nav performance
Browse files Browse the repository at this point in the history
  • Loading branch information
d3george committed Jun 18, 2024
1 parent 10c099a commit 9bbedee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
11 changes: 4 additions & 7 deletions src/layouts/dashboard/nav-horizontal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -26,18 +29,12 @@ export default function NavHorizontal() {
*/
const [openKeys, setOpenKeys] = useState<string[]>([]);
const [selectedKeys, setSelectedKeys] = useState<string[]>(['']);
const [menuList, setMenuList] = useState<ItemType[]>([]);
const [menuList] = useState<ItemType[]>(menus);

useEffect(() => {
setSelectedKeys([pathname]);
}, [pathname, matches]);

useEffect(() => {
const menuRoutes = menuFilter(permissionRoutes);
const menus = routeToMenuFn(menuRoutes);
setMenuList(menus);
}, [permissionRoutes, routeToMenuFn]);

/**
* events
*/
Expand Down
13 changes: 4 additions & 9 deletions src/layouts/dashboard/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

useEffect(() => {
Expand All @@ -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) {
Expand Down Expand Up @@ -165,7 +161,6 @@ export default function Nav(props: Props) {
onClick={onClick}
style={menuStyle}
inlineCollapsed={collapsed}
inlineIndent={50}
/>
</Scrollbar>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/store/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
};

Expand Down

0 comments on commit 9bbedee

Please sign in to comment.