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
P
pro-blocks
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
pro-blocks
Commits
15b499dc
Commit
15b499dc
authored
Nov 22, 2018
by
Wei Zhu
Committed by
陈帅
Nov 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use a properer method name for menu data (#2937)
parent
ad33da59
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
9 deletions
+8
-9
src/layouts/BasicLayout.js
src/layouts/BasicLayout.js
+8
-9
No files found.
src/layouts/BasicLayout.js
View file @
15b499dc
...
@@ -20,9 +20,8 @@ import Exception403 from '../pages/Exception/403';
...
@@ -20,9 +20,8 @@ import Exception403 from '../pages/Exception/403';
const
{
Content
}
=
Layout
;
const
{
Content
}
=
Layout
;
// Conversion router to menu.
function
mapRoutesToMenu
(
routes
,
parentAuthority
,
parentName
)
{
function
formatter
(
data
,
parentAuthority
,
parentName
)
{
return
routes
return
data
.
map
(
item
=>
{
.
map
(
item
=>
{
if
(
!
item
.
name
||
!
item
.
path
)
{
if
(
!
item
.
name
||
!
item
.
path
)
{
return
null
;
return
null
;
...
@@ -42,7 +41,7 @@ function formatter(data, parentAuthority, parentName) {
...
@@ -42,7 +41,7 @@ function formatter(data, parentAuthority, parentName) {
authority
:
item
.
authority
||
parentAuthority
,
authority
:
item
.
authority
||
parentAuthority
,
};
};
if
(
item
.
routes
)
{
if
(
item
.
routes
)
{
const
children
=
formatter
(
item
.
routes
,
item
.
authority
,
locale
);
const
children
=
mapRoutesToMenu
(
item
.
routes
,
item
.
authority
,
locale
);
// Reduce memory usage
// Reduce memory usage
result
.
children
=
children
;
result
.
children
=
children
;
}
}
...
@@ -52,7 +51,7 @@ function formatter(data, parentAuthority, parentName) {
...
@@ -52,7 +51,7 @@ function formatter(data, parentAuthority, parentName) {
.
filter
(
item
=>
item
);
.
filter
(
item
=>
item
);
}
}
const
memoize
OneFormatter
=
memoizeOne
(
formatter
,
isEqual
);
const
memoize
dMapRoutesToMenu
=
memoizeOne
(
mapRoutesToMenu
,
isEqual
);
const
query
=
{
const
query
=
{
'
screen-xs
'
:
{
'
screen-xs
'
:
{
...
@@ -145,7 +144,7 @@ class BasicLayout extends React.PureComponent {
...
@@ -145,7 +144,7 @@ class BasicLayout extends React.PureComponent {
const
{
const
{
route
:
{
routes
,
authority
},
route
:
{
routes
,
authority
},
}
=
this
.
props
;
}
=
this
.
props
;
return
memoize
OneFormatter
(
routes
,
authority
);
return
memoize
dMapRoutesToMenu
(
routes
,
authority
);
}
}
/**
/**
...
@@ -154,16 +153,16 @@ class BasicLayout extends React.PureComponent {
...
@@ -154,16 +153,16 @@ class BasicLayout extends React.PureComponent {
*/
*/
getBreadcrumbNameMap
()
{
getBreadcrumbNameMap
()
{
const
routerMap
=
{};
const
routerMap
=
{};
const
mergeMenuAndRouter
=
data
=>
{
const
flattenMenuData
=
data
=>
{
data
.
forEach
(
menuItem
=>
{
data
.
forEach
(
menuItem
=>
{
if
(
menuItem
.
children
)
{
if
(
menuItem
.
children
)
{
mergeMenuAndRouter
(
menuItem
.
children
);
flattenMenuData
(
menuItem
.
children
);
}
}
// Reduce memory usage
// Reduce memory usage
routerMap
[
menuItem
.
path
]
=
menuItem
;
routerMap
[
menuItem
.
path
]
=
menuItem
;
});
});
};
};
mergeMenuAndRouter
(
this
.
getMenuData
());
flattenMenuData
(
this
.
getMenuData
());
return
routerMap
;
return
routerMap
;
}
}
...
...
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