mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-26 15:54:14 +00:00
Menu supports multiple languages.
This commit is contained in:
+14
-2
@@ -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 = {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
"Switch Theme": "Switch Theme",
|
||||
"Username": "Username",
|
||||
"You have viewed all notifications.": "You have viewed all notifications."
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -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',
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user