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