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