UNPKG

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