UNPKG

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