UNPKG

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