|
@@ -0,0 +1,62 @@
|
|
|
+import React from 'react'
|
|
|
+import { routes } from './routes'
|
|
|
+import { Layout, Menu } from 'antd'
|
|
|
+import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom'
|
|
|
+import styled from 'styled-components'
|
|
|
+const { Content, Sider } = Layout
|
|
|
+
|
|
|
+const MenuItem = Menu.Item
|
|
|
+
|
|
|
+const DemoTitle = styled.div`
|
|
|
+ height: 32px;
|
|
|
+ margin: 16px;
|
|
|
+ background: rgba(255, 255, 255, 0.2);
|
|
|
+ text-align: center;
|
|
|
+ color: #fff;
|
|
|
+ line-height: 32px;
|
|
|
+`
|
|
|
+
|
|
|
+export default function Sidebar() {
|
|
|
+ const menus = routes.map((item, index) => {
|
|
|
+ return {
|
|
|
+ key: String(index + 1),
|
|
|
+ label: <Link to={item.path}>{item.title}</Link>,
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ let childrenList = []
|
|
|
+ const routesInfo = routes.map(item => {
|
|
|
+ if (item.children.length > 0) {
|
|
|
+ childrenList = childrenList.concat(...item.children)
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ path: item.path,
|
|
|
+ exact: item?.exact,
|
|
|
+ component: <item.component />,
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const list = routesInfo.concat(...childrenList)
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Router>
|
|
|
+ <Layout hasSider>
|
|
|
+ <Sider>
|
|
|
+ <DemoTitle>ai中台demo</DemoTitle>
|
|
|
+ <Menu theme="dark" mode="inline" items={menus} />
|
|
|
+ </Sider>
|
|
|
+ <Content>
|
|
|
+ <Routes>
|
|
|
+ {list.map((route, index) => (
|
|
|
+ <Route
|
|
|
+ key={index}
|
|
|
+ path={route.path}
|
|
|
+ exact={route?.exact}
|
|
|
+ element={route.component}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
+ </Routes>
|
|
|
+ </Content>
|
|
|
+ </Layout>
|
|
|
+ </Router>
|
|
|
+ )
|
|
|
+}
|