UNPKG

1.88 kBJavaScriptView Raw
1import React from 'react';
2import { Layout, Menu, Icon } from 'antd';
3import {
4 BrowserRouter as Router,
5 Route,
6 HashRouter,
7 Link
8} from 'react-router-dom';
9
10const { SubMenu } = Menu;
11const { Sider } = Layout;
12
13import PubSub from 'pubsub-js';
14
15import {Router, Route, Link, browserHistory, hashHistory, IndexRoute} from 'react-router';
16
17export default class SiderView extends React.Component {
18
19 constructor(props) {
20 super(props);
21 }
22
23 $renderItem(db) {
24
25 const{md, config} = db;
26
27 const res = [];
28
29 const category = config.category.slice();
30
31 category.forEach((cg, i) => {
32 const list = md[cg];
33 const items = list.map((item, i) => {
34 return <Menu.Item key={item.page}>{item.page}</Menu.Item>
35 });
36
37 res.push((
38 <SubMenu key={cg + '-key'} title={cg}>
39 {items}
40 </SubMenu>
41 ));
42 });
43 return res;
44 }
45
46 componentDidMount() {
47 const{md, config} =this.props.db;
48 const cg = config.category[0];
49 if(cg) PubSub.publish('SET_PAGE', md[cg][0].page);
50 }
51
52 handleMenuClick({item, key, keyPath}) {
53 // console.log(item, key);
54 PubSub.publish('SET_PAGE', key);
55 }
56
57 render() {
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 </Menu>
76 )
77 }
78}
\No newline at end of file