|
@@ -0,0 +1,78 @@
|
|
|
+import React, { useState } from 'react';
|
|
|
+import { Outlet,Link } from 'umi';
|
|
|
+import { HomeOutlined, UserOutlined, ShoppingOutlined } from '@ant-design/icons';
|
|
|
+import type { MenuProps } 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];
|
|
|
+
|
|
|
+function getItem(
|
|
|
+ label: React.ReactNode,
|
|
|
+ key: React.Key,
|
|
|
+ icon?: React.ReactNode,
|
|
|
+ children?: MenuItem[],
|
|
|
+ type?: 'group',
|
|
|
+): MenuItem {
|
|
|
+ return {
|
|
|
+ key,
|
|
|
+ icon,
|
|
|
+ children,
|
|
|
+ label,
|
|
|
+ type,
|
|
|
+ } as MenuItem;
|
|
|
+}
|
|
|
+
|
|
|
+const items: MenuItem[] = [
|
|
|
+ getItem((<Link to="/">系统首页</Link>), 'admin_1', <HomeOutlined />),
|
|
|
+ getItem('用户管理', 'admin_2', <UserOutlined />,
|
|
|
+ [
|
|
|
+ getItem((<Link to="/user">普通用户</Link>), 'admin_2_1'),
|
|
|
+ getItem((<Link to="/admin">管理员</Link>), 'admin_2_2'),
|
|
|
+ ]),
|
|
|
+ getItem('产品管理', 'admin_3', <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'),
|
|
|
+ ]),
|
|
|
+];
|
|
|
+
|
|
|
+// submenu keys of first level
|
|
|
+const rootSubmenuKeys = ['admin_1', 'admin_2', 'admin_3'];
|
|
|
+
|
|
|
+const App: React.FC = () => {
|
|
|
+ const [openKeys, setOpenKeys] = useState(['admin_1']);
|
|
|
+ const onOpenChange: MenuProps['onOpenChange'] = (keys) => {
|
|
|
+ const latestOpenKey = keys.find((key) => openKeys.indexOf(key) === -1);
|
|
|
+ if (rootSubmenuKeys.indexOf(latestOpenKey!) === -1) {
|
|
|
+ setOpenKeys(keys);
|
|
|
+ } else {
|
|
|
+ setOpenKeys(latestOpenKey ? [latestOpenKey] : []);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return (
|
|
|
+ <div className='main'>
|
|
|
+ <div className='top'><Header /></div>
|
|
|
+ <div className='center'>
|
|
|
+ <div className='left'>
|
|
|
+ <Menu
|
|
|
+ mode="inline"
|
|
|
+ defaultSelectedKeys={openKeys}
|
|
|
+ defaultOpenKeys={openKeys}
|
|
|
+ openKeys={openKeys}
|
|
|
+ onOpenChange={onOpenChange}
|
|
|
+ style={{ width: 256 }}
|
|
|
+ items={items}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div className='right'><Outlet /></div>
|
|
|
+ </div>
|
|
|
+ <div className='down'><Footer /></div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default App;
|