UNPKG

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