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 | import {Router, Route, Link, browserHistory, hashHistory, IndexRoute} from 'react-router';
|
10 |
|
11 |
|
12 |
|
13 | export default class SiderView extends React.Component {
|
14 |
|
15 | constructor(props) {
|
16 | super(props);
|
17 | }
|
18 |
|
19 |
|
20 | $renderItem(db) {
|
21 |
|
22 | const{md, config} = db;
|
23 |
|
24 | const res = [];
|
25 |
|
26 | const category = config.category.slice();
|
27 |
|
28 | category.forEach((cg, i) => {
|
29 | const list = md[cg];
|
30 | const items = list.map((item, i) => {
|
31 | return <Menu.Item key={item.page}>{item.page}</Menu.Item>
|
32 | });
|
33 |
|
34 | res.push((
|
35 | <SubMenu key={cg + '-key'} title={cg}>
|
36 | {items}
|
37 | </SubMenu>
|
38 | ));
|
39 | });
|
40 | return res;
|
41 | }
|
42 |
|
43 | componentDidMount() {
|
44 |
|
45 | const{md, config} =this.props.db;
|
46 | const cg = config.category[0];
|
47 |
|
48 | console.log(config);
|
49 |
|
50 |
|
51 |
|
52 | if(cg) PubSub.publish('SET_PAGE', md[cg][0].page);
|
53 | }
|
54 |
|
55 | handleMenuClick({item, key, keyPath}) {
|
56 | console.log(item, key);
|
57 |
|
58 | PubSub.publish('SET_PAGE', key);
|
59 |
|
60 | }
|
61 |
|
62 | render() {
|
63 |
|
64 | const menuItems = this.$renderItem(this.props.db);
|
65 | const{md, config} =this.props.db;
|
66 |
|
67 | const defaultKeys = config.category.map(item => {
|
68 | return item + '-key';
|
69 | })
|
70 |
|
71 | return (
|
72 | <Menu
|
73 | mode="inline"
|
74 | defaultSelectedKeys={['0']}
|
75 | defaultOpenKeys={defaultKeys}
|
76 | style={{ height: '100%' }}
|
77 | onClick={this.handleMenuClick.bind(this)}
|
78 | >
|
79 | {menuItems}
|
80 |
|
81 |
|
82 | </Menu>
|
83 | )
|
84 | }
|
85 | } |
\ | No newline at end of file |