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

menu decoupling umi/local

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