Skip to content

Commit

Permalink
perf: navi menu & add motion config for antd menu
Browse files Browse the repository at this point in the history
  • Loading branch information
zefa authored and d3george committed Jul 15, 2024
1 parent e7c8c92 commit 12c44f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/layouts/dashboard/nav-horizontal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Menu, MenuProps } from 'antd';
import { useState, useEffect, CSSProperties } from 'react';
import { useState, useEffect, CSSProperties, useMemo } from 'react';
import { useNavigate, useMatches, useLocation } from 'react-router-dom';

import { useRouteToMenuFn, usePermissionRoutes, useFlattenedRoutes } from '@/router/hooks';
Expand All @@ -17,8 +17,10 @@ export default function NavHorizontal() {

const routeToMenuFn = useRouteToMenuFn();
const permissionRoutes = usePermissionRoutes();
const menuRoutes = menuFilter(permissionRoutes);
const menuList = routeToMenuFn(menuRoutes);
const menuList = useMemo(() => {
const menuRoutes = menuFilter(permissionRoutes);
return routeToMenuFn(menuRoutes);
}, [routeToMenuFn, permissionRoutes]);

// 获取拍平后的路由菜单
const flattenedRoutes = useFlattenedRoutes();
Expand Down
8 changes: 5 additions & 3 deletions src/layouts/dashboard/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, useState } from 'react';
import { CSSProperties, useEffect, useMemo, useState } from 'react';
import { useLocation, useMatches, useNavigate } from 'react-router-dom';

import MotionContainer from '@/components/animate/motion-container';
Expand Down Expand Up @@ -40,8 +40,10 @@ export default function Nav(props: Props) {

const routeToMenuFn = useRouteToMenuFn();
const permissionRoutes = usePermissionRoutes();
const menuRoutes = menuFilter(permissionRoutes);
const menuList = routeToMenuFn(menuRoutes);
const menuList = useMemo(() => {
const menuRoutes = menuFilter(permissionRoutes);
return routeToMenuFn(menuRoutes);
}, [routeToMenuFn, permissionRoutes]);

// 获取拍平后的路由菜单
const flattenedRoutes = useFlattenedRoutes();
Expand Down
2 changes: 2 additions & 0 deletions src/theme/antd/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const customComponentConfig: ThemeConfig['components'] = {
fontSize: 14,
colorFillAlter: 'transparent',
itemColor: 'rgb(145, 158, 171)',
motionDurationMid: '0.125s',
motionDurationSlow: '0.125s',
},
};

Expand Down

0 comments on commit 12c44f1

Please sign in to comment.