UNPKG

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