Commit 85d556d3 authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

move menuData to state

parent 1cdf5662
...@@ -80,7 +80,7 @@ export default class BaseMenu extends PureComponent { ...@@ -80,7 +80,7 @@ export default class BaseMenu extends PureComponent {
getSubMenuOrItem = item => { getSubMenuOrItem = item => {
// doc: add hideChildrenInMenu // doc: add hideChildrenInMenu
if (item.children && !item.hideChildrenInMenu && item.children.some(child => child.name)) { if (item.children && !item.hideChildrenInMenu && item.children.some(child => child.name)) {
const name = formatMessage({ id: item.locale }); const name = item.locale ? formatMessage({ id: item.locale }) : item.name;
return ( return (
<SubMenu <SubMenu
title={ title={
...@@ -108,7 +108,7 @@ export default class BaseMenu extends PureComponent { ...@@ -108,7 +108,7 @@ export default class BaseMenu extends PureComponent {
* @memberof SiderMenu * @memberof SiderMenu
*/ */
getMenuItemPath = item => { getMenuItemPath = item => {
const name = formatMessage({ id: item.locale }); const name = item.locale ? formatMessage({ id: item.locale }) : item.name;
const itemPath = this.conversionPath(item.path); const itemPath = this.conversionPath(item.path);
const icon = getIcon(item.icon); const icon = getIcon(item.icon);
const { target } = item; const { target } = item;
......
...@@ -22,28 +22,39 @@ const { Content } = Layout; ...@@ -22,28 +22,39 @@ const { Content } = Layout;
// Conversion router to menu. // Conversion router to menu.
function formatter(data, parentPath = '', parentAuthority, parentName) { function formatter(data, parentPath = '', parentAuthority, parentName) {
return data.map(item => { return data
let locale = 'menu'; .map(item => {
if (parentName && item.name) { let locale = 'menu';
locale = `${parentName}.${item.name}`; if (parentName && item.name) {
} else if (item.name) { locale = `${parentName}.${item.name}`;
locale = `menu.${item.name}`; } else if (item.name) {
} else if (parentName) { locale = `menu.${item.name}`;
locale = parentName; } else if (parentName) {
} locale = parentName;
const result = { }
...item, if (item.path) {
locale, const result = {
authority: item.authority || parentAuthority, ...item,
}; locale,
if (item.routes) { authority: item.authority || parentAuthority,
const children = formatter(item.routes, `${parentPath}${item.path}/`, item.authority, locale); };
// Reduce memory usage if (item.routes) {
result.children = children; const children = formatter(
} item.routes,
delete result.routes; `${parentPath}${item.path}/`,
return result; item.authority,
}); locale
);
// Reduce memory usage
result.children = children;
}
delete result.routes;
return result;
}
return null;
})
.filter(item => item);
} }
const memoizeOneFormatter = memoizeOne(formatter, isEqual); const memoizeOneFormatter = memoizeOne(formatter, isEqual);
...@@ -85,6 +96,7 @@ class BasicLayout extends React.PureComponent { ...@@ -85,6 +96,7 @@ class BasicLayout extends React.PureComponent {
state = { state = {
rendering: true, rendering: true,
isMobile: false, isMobile: false,
menuData: this.getMenuData(),
}; };
componentDidMount() { componentDidMount() {
...@@ -224,9 +236,8 @@ class BasicLayout extends React.PureComponent { ...@@ -224,9 +236,8 @@ class BasicLayout extends React.PureComponent {
children, children,
location: { pathname }, location: { pathname },
} = this.props; } = this.props;
const { isMobile } = this.state; const { isMobile, menuData } = this.state;
const isTop = PropsLayout === 'topmenu'; const isTop = PropsLayout === 'topmenu';
const menuData = this.getMenuData();
const routerConfig = this.matchParamsPath(pathname); const routerConfig = this.matchParamsPath(pathname);
const layout = ( const layout = (
<Layout> <Layout>
......
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