Commit 4caebc00 authored by 陈帅's avatar 陈帅

add meun Intl

parent 663e34ab
...@@ -202,15 +202,15 @@ const menuData = [ ...@@ -202,15 +202,15 @@ const menuData = [
path: 'dashboard', path: 'dashboard',
children: [ children: [
{ {
name: '分析页', name: 'analysis',
path: 'analysis', path: 'analysis',
}, },
{ {
name: '监控页', name: 'monitor',
path: 'monitor', path: 'monitor',
}, },
{ {
name: '工作台', name: 'workplace',
path: 'workplace', path: 'workplace',
// hideInBreadcrumb: true, // hideInBreadcrumb: true,
// hideInMenu: true, // hideInMenu: true,
...@@ -218,56 +218,61 @@ const menuData = [ ...@@ -218,56 +218,61 @@ const menuData = [
], ],
}, },
{ {
name: '表单页', name: 'form',
icon: 'form', icon: 'form',
path: 'form', path: 'form',
children: [ children: [
{ {
name: '基础表单', name: 'basicform',
path: 'basic-form', path: 'basic-form',
}, },
{ {
name: '分步表单', name: 'stepform',
path: 'step-form', path: 'step-form',
}, },
{ {
<<<<<<< HEAD
name: '高级表单', name: '高级表单',
// authority: 'admin', // authority: 'admin',
=======
name: 'advancedform',
authority: 'admin',
>>>>>>> add meun Intl
path: 'advanced-form', path: 'advanced-form',
}, },
], ],
}, },
{ {
name: '列表页', name: 'list',
icon: 'table', icon: 'table',
path: 'list', path: 'list',
children: [ children: [
{ {
name: '查询表格', name: 'searchlist',
path: 'table-list', path: 'table-list',
}, },
{ {
name: '标准列表', name: 'basiclist',
path: 'basic-list', path: 'basic-list',
}, },
{ {
name: '卡片列表', name: 'cardlist',
path: 'card-list', path: 'card-list',
}, },
{ {
name: '搜索列表', name: 'searchlist',
path: 'search', path: 'search',
children: [ children: [
{ {
name: '搜索列表(文章)', name: 'articles',
path: 'articles', path: 'articles',
}, },
{ {
name: '搜索列表(项目)', name: 'projects',
path: 'projects', path: 'projects',
}, },
{ {
name: '搜索列表(应用)', name: 'applications',
path: 'applications', path: 'applications',
}, },
], ],
...@@ -275,91 +280,91 @@ const menuData = [ ...@@ -275,91 +280,91 @@ const menuData = [
], ],
}, },
{ {
name: '详情页', name: 'profile',
icon: 'profile', icon: 'profile',
path: 'profile', path: 'profile',
children: [ children: [
{ {
name: '基础详情页', name: 'basic',
path: 'basic', path: 'basic',
}, },
{ {
name: '高级详情页', name: 'advanced',
path: 'advanced', path: 'advanced',
// authority: 'admin', // authority: 'admin',
}, },
], ],
}, },
{ {
name: '结果页', name: 'result',
icon: 'check-circle-o', icon: 'check-circle-o',
path: 'result', path: 'result',
children: [ children: [
{ {
name: '成功', name: 'success',
path: 'success', path: 'success',
}, },
{ {
name: '失败', name: 'fail',
path: 'fail', path: 'fail',
}, },
], ],
}, },
{ {
name: '异常页', name: 'exception',
icon: 'warning', icon: 'warning',
path: 'exception', path: 'exception',
children: [ children: [
{ {
name: '403', name: 'not-permission',
path: '403', path: '403',
}, },
{ {
name: '404', name: 'not-find',
path: '404', path: '404',
}, },
{ {
name: '500', name: 'server-error',
path: '500', path: '500',
}, },
// { {
// name: '触发异常', name: 'trigger',
// path: 'triggerException', path: 'trigger',
// hideInMenu: true, hideInMenu: true,
// }, },
], ],
}, },
{ {
name: '账户', name: 'user',
icon: 'user', icon: 'user',
path: 'User', path: 'User',
authority: 'guest', authority: 'guest',
children: [ children: [
{ {
name: '登录', name: 'login',
path: 'login', path: 'login',
}, },
{ {
name: '注册', name: 'register',
path: 'register', path: 'register',
}, },
{ {
name: '注册结果', name: 'register-result',
path: 'register-result', path: 'register-result',
}, },
], ],
}, },
{ {
name: '个人页', name: 'account',
icon: 'user', icon: 'user',
path: 'account', path: 'account',
children: [ children: [
{ {
name: '个人中心', name: 'center',
path: 'center', path: 'center',
}, },
{ {
name: '个人设置', name: 'settings',
path: 'settings', path: 'settings',
}, },
], ],
......
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { Menu, Icon } from 'antd'; import { Menu, Icon } from 'antd';
import { Link } from 'dva/router'; import { Link } from 'dva/router';
import { FormattedMessage } from 'react-intl';
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';
...@@ -53,7 +54,7 @@ export default class BaseMenu extends PureComponent { ...@@ -53,7 +54,7 @@ export default class BaseMenu extends PureComponent {
* 获得菜单子节点 * 获得菜单子节点
* @memberof SiderMenu * @memberof SiderMenu
*/ */
getNavMenuItems = menusData => { getNavMenuItems = (menusData, parent) => {
if (!menusData) { if (!menusData) {
return []; return [];
} }
...@@ -61,7 +62,7 @@ export default class BaseMenu extends PureComponent { ...@@ -61,7 +62,7 @@ export default class BaseMenu extends PureComponent {
.filter(item => item.name && !item.hideInMenu) .filter(item => item.name && !item.hideInMenu)
.map(item => { .map(item => {
// make dom // make dom
const ItemDom = this.getSubMenuOrItem(item); const ItemDom = this.getSubMenuOrItem(item, parent);
return this.checkPermissionItem(item.authority, ItemDom); return this.checkPermissionItem(item.authority, ItemDom);
}) })
.filter(item => item); .filter(item => item);
...@@ -78,27 +79,29 @@ export default class BaseMenu extends PureComponent { ...@@ -78,27 +79,29 @@ export default class BaseMenu extends PureComponent {
/** /**
* get SubMenu or Item * 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)) { if (item.children && item.children.some(child => child.name)) {
const name = <FormattedMessage defaultMessage={item.name} id={id} />;
return ( return (
<SubMenu <SubMenu
title={ title={
item.icon ? ( item.icon ? (
<span> <span>
{getIcon(item.icon)} {getIcon(item.icon)}
<span>{item.name}</span> <span>{name}</span>
</span> </span>
) : ( ) : (
item.name name
) )
} }
key={item.path} key={item.path}
> >
{this.getNavMenuItems(item.children)} {this.getNavMenuItems(item.children, id)}
</SubMenu> </SubMenu>
); );
} else { } else {
return <Menu.Item key={item.path}>{this.getMenuItemPath(item)}</Menu.Item>; return <Menu.Item key={item.path}>{this.getMenuItemPath(item, parent)}</Menu.Item>;
} }
}; };
...@@ -107,10 +110,12 @@ export default class BaseMenu extends PureComponent { ...@@ -107,10 +110,12 @@ export default class BaseMenu extends PureComponent {
* Judge whether it is http link.return a or Link * Judge whether it is http link.return a or Link
* @memberof SiderMenu * @memberof SiderMenu
*/ */
getMenuItemPath = item => { getMenuItemPath = (item, parent) => {
const id = parent ? `${parent}.${item.name}` : `menu.${item.name}`;
const name = <FormattedMessage defaultMessage={item.name} id={id} />;
const itemPath = this.conversionPath(item.path); const itemPath = this.conversionPath(item.path);
const icon = getIcon(item.icon); const icon = getIcon(item.icon);
const { target, name } = item; const { target } = item;
// Is it a http link // Is it a http link
if (/^https?:\/\//.test(itemPath)) { if (/^https?:\/\//.test(itemPath)) {
return ( return (
......
...@@ -2,6 +2,7 @@ import React, { PureComponent } from 'react'; ...@@ -2,6 +2,7 @@ import React, { PureComponent } from 'react';
import { Layout, Menu, Icon } from 'antd'; import { Layout, Menu, Icon } from 'antd';
import pathToRegexp from 'path-to-regexp'; import pathToRegexp from 'path-to-regexp';
import { Link } from 'dva/router'; import { Link } from 'dva/router';
import { FormattedMessage } from 'react-intl';
import styles from './index.less'; import styles from './index.less';
import BaseMenu, { getMenuMatches } from './BaseMenu'; import BaseMenu, { getMenuMatches } from './BaseMenu';
import { urlToList } from '../_utils/pathTools'; import { urlToList } from '../_utils/pathTools';
...@@ -104,6 +105,7 @@ export default class SiderMenu extends PureComponent { ...@@ -104,6 +105,7 @@ export default class SiderMenu extends PureComponent {
* @memberof SiderMenu * @memberof SiderMenu
*/ */
getMenuItemPath = item => { getMenuItemPath = item => {
console.log(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, name } = item; const { target, name } = item;
...@@ -112,7 +114,9 @@ export default class SiderMenu extends PureComponent { ...@@ -112,7 +114,9 @@ export default class SiderMenu extends PureComponent {
return ( return (
<a href={itemPath} target={target}> <a href={itemPath} target={target}>
{icon} {icon}
<span>{name}</span> <span>
<FormattedMessage id={name} />
</span>
</a> </a>
); );
} }
...@@ -131,7 +135,9 @@ export default class SiderMenu extends PureComponent { ...@@ -131,7 +135,9 @@ export default class SiderMenu extends PureComponent {
} }
> >
{icon} {icon}
<span>{name}</span> <span>
<FormattedMessage id={name} />
</span>
</Link> </Link>
); );
}; };
......
...@@ -9,6 +9,7 @@ export default { ...@@ -9,6 +9,7 @@ export default {
messages: { messages: {
'app.home.introduce': 'introduce', 'app.home.introduce': 'introduce',
'app.analysis.test': 'Gongzhuan road No.{no} shop', 'app.analysis.test': 'Gongzhuan road No.{no} shop',
// ...enMessages, // ...enMessages,
}, },
}; };
...@@ -9,6 +9,35 @@ export default { ...@@ -9,6 +9,35 @@ export default {
messages: { messages: {
'app.home.introduce': '介绍', 'app.home.introduce': '介绍',
'app.analysis.test': '工专路 {no} 号店', 'app.analysis.test': '工专路 {no} 号店',
'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, // ...zhMessages,
}, },
}; };
...@@ -12,6 +12,7 @@ import cnLocale from './locale/zh-CN'; ...@@ -12,6 +12,7 @@ import cnLocale from './locale/zh-CN';
const { ConnectedRouter } = routerRedux; const { ConnectedRouter } = routerRedux;
const { AuthorizedRoute } = Authorized; const { AuthorizedRoute } = Authorized;
dynamic.setDefaultLoadingComponent(() => { dynamic.setDefaultLoadingComponent(() => {
return <Spin size="large" className={styles.globalSpin} />; return <Spin size="large" className={styles.globalSpin} />;
}); });
......
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