UNPKG

1.82 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
28
29 category.forEach((cg, i) => {
30 const list = md[cg];
31 const items = list.map((item, i) => {
32 const to = `/page/ + ${decodeURIComponent(item.page)}`;
33 return(
34 <Menu.Item key={item.page}>
35 <Link to={to}>
36 {item.page}
37 </Link>
38 </Menu.Item>
39 )
40 });
41
42 res.push((
43 <SubMenu key={cg + '-key'} title={cg}>
44 {items}
45 </SubMenu>
46 ));
47 });
48 return res;
49 }
50
51 componentDidMount() {
52 // const{md, config} =this.props.db;
53 // const cg = config.category[0];
54 // if(cg) PubSub.publish('SET_PAGE', md[cg][0].page);
55 }
56
57 render() {
58 const menuItems = this.$renderItem(this.props.db);
59 const{md, config} =this.props.db;
60
61 const defaultKeys = config.category.map(item => {
62 return item + '-key';
63 })
64
65 return (
66 <Menu
67 mode="inline"
68 defaultSelectedKeys={['0']}
69 defaultOpenKeys={defaultKeys}
70 style={{ height: '100%' }}
71 >
72 {menuItems}
73
74 </Menu>
75 )
76 }
77}
\No newline at end of file