Commit 94207918 authored by afc163's avatar afc163 Committed by ๅๅณ

use this.props.routes replace import config

parent 9b3ad051
...@@ -23,7 +23,7 @@ const getIcon = icon => { ...@@ -23,7 +23,7 @@ const getIcon = icon => {
}; };
export const getMenuMatches = (flatMenuKeys, path) => export const getMenuMatches = (flatMenuKeys, path) =>
flatMenuKeys.filter(item => pathToRegexp(item).test(path)); flatMenuKeys.filter(item => item && pathToRegexp(item).test(path));
export default class BaseMenu extends PureComponent { export default class BaseMenu extends PureComponent {
constructor(props) { constructor(props) {
......
...@@ -16,8 +16,6 @@ import logo from '../assets/logo.svg'; ...@@ -16,8 +16,6 @@ import logo from '../assets/logo.svg';
import Footer from './Footer'; import Footer from './Footer';
import Header from './Header'; import Header from './Header';
import Context from './MenuContext'; import Context from './MenuContext';
// TODO: should use this.props.routes
import routerConfig from '../../config/router.config';
const { Content } = Layout; const { Content } = Layout;
const { check } = Authorized; const { check } = Authorized;
...@@ -48,28 +46,6 @@ function formatter(data, parentPath = '', parentAuthority, parentName) { ...@@ -48,28 +46,6 @@ function formatter(data, parentPath = '', parentAuthority, parentName) {
}); });
} }
// get menu map data
const menuData = formatter(routerConfig[1].routes);
/**
* ่Žทๅ–้ขๅŒ…ๅฑ‘ๆ˜ ๅฐ„
* @param {Object} menuData ่œๅ•้…็ฝฎ
*/
const getBreadcrumbNameMap = memoizeOne(menu => {
const routerMap = {};
const mergeMenuAndRouter = data => {
data.forEach(menuItem => {
if (menuItem.children) {
mergeMenuAndRouter(menuItem.children);
}
// Reduce memory usage
routerMap[menuItem.path] = menuItem;
});
};
mergeMenuAndRouter(menu);
return routerMap;
}, isEqual);
const query = { const query = {
'screen-xs': { 'screen-xs': {
maxWidth: 575, maxWidth: 575,
...@@ -99,8 +75,8 @@ class BasicLayout extends React.PureComponent { ...@@ -99,8 +75,8 @@ class BasicLayout extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.getPageTitle = memoizeOne(this.getPageTitle); this.getPageTitle = memoizeOne(this.getPageTitle);
// Because there are many places to be. So put it here this.getBreadcrumbNameMap = memoizeOne(this.getBreadcrumbNameMap, isEqual);
this.breadcrumbNameMap = getBreadcrumbNameMap(menuData); this.breadcrumbNameMap = this.getBreadcrumbNameMap();
} }
state = { state = {
...@@ -132,7 +108,7 @@ class BasicLayout extends React.PureComponent { ...@@ -132,7 +108,7 @@ class BasicLayout extends React.PureComponent {
} }
componentDidUpdate() { componentDidUpdate() {
this.breadcrumbNameMap = getBreadcrumbNameMap(menuData); this.breadcrumbNameMap = this.getBreadcrumbNameMap();
} }
componentWillUnmount() { componentWillUnmount() {
...@@ -148,6 +124,32 @@ class BasicLayout extends React.PureComponent { ...@@ -148,6 +124,32 @@ class BasicLayout extends React.PureComponent {
}; };
} }
getMenuData() {
const {
route: { routes },
} = this.props;
return formatter(routes);
}
/**
* ่Žทๅ–้ขๅŒ…ๅฑ‘ๆ˜ ๅฐ„
* @param {Object} menuData ่œๅ•้…็ฝฎ
*/
getBreadcrumbNameMap() {
const routerMap = {};
const mergeMenuAndRouter = data => {
data.forEach(menuItem => {
if (menuItem.children) {
mergeMenuAndRouter(menuItem.children);
}
// Reduce memory usage
routerMap[menuItem.path] = menuItem;
});
};
mergeMenuAndRouter(this.getMenuData());
return routerMap;
}
getPageTitle = pathname => { getPageTitle = pathname => {
let currRouterData = null; let currRouterData = null;
// match params path // match params path
...@@ -230,7 +232,7 @@ class BasicLayout extends React.PureComponent { ...@@ -230,7 +232,7 @@ class BasicLayout extends React.PureComponent {
Authorized={Authorized} Authorized={Authorized}
theme={silderTheme} theme={silderTheme}
onCollapse={this.handleMenuCollapse} onCollapse={this.handleMenuCollapse}
menuData={menuData} menuData={this.getMenuData()}
{...this.props} {...this.props}
/> />
)} )}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment