1 | import React from 'react';
|
2 | import { Layout, Menu, Icon } from 'antd';
|
3 | import {
|
4 | BrowserRouter as Router,
|
5 | Route,
|
6 | HashRouter,
|
7 | Redirect,
|
8 | Link
|
9 | } from 'react-router-dom';
|
10 |
|
11 | const { SubMenu } = Menu;
|
12 | const { Sider } = Layout;
|
13 |
|
14 | export default class SiderView extends React.Component {
|
15 |
|
16 | constructor(props) {
|
17 | super(props);
|
18 | }
|
19 |
|
20 | $renderItem(db) {
|
21 |
|
22 | const{md, config} = db;
|
23 |
|
24 | const res = [];
|
25 |
|
26 | const category = config.category.slice();
|
27 |
|
28 | category.forEach((cg, i) => {
|
29 | const list = md[cg];
|
30 | const items = list.map((item, i) => {
|
31 | const to = `/page/${item.page}`;
|
32 | return(
|
33 | <Menu.Item key={item.page}>
|
34 | <Link to={to}>
|
35 | {item.page}
|
36 | </Link>
|
37 | </Menu.Item>
|
38 | )
|
39 | });
|
40 |
|
41 | res.push((
|
42 | <SubMenu key={cg + '-key'} title={cg}>
|
43 | {items}
|
44 | </SubMenu>
|
45 | ));
|
46 | });
|
47 | return res;
|
48 | }
|
49 |
|
50 | componentDidMount() {
|
51 |
|
52 |
|
53 |
|
54 | }
|
55 |
|
56 | render() {
|
57 | const menuItems = this.$renderItem(this.props.db);
|
58 | const{md, config} =this.props.db;
|
59 | const cg = config.category[0];
|
60 |
|
61 | const defaultKeys = config.category.map(item => {
|
62 | return item + '-key';
|
63 | })
|
64 |
|
65 |
|
66 |
|
67 | return (
|
68 | <Menu
|
69 | mode="inline"
|
70 | defaultSelectedKeys={['0']}
|
71 | defaultOpenKeys={defaultKeys}
|
72 | style={{ height: '100%' }}
|
73 | >
|
74 | {menuItems}
|
75 |
|
76 |
|
77 | </Menu>
|
78 | )
|
79 | }
|
80 | } |
\ | No newline at end of file |