UNPKG

1.52 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 PubSub.publish('SET_PAGE', this.props.db.config.category[0]);
41 }
42
43 handleMenuClick({item, key, keyPath}) {
44 console.log(item, key);
45
46 PubSub.publish('SET_PAGE', key);
47
48 }
49
50 render() {
51
52 const menuItems = this.$renderItem(this.props.db);
53
54 return (
55 <Menu
56 mode="inline"
57 defaultSelectedKeys={['0']}
58 defaultOpenKeys={['Comp']}
59 style={{ height: '100%' }}
60 onClick={this.handleMenuClick.bind(this)}
61 >
62 {menuItems}
63
64
65 </Menu>
66 )
67 }
68}
\No newline at end of file