UNPKG

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