UNPKG

1.83 kBJavaScriptView Raw
1import React from 'react';
2import { Layout, Menu, Icon } from 'antd';
3
4const { SubMenu } = Menu;
5const { Sider } = Layout;
6
7import PubSub from 'pubsub-js';
8
9import {Router, Route, Link, browserHistory, hashHistory, IndexRoute} from 'react-router';
10
11
12
13export 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 console.log(item, key);
51
52 PubSub.publish('SET_PAGE', key);
53
54 }
55
56 render() {
57
58 const menuItems = this.$renderItem(this.props.db);
59 const{md, config} =this.props.db;
60
61 const defaultKeys = config.category.map(item => {
62 return item + '-key';
63 })
64
65 return (
66 <Menu
67 mode="inline"
68 defaultSelectedKeys={['0']}
69 defaultOpenKeys={defaultKeys}
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