Menu supports multiple languages.

This commit is contained in:
zuiidea
2018-10-16 16:20:48 +08:00
parent c1df88c25f
commit 0b17931c62
5 changed files with 36 additions and 10 deletions
+14 -2
View File
@@ -6,12 +6,14 @@ const database = [
id: '1',
icon: 'dashboard',
name: 'Dashboard',
zhName: '仪表盘',
route: '/dashboard',
},
{
id: '2',
breadcrumbParentId: '1',
name: 'Users',
zhName: '用户管理',
icon: 'user',
route: '/user',
},
@@ -19,6 +21,7 @@ const database = [
id: '7',
breadcrumbParentId: '1',
name: 'Posts',
zhName: '文章管理',
icon: 'shopping-cart',
route: '/post',
},
@@ -27,12 +30,14 @@ const database = [
menuParentId: '-1',
breadcrumbParentId: '2',
name: 'User Detail',
zhName: '用户详情',
route: '/user/:id',
},
{
id: '3',
breadcrumbParentId: '1',
name: 'Request',
zhName: 'Request',
icon: 'api',
route: '/request',
},
@@ -40,6 +45,7 @@ const database = [
id: '4',
breadcrumbParentId: '1',
name: 'UI Element',
zhName: 'UI组件',
icon: 'camera-o',
},
{
@@ -47,6 +53,7 @@ const database = [
breadcrumbParentId: '4',
menuParentId: '4',
name: 'DropOption',
zhName: 'DropOption',
icon: 'bars',
route: '/UIElement/dropOption',
},
@@ -55,6 +62,7 @@ const database = [
breadcrumbParentId: '4',
menuParentId: '4',
name: 'Editor',
zhName: 'Editor',
icon: 'edit',
route: '/UIElement/editor',
},
@@ -62,6 +70,7 @@ const database = [
id: '5',
breadcrumbParentId: '1',
name: 'Charts',
zhName: 'Charts',
icon: 'code-o',
},
{
@@ -69,6 +78,7 @@ const database = [
breadcrumbParentId: '5',
menuParentId: '5',
name: 'ECharts',
zhName: 'ECharts',
icon: 'line-chart',
route: '/chart/ECharts',
},
@@ -76,7 +86,8 @@ const database = [
id: '52',
breadcrumbParentId: '5',
menuParentId: '5',
name: 'highCharts',
name: 'HighCharts',
zhName: 'HighCharts',
icon: 'bar-chart',
route: '/chart/highCharts',
},
@@ -85,9 +96,10 @@ const database = [
breadcrumbParentId: '5',
menuParentId: '5',
name: 'Rechartst',
zhName: 'Rechartst',
icon: 'area-chart',
route: '/chart/Recharts',
}
},
]
module.exports = {
+1 -1
View File
@@ -17,7 +17,7 @@
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
justify-content: center;
padding: 0 24px;
box-shadow: 0 1px 9px -3px rgba(0, 0, 0, 0.2);
.logo {
+16 -4
View File
@@ -8,7 +8,7 @@ import { MyLayout, ScrollBar } from 'components'
import { BackTop, Layout, Drawer } from 'antd'
import { GlobalFooter } from 'ant-design-pro'
import { enquireScreen, unenquireScreen } from 'enquire-js'
import { config, pathMatchRegexp } from 'utils'
import { config, pathMatchRegexp, langFromPath } from 'utils'
import Error from '../pages/404'
import styles from './PrimaryLayout.less'
@@ -57,8 +57,20 @@ class PrimaryLayout extends PureComponent {
const { isMobile } = this.state
const { onCollapseChange } = this
// Localized route name.
const newRouteList =
langFromPath(location.pathname) === 'zh'
? routeList.map(item => {
const { zhName, ...other } = item
return {
...other,
name: zhName,
}
})
: routeList
// Find a route that matches the pathname.
const currentRoute = routeList.find(
const currentRoute = newRouteList.find(
_ => _.route && pathMatchRegexp(_.route, location.pathname)
)
@@ -68,7 +80,7 @@ class PrimaryLayout extends PureComponent {
: false
// MenuParentId is equal to -1 is not a available menu.
const menus = routeList.filter(_ => _.menuParentId !== '-1')
const menus = newRouteList.filter(_ => _.menuParentId !== '-1')
const headerProps = {
menus,
@@ -129,7 +141,7 @@ class PrimaryLayout extends PureComponent {
>
<Header {...headerProps} />
<Content className={styles.content}>
<Bread routeList={routeList} />
<Bread routeList={newRouteList} />
{hasPermission ? children : <Error />}
</Content>
<BackTop
+1 -1
View File
@@ -12,4 +12,4 @@
"Switch Theme": "Switch Theme",
"Username": "Username",
"You have viewed all notifications.": "You have viewed all notifications."
}
}
+4 -2
View File
@@ -18,9 +18,10 @@ export default {
},
routeList: [
{
id: 1,
id: '1',
icon: 'laptop',
name: 'Dashboard',
zhName: '仪表盘',
router: '/dashboard',
},
],
@@ -128,9 +129,10 @@ export default {
permissions: { visit: [] },
menu: [
{
id: 1,
id: '1',
icon: 'laptop',
name: 'Dashboard',
zhName: '仪表盘',
router: '/dashboard',
},
],