UNPKG

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