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 | const{md, config} =this.props.db;
|
45 | const cg = config.category[0];
|
46 | if(cg) PubSub.publish('SET_PAGE', md[cg][0].page);
|
47 | }
|
48 |
|
49 | handleMenuClick({item, key, keyPath}) {
|
50 |
|
51 | PubSub.publish('SET_PAGE', key);
|
52 | }
|
53 |
|
54 | render() {
|
55 |
|
56 | const menuItems = this.$renderItem(this.props.db);
|
57 | const{md, config} =this.props.db;
|
58 |
|
59 | const defaultKeys = config.category.map(item => {
|
60 | return item + '-key';
|
61 | })
|
62 |
|
63 | return (
|
64 | <Menu
|
65 | mode="inline"
|
66 | defaultSelectedKeys={['0']}
|
67 | defaultOpenKeys={defaultKeys}
|
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 |