UNPKG

1.78 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 const 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 + '-key'} 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 const defaultKeys = config.category.map(item => {
65 return item + '-key';
66 })
67
68 return (
69 <Menu
70 mode="inline"
71 defaultSelectedKeys={['0']}
72 defaultOpenKeys={defaultKeys}
73 style={{ height: '100%' }}
74 onClick={this.handleMenuClick.bind(this)}
75 >
76 {menuItems}
77
78
79 </Menu>
80 )
81 }
82}
\No newline at end of file