Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
85d556d3
Commit
85d556d3
authored
Oct 04, 2018
by
ιεΈ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move menuData to state
parent
1cdf5662
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
26 deletions
+37
-26
src/components/SiderMenu/BaseMenu.js
src/components/SiderMenu/BaseMenu.js
+2
-2
src/layouts/BasicLayout.js
src/layouts/BasicLayout.js
+35
-24
No files found.
src/components/SiderMenu/BaseMenu.js
View file @
85d556d3
...
...
@@ -80,7 +80,7 @@ export default class BaseMenu extends PureComponent {
getSubMenuOrItem
=
item
=>
{
// doc: add hideChildrenInMenu
if
(
item
.
children
&&
!
item
.
hideChildrenInMenu
&&
item
.
children
.
some
(
child
=>
child
.
name
))
{
const
name
=
formatMessage
({
id
:
item
.
locale
})
;
const
name
=
item
.
locale
?
formatMessage
({
id
:
item
.
locale
})
:
item
.
name
;
return
(
<
SubMenu
title
=
{
...
...
@@ -108,7 +108,7 @@ export default class BaseMenu extends PureComponent {
* @memberof SiderMenu
*/
getMenuItemPath
=
item
=>
{
const
name
=
formatMessage
({
id
:
item
.
locale
})
;
const
name
=
item
.
locale
?
formatMessage
({
id
:
item
.
locale
})
:
item
.
name
;
const
itemPath
=
this
.
conversionPath
(
item
.
path
);
const
icon
=
getIcon
(
item
.
icon
);
const
{
target
}
=
item
;
...
...
src/layouts/BasicLayout.js
View file @
85d556d3
...
...
@@ -22,28 +22,39 @@ const { Content } = Layout;
// Conversion router to menu.
function
formatter
(
data
,
parentPath
=
''
,
parentAuthority
,
parentName
)
{
return
data
.
map
(
item
=>
{
let
locale
=
'
menu
'
;
if
(
parentName
&&
item
.
name
)
{
locale
=
`
${
parentName
}
.
${
item
.
name
}
`
;
}
else
if
(
item
.
name
)
{
locale
=
`menu.
${
item
.
name
}
`
;
}
else
if
(
parentName
)
{
locale
=
parentName
;
}
const
result
=
{
...
item
,
locale
,
authority
:
item
.
authority
||
parentAuthority
,
};
if
(
item
.
routes
)
{
const
children
=
formatter
(
item
.
routes
,
`
${
parentPath
}${
item
.
path
}
/`
,
item
.
authority
,
locale
);
// Reduce memory usage
result
.
children
=
children
;
}
delete
result
.
routes
;
return
result
;
});
return
data
.
map
(
item
=>
{
let
locale
=
'
menu
'
;
if
(
parentName
&&
item
.
name
)
{
locale
=
`
${
parentName
}
.
${
item
.
name
}
`
;
}
else
if
(
item
.
name
)
{
locale
=
`menu.
${
item
.
name
}
`
;
}
else
if
(
parentName
)
{
locale
=
parentName
;
}
if
(
item
.
path
)
{
const
result
=
{
...
item
,
locale
,
authority
:
item
.
authority
||
parentAuthority
,
};
if
(
item
.
routes
)
{
const
children
=
formatter
(
item
.
routes
,
`
${
parentPath
}${
item
.
path
}
/`
,
item
.
authority
,
locale
);
// Reduce memory usage
result
.
children
=
children
;
}
delete
result
.
routes
;
return
result
;
}
return
null
;
})
.
filter
(
item
=>
item
);
}
const
memoizeOneFormatter
=
memoizeOne
(
formatter
,
isEqual
);
...
...
@@ -85,6 +96,7 @@ class BasicLayout extends React.PureComponent {
state
=
{
rendering
:
true
,
isMobile
:
false
,
menuData
:
this
.
getMenuData
(),
};
componentDidMount
()
{
...
...
@@ -224,9 +236,8 @@ class BasicLayout extends React.PureComponent {
children
,
location
:
{
pathname
},
}
=
this
.
props
;
const
{
isMobile
}
=
this
.
state
;
const
{
isMobile
,
menuData
}
=
this
.
state
;
const
isTop
=
PropsLayout
===
'
topmenu
'
;
const
menuData
=
this
.
getMenuData
();
const
routerConfig
=
this
.
matchParamsPath
(
pathname
);
const
layout
=
(
<
Layout
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment