From 4caebc00df9288c96f913b6735ba74cf60ca2150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Sat, 16 Jun 2018 22:44:29 +0800 Subject: [PATCH] add meun Intl --- src/common/menu.js | 77 ++++++++++++++------------ src/components/SiderMenu/BaseMenu.js | 23 +++++--- src/components/SiderMenu/SliderMenu.js | 10 +++- src/locale/en-US.js | 3 +- src/locale/zh-CN.js | 31 ++++++++++- src/router.js | 1 + 6 files changed, 96 insertions(+), 49 deletions(-) diff --git a/src/common/menu.js b/src/common/menu.js index ebb219e4..82939073 100644 --- a/src/common/menu.js +++ b/src/common/menu.js @@ -202,15 +202,15 @@ const menuData = [ path: 'dashboard', children: [ { - name: '分析页', + name: 'analysis', path: 'analysis', }, { - name: '监控页', + name: 'monitor', path: 'monitor', }, { - name: '工作台', + name: 'workplace', path: 'workplace', // hideInBreadcrumb: true, // hideInMenu: true, @@ -218,56 +218,61 @@ const menuData = [ ], }, { - name: '表单页', + name: 'form', icon: 'form', path: 'form', children: [ { - name: '基础表单', + name: 'basicform', path: 'basic-form', }, { - name: '分步表单', + name: 'stepform', path: 'step-form', }, { +<<<<<<< HEAD name: '高级表单', // authority: 'admin', +======= + name: 'advancedform', + authority: 'admin', +>>>>>>> add meun Intl path: 'advanced-form', }, ], }, { - name: '列表页', + name: 'list', icon: 'table', path: 'list', children: [ { - name: '查询表格', + name: 'searchlist', path: 'table-list', }, { - name: '标准列表', + name: 'basiclist', path: 'basic-list', }, { - name: '卡片列表', + name: 'cardlist', path: 'card-list', }, { - name: '搜索列表', + name: 'searchlist', path: 'search', children: [ { - name: '搜索列表(文章)', + name: 'articles', path: 'articles', }, { - name: '搜索列表(项目)', + name: 'projects', path: 'projects', }, { - name: '搜索列表(应用)', + name: 'applications', path: 'applications', }, ], @@ -275,91 +280,91 @@ const menuData = [ ], }, { - name: '详情页', + name: 'profile', icon: 'profile', path: 'profile', children: [ { - name: '基础详情页', + name: 'basic', path: 'basic', }, { - name: '高级详情页', + name: 'advanced', path: 'advanced', // authority: 'admin', }, ], }, { - name: '结果页', + name: 'result', icon: 'check-circle-o', path: 'result', children: [ { - name: '成功', + name: 'success', path: 'success', }, { - name: '失败', + name: 'fail', path: 'fail', }, ], }, { - name: '异常页', + name: 'exception', icon: 'warning', path: 'exception', children: [ { - name: '403', + name: 'not-permission', path: '403', }, { - name: '404', + name: 'not-find', path: '404', }, { - name: '500', + name: 'server-error', path: '500', }, - // { - // name: '触发异常', - // path: 'triggerException', - // hideInMenu: true, - // }, + { + name: 'trigger', + path: 'trigger', + hideInMenu: true, + }, ], }, { - name: '账户', + name: 'user', icon: 'user', path: 'User', authority: 'guest', children: [ { - name: '登录', + name: 'login', path: 'login', }, { - name: '注册', + name: 'register', path: 'register', }, { - name: '注册结果', + name: 'register-result', path: 'register-result', }, ], }, { - name: '个人页', + name: 'account', icon: 'user', path: 'account', children: [ { - name: '个人中心', + name: 'center', path: 'center', }, { - name: '个人设置', + name: 'settings', path: 'settings', }, ], diff --git a/src/components/SiderMenu/BaseMenu.js b/src/components/SiderMenu/BaseMenu.js index bdee72ac..fb86f765 100644 --- a/src/components/SiderMenu/BaseMenu.js +++ b/src/components/SiderMenu/BaseMenu.js @@ -1,6 +1,7 @@ import React, { PureComponent } from 'react'; import { Menu, Icon } from 'antd'; import { Link } from 'dva/router'; +import { FormattedMessage } from 'react-intl'; import pathToRegexp from 'path-to-regexp'; import { urlToList } from '../_utils/pathTools'; import styles from './index.less'; @@ -53,7 +54,7 @@ export default class BaseMenu extends PureComponent { * 获得菜单子节点 * @memberof SiderMenu */ - getNavMenuItems = menusData => { + getNavMenuItems = (menusData, parent) => { if (!menusData) { return []; } @@ -61,7 +62,7 @@ export default class BaseMenu extends PureComponent { .filter(item => item.name && !item.hideInMenu) .map(item => { // make dom - const ItemDom = this.getSubMenuOrItem(item); + const ItemDom = this.getSubMenuOrItem(item, parent); return this.checkPermissionItem(item.authority, ItemDom); }) .filter(item => item); @@ -78,27 +79,29 @@ export default class BaseMenu extends PureComponent { /** * get SubMenu or Item */ - getSubMenuOrItem = item => { + getSubMenuOrItem = (item, parent) => { + const id = parent ? `${parent}.${item.name}` : `menu.${item.name}`; if (item.children && item.children.some(child => child.name)) { + const name = ; return ( {getIcon(item.icon)} - {item.name} + {name} ) : ( - item.name + name ) } key={item.path} > - {this.getNavMenuItems(item.children)} + {this.getNavMenuItems(item.children, id)} ); } else { - return {this.getMenuItemPath(item)}; + return {this.getMenuItemPath(item, parent)}; } }; @@ -107,10 +110,12 @@ export default class BaseMenu extends PureComponent { * Judge whether it is http link.return a or Link * @memberof SiderMenu */ - getMenuItemPath = item => { + getMenuItemPath = (item, parent) => { + const id = parent ? `${parent}.${item.name}` : `menu.${item.name}`; + const name = ; const itemPath = this.conversionPath(item.path); const icon = getIcon(item.icon); - const { target, name } = item; + const { target } = item; // Is it a http link if (/^https?:\/\//.test(itemPath)) { return ( diff --git a/src/components/SiderMenu/SliderMenu.js b/src/components/SiderMenu/SliderMenu.js index 3f61152f..5dc9eb60 100644 --- a/src/components/SiderMenu/SliderMenu.js +++ b/src/components/SiderMenu/SliderMenu.js @@ -2,6 +2,7 @@ import React, { PureComponent } from 'react'; import { Layout, Menu, Icon } from 'antd'; import pathToRegexp from 'path-to-regexp'; import { Link } from 'dva/router'; +import { FormattedMessage } from 'react-intl'; import styles from './index.less'; import BaseMenu, { getMenuMatches } from './BaseMenu'; import { urlToList } from '../_utils/pathTools'; @@ -104,6 +105,7 @@ 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; @@ -112,7 +114,9 @@ export default class SiderMenu extends PureComponent { return ( {icon} - {name} + + + ); } @@ -131,7 +135,9 @@ export default class SiderMenu extends PureComponent { } > {icon} - {name} + + + ); }; diff --git a/src/locale/en-US.js b/src/locale/en-US.js index a87f0531..38af6eab 100644 --- a/src/locale/en-US.js +++ b/src/locale/en-US.js @@ -9,6 +9,7 @@ export default { messages: { 'app.home.introduce': 'introduce', 'app.analysis.test': 'Gongzhuan road No.{no} shop', - // ...enMessages, + + // ...enMessages, }, }; diff --git a/src/locale/zh-CN.js b/src/locale/zh-CN.js index 9f5cb223..b3eb7138 100644 --- a/src/locale/zh-CN.js +++ b/src/locale/zh-CN.js @@ -9,6 +9,35 @@ export default { messages: { 'app.home.introduce': '介绍', 'app.analysis.test': '工专路 {no} 号店', - // ...zhMessages, + 'menu.dashboard': '仪表盘', + 'menu.dashboard.analysis': '分析页', + 'menu.dashboard.monitor': '监控页', + 'menu.dashboard.workplace': '工作台', + 'menu.form': '表单页', + 'menu.form.basicform': '基础表单', + 'menu.form.stepform': '分布表单', + 'menu.form.advancedform': '高级表单', + 'menu.list': '列表页', + 'menu.list.searchlist': '搜索列表', + 'menu.list.basiclist': '标准列表', + 'menu.list.cardlist': '卡片列表', + 'menu.list.searchlist.articles': '搜索列表(文章)', + 'menu.list.searchlist.projects': '搜索列表(项目)', + 'menu.list.searchlist.applications': '搜索列表(列表)', + 'menu.profile': '详情页', + 'menu.profile.basic': '详情页', + 'menu.profile.advanced': '详情页', + 'menu.result': '结果页', + 'menu.result.success': '成功页', + 'menu.result.fail': '成功页', + 'menu.exception': '异常页', + 'menu.exception.not-permission': '403', + 'menu.exception.not-find': '404', + 'menu.exception.server-error': '500', + 'menu.exception.trigger': '触发错误', + 'menu.account': '个人页', + 'menu.account.center': '个人中心', + 'menu.account.settings': '个人设置', + // ...zhMessages, }, }; diff --git a/src/router.js b/src/router.js index 88c83517..8c296afc 100644 --- a/src/router.js +++ b/src/router.js @@ -12,6 +12,7 @@ import cnLocale from './locale/zh-CN'; const { ConnectedRouter } = routerRedux; const { AuthorizedRoute } = Authorized; + dynamic.setDefaultLoadingComponent(() => { return ; }); -- GitLab