Commit 8b743adb authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

menu decoupling umi/local

parent f473b000
...@@ -3,7 +3,6 @@ import { Menu, Icon } from 'antd'; ...@@ -3,7 +3,6 @@ import { Menu, Icon } from 'antd';
import Link from 'umi/link'; import Link from 'umi/link';
import isEqual from 'lodash/isEqual'; import isEqual from 'lodash/isEqual';
import memoizeOne from 'memoize-one'; import memoizeOne from 'memoize-one';
import { formatMessage } from 'umi/locale';
import pathToRegexp from 'path-to-regexp'; import pathToRegexp from 'path-to-regexp';
import { urlToList } from '../_utils/pathTools'; import { urlToList } from '../_utils/pathTools';
import styles from './index.less'; import styles from './index.less';
...@@ -83,7 +82,7 @@ export default class BaseMenu extends PureComponent { ...@@ -83,7 +82,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 = item.locale ? formatMessage({ id: item.locale }) : item.name; const { name } = item;
return ( return (
<SubMenu <SubMenu
title={ title={
...@@ -111,7 +110,7 @@ export default class BaseMenu extends PureComponent { ...@@ -111,7 +110,7 @@ export default class BaseMenu extends PureComponent {
* @memberof SiderMenu * @memberof SiderMenu
*/ */
getMenuItemPath = item => { getMenuItemPath = item => {
const name = item.locale ? formatMessage({ id: item.locale }) : item.name; const { name } = item;
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;
......
...@@ -24,30 +24,30 @@ const { Content } = Layout; ...@@ -24,30 +24,30 @@ const { Content } = Layout;
function formatter(data, parentAuthority, parentName) { function formatter(data, parentAuthority, parentName) {
return data return data
.map(item => { .map(item => {
if (!item.name || !item.path) {
return null;
}
let locale = 'menu'; let locale = 'menu';
if (parentName && item.name) { if (parentName) {
locale = `${parentName}.${item.name}`; locale = `${parentName}.${item.name}`;
} else if (item.name) { } else {
locale = `menu.${item.name}`; locale = `menu.${item.name}`;
} else if (parentName) {
locale = parentName;
}
if (item.path) {
const result = {
...item,
locale,
authority: item.authority || parentAuthority,
};
if (item.routes) {
const children = formatter(item.routes, item.authority, locale);
// Reduce memory usage
result.children = children;
}
delete result.routes;
return result;
} }
return null; const result = {
...item,
name: formatMessage({ id: locale, defaultMessage: item.name }),
locale,
authority: item.authority || parentAuthority,
};
if (item.routes) {
const children = formatter(item.routes, item.authority, locale);
// Reduce memory usage
result.children = children;
}
delete result.routes;
return result;
}) })
.filter(item => item); .filter(item => item);
} }
......
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