From 93cc3870853a9e44df832b6812c754a4144f08ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Sun, 17 Jun 2018 17:06:15 +0800 Subject: [PATCH] optimize menu --- src/common/menu.js | 7 +++++-- src/components/SiderMenu/BaseMenu.js | 14 ++++++-------- src/components/SiderMenu/SliderMenu.js | 9 ++++----- src/locale/en-US.js | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/common/menu.js b/src/common/menu.js index 82939073..fc6ae8cc 100644 --- a/src/common/menu.js +++ b/src/common/menu.js @@ -371,19 +371,22 @@ const menuData = [ }, ]; -function formatter(data, parentPath = '/', parentAuthority) { +function formatter(data, parentPath = '/', parentAuthority, parentName) { return data.map(item => { let { path } = item; + const id = parentName ? `${parentName}.${item.name}` : `menu.${item.name}`; + if (!isUrl(path)) { path = parentPath + item.path; } const result = { ...item, path, + locale: id, authority: item.authority || parentAuthority, }; if (item.children) { - result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority); + result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority, id); } return result; }); diff --git a/src/components/SiderMenu/BaseMenu.js b/src/components/SiderMenu/BaseMenu.js index fb86f765..5539f49d 100644 --- a/src/components/SiderMenu/BaseMenu.js +++ b/src/components/SiderMenu/BaseMenu.js @@ -79,10 +79,9 @@ export default class BaseMenu extends PureComponent { /** * get SubMenu or Item */ - getSubMenuOrItem = (item, parent) => { - const id = parent ? `${parent}.${item.name}` : `menu.${item.name}`; + getSubMenuOrItem = item => { if (item.children && item.children.some(child => child.name)) { - const name = ; + const name = ; return ( - {this.getNavMenuItems(item.children, id)} + {this.getNavMenuItems(item.children)} ); } else { - return {this.getMenuItemPath(item, parent)}; + return {this.getMenuItemPath(item)}; } }; @@ -110,9 +109,8 @@ export default class BaseMenu extends PureComponent { * Judge whether it is http link.return a or Link * @memberof SiderMenu */ - getMenuItemPath = (item, parent) => { - const id = parent ? `${parent}.${item.name}` : `menu.${item.name}`; - const name = ; + getMenuItemPath = item => { + const name = ; const itemPath = this.conversionPath(item.path); const icon = getIcon(item.icon); const { target } = item; diff --git a/src/components/SiderMenu/SliderMenu.js b/src/components/SiderMenu/SliderMenu.js index 5dc9eb60..cee42b13 100644 --- a/src/components/SiderMenu/SliderMenu.js +++ b/src/components/SiderMenu/SliderMenu.js @@ -105,17 +105,16 @@ export default class SiderMenu extends PureComponent { * @memberof SiderMenu */ getMenuItemPath = item => { - console.log(item); const itemPath = this.conversionPath(item.path); const icon = getIcon(item.icon); - const { target, name } = item; + const { target, name, locale } = item; // Is it a http link if (/^https?:\/\//.test(itemPath)) { return ( {icon} - + ); @@ -136,7 +135,7 @@ export default class SiderMenu extends PureComponent { > {icon} - + ); @@ -159,7 +158,7 @@ export default class SiderMenu extends PureComponent { {item.name} ) : ( - item.name + ) } key={item.path} diff --git a/src/locale/en-US.js b/src/locale/en-US.js index aecec5c9..3a22caf6 100644 --- a/src/locale/en-US.js +++ b/src/locale/en-US.js @@ -7,7 +7,7 @@ export default { data: appLocaleData, antd: antdEn, messages: { - 'menu.home': 'home', + 'menu.home': 'Home', 'menu.dashboard': 'Dashboard', 'menu.dashboard.analysis': 'Analysis', 'menu.dashboard.monitor': 'Monitor', -- GitLab