1 | import React from 'react';
|
2 | import { Layout, Menu, Icon } from 'antd';
|
3 |
|
4 | const { SubMenu } = Menu;
|
5 | const { Sider } = Layout;
|
6 |
|
7 | import PubSub from 'pubsub-js';
|
8 |
|
9 |
|
10 | export 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 |
|
43 | setTimeout(()=> {
|
44 |
|
45 | const cg = config.category[0];
|
46 |
|
47 | PubSub.publish('SET_PAGE', );
|
48 | }, 10)
|
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 |
|
62 | return (
|
63 | <Menu
|
64 | mode="inline"
|
65 | defaultSelectedKeys={['0']}
|
66 | defaultOpenKeys={['Comp']}
|
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 |