|
@@ -1,10 +1,9 @@
|
|
|
import React, { useState } from 'react';
|
|
|
-import { Outlet,Link } from 'umi';
|
|
|
+import { Outlet, Link ,useLocation} from 'umi';
|
|
|
import { HomeOutlined, UserOutlined, ShoppingOutlined } from '@ant-design/icons';
|
|
|
-import type { MenuProps } from 'antd';
|
|
|
+import type { MenuProps, MenuTheme } from 'antd';
|
|
|
import { Menu } from 'antd';
|
|
|
import Header from '@/components/Header';
|
|
|
-import Footer from '@/components/Footer';
|
|
|
import './index.less';
|
|
|
|
|
|
type MenuItem = Required<MenuProps>['items'][number];
|
|
@@ -26,25 +25,49 @@ function getItem(
|
|
|
}
|
|
|
|
|
|
const items: MenuItem[] = [
|
|
|
- getItem((<Link to="/">系统首页</Link>), 'admin_1', <HomeOutlined />),
|
|
|
- getItem('用户管理', 'admin_2', <UserOutlined />,
|
|
|
+ getItem((<Link to="/">系统首页</Link>), '/', <HomeOutlined />),
|
|
|
+ getItem('用户管理', '/test1', <UserOutlined />,
|
|
|
[
|
|
|
- getItem((<Link to="/user">普通用户</Link>), 'admin_2_1'),
|
|
|
- getItem((<Link to="/admin">管理员</Link>), 'admin_2_2'),
|
|
|
+ getItem((<Link to="/user">普通用户</Link>), '/user', <UserOutlined />),
|
|
|
+ getItem((<Link to="/admin">管理员</Link>), '/admin', <UserOutlined />),
|
|
|
]),
|
|
|
- getItem('产品管理', 'admin_3', <ShoppingOutlined />,
|
|
|
+ getItem('产品管理', '/test2', <ShoppingOutlined />,
|
|
|
[
|
|
|
- getItem((<Link to="/tea">茶产品</Link>), 'admin_3_1'),
|
|
|
- getItem((<Link to="/fruit">水果茶产品</Link>), 'admin_3_2'),
|
|
|
- getItem((<Link to="/products">茶副产品</Link>), 'admin_3_3'),
|
|
|
+ getItem((<Link to="/tea">茶产品</Link>), '/tea', <ShoppingOutlined />),
|
|
|
+ getItem((<Link to="/fruit">水果茶产品</Link>), '/fruit', <ShoppingOutlined />),
|
|
|
+ getItem((<Link to="/products">茶副产品</Link>), '/products', <ShoppingOutlined />),
|
|
|
]),
|
|
|
];
|
|
|
|
|
|
-// submenu keys of first level
|
|
|
-const rootSubmenuKeys = ['admin_1', 'admin_2', 'admin_3'];
|
|
|
+// 所有一级菜单
|
|
|
+const rootSubmenuKeys = ['/', '/test1', '/test2'];
|
|
|
|
|
|
const App: React.FC = () => {
|
|
|
- const [openKeys, setOpenKeys] = useState(['admin_1']);
|
|
|
+ // 处理刷新回到刷新前的页面
|
|
|
+ const location = useLocation();
|
|
|
+ let one='';
|
|
|
+ let two='';
|
|
|
+ const list:any = items;
|
|
|
+ for (const val of list) {
|
|
|
+ if(val.key===location.pathname){
|
|
|
+ one=val.key
|
|
|
+ two=val.key
|
|
|
+ break
|
|
|
+ }else{
|
|
|
+ if(val.children){
|
|
|
+ for (const as of val.children) {
|
|
|
+ if(as.key===location.pathname) {
|
|
|
+ one=val.key
|
|
|
+ two=as.key
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const defaultOpenKeys = [two];
|
|
|
+ const [openKeys, setOpenKeys] = useState([one]);
|
|
|
+ const [theme] = useState<MenuTheme>('dark');
|
|
|
const onOpenChange: MenuProps['onOpenChange'] = (keys) => {
|
|
|
const latestOpenKey = keys.find((key) => openKeys.indexOf(key) === -1);
|
|
|
if (rootSubmenuKeys.indexOf(latestOpenKey!) === -1) {
|
|
@@ -56,11 +79,12 @@ const App: React.FC = () => {
|
|
|
return (
|
|
|
<div className='main'>
|
|
|
<div className='top'><Header /></div>
|
|
|
- <div className='center'>
|
|
|
+ <div className='down'>
|
|
|
<div className='left'>
|
|
|
<Menu
|
|
|
mode="inline"
|
|
|
- defaultSelectedKeys={openKeys}
|
|
|
+ theme={theme}
|
|
|
+ defaultSelectedKeys={defaultOpenKeys}
|
|
|
defaultOpenKeys={openKeys}
|
|
|
openKeys={openKeys}
|
|
|
onOpenChange={onOpenChange}
|
|
@@ -70,7 +94,6 @@ const App: React.FC = () => {
|
|
|
</div>
|
|
|
<div className='right'><Outlet /></div>
|
|
|
</div>
|
|
|
- <div className='down'><Footer /></div>
|
|
|
</div>
|
|
|
);
|
|
|
};
|