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
94207918
Commit
94207918
authored
Aug 29, 2018
by
afc163
Committed by
ๅๅณ
Aug 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use this.props.routes replace import config
parent
9b3ad051
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
29 deletions
+31
-29
src/components/SiderMenu/BaseMenu.js
src/components/SiderMenu/BaseMenu.js
+1
-1
src/layouts/BasicLayout.js
src/layouts/BasicLayout.js
+30
-28
No files found.
src/components/SiderMenu/BaseMenu.js
View file @
94207918
...
@@ -23,7 +23,7 @@ const getIcon = icon => {
...
@@ -23,7 +23,7 @@ const getIcon = icon => {
};
};
export
const
getMenuMatches
=
(
flatMenuKeys
,
path
)
=>
export
const
getMenuMatches
=
(
flatMenuKeys
,
path
)
=>
flatMenuKeys
.
filter
(
item
=>
pathToRegexp
(
item
).
test
(
path
));
flatMenuKeys
.
filter
(
item
=>
item
&&
pathToRegexp
(
item
).
test
(
path
));
export
default
class
BaseMenu
extends
PureComponent
{
export
default
class
BaseMenu
extends
PureComponent
{
constructor
(
props
)
{
constructor
(
props
)
{
...
...
src/layouts/BasicLayout.js
View file @
94207918
...
@@ -16,8 +16,6 @@ import logo from '../assets/logo.svg';
...
@@ -16,8 +16,6 @@ import logo from '../assets/logo.svg';
import
Footer
from
'
./Footer
'
;
import
Footer
from
'
./Footer
'
;
import
Header
from
'
./Header
'
;
import
Header
from
'
./Header
'
;
import
Context
from
'
./MenuContext
'
;
import
Context
from
'
./MenuContext
'
;
// TODO: should use this.props.routes
import
routerConfig
from
'
../../config/router.config
'
;
const
{
Content
}
=
Layout
;
const
{
Content
}
=
Layout
;
const
{
check
}
=
Authorized
;
const
{
check
}
=
Authorized
;
...
@@ -48,28 +46,6 @@ function formatter(data, parentPath = '', parentAuthority, parentName) {
...
@@ -48,28 +46,6 @@ function formatter(data, parentPath = '', parentAuthority, parentName) {
});
});
}
}
// get menu map data
const
menuData
=
formatter
(
routerConfig
[
1
].
routes
);
/**
* ่ทๅ้ขๅ ๅฑๆ ๅฐ
* @param {Object} menuData ่ๅ้ ็ฝฎ
*/
const
getBreadcrumbNameMap
=
memoizeOne
(
menu
=>
{
const
routerMap
=
{};
const
mergeMenuAndRouter
=
data
=>
{
data
.
forEach
(
menuItem
=>
{
if
(
menuItem
.
children
)
{
mergeMenuAndRouter
(
menuItem
.
children
);
}
// Reduce memory usage
routerMap
[
menuItem
.
path
]
=
menuItem
;
});
};
mergeMenuAndRouter
(
menu
);
return
routerMap
;
},
isEqual
);
const
query
=
{
const
query
=
{
'
screen-xs
'
:
{
'
screen-xs
'
:
{
maxWidth
:
575
,
maxWidth
:
575
,
...
@@ -99,8 +75,8 @@ class BasicLayout extends React.PureComponent {
...
@@ -99,8 +75,8 @@ class BasicLayout extends React.PureComponent {
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
getPageTitle
=
memoizeOne
(
this
.
getPageTitle
);
this
.
getPageTitle
=
memoizeOne
(
this
.
getPageTitle
);
// Because there are many places to be. So put it here
this
.
getBreadcrumbNameMap
=
memoizeOne
(
this
.
getBreadcrumbNameMap
,
isEqual
);
this
.
breadcrumbNameMap
=
getBreadcrumbNameMap
(
menuData
);
this
.
breadcrumbNameMap
=
this
.
getBreadcrumbNameMap
(
);
}
}
state
=
{
state
=
{
...
@@ -132,7 +108,7 @@ class BasicLayout extends React.PureComponent {
...
@@ -132,7 +108,7 @@ class BasicLayout extends React.PureComponent {
}
}
componentDidUpdate
()
{
componentDidUpdate
()
{
this
.
breadcrumbNameMap
=
getBreadcrumbNameMap
(
menuData
);
this
.
breadcrumbNameMap
=
this
.
getBreadcrumbNameMap
(
);
}
}
componentWillUnmount
()
{
componentWillUnmount
()
{
...
@@ -148,6 +124,32 @@ class BasicLayout extends React.PureComponent {
...
@@ -148,6 +124,32 @@ class BasicLayout extends React.PureComponent {
};
};
}
}
getMenuData
()
{
const
{
route
:
{
routes
},
}
=
this
.
props
;
return
formatter
(
routes
);
}
/**
* ่ทๅ้ขๅ ๅฑๆ ๅฐ
* @param {Object} menuData ่ๅ้ ็ฝฎ
*/
getBreadcrumbNameMap
()
{
const
routerMap
=
{};
const
mergeMenuAndRouter
=
data
=>
{
data
.
forEach
(
menuItem
=>
{
if
(
menuItem
.
children
)
{
mergeMenuAndRouter
(
menuItem
.
children
);
}
// Reduce memory usage
routerMap
[
menuItem
.
path
]
=
menuItem
;
});
};
mergeMenuAndRouter
(
this
.
getMenuData
());
return
routerMap
;
}
getPageTitle
=
pathname
=>
{
getPageTitle
=
pathname
=>
{
let
currRouterData
=
null
;
let
currRouterData
=
null
;
// match params path
// match params path
...
@@ -230,7 +232,7 @@ class BasicLayout extends React.PureComponent {
...
@@ -230,7 +232,7 @@ class BasicLayout extends React.PureComponent {
Authorized
=
{
Authorized
}
Authorized
=
{
Authorized
}
theme
=
{
silderTheme
}
theme
=
{
silderTheme
}
onCollapse
=
{
this
.
handleMenuCollapse
}
onCollapse
=
{
this
.
handleMenuCollapse
}
menuData
=
{
menuData
}
menuData
=
{
this
.
getMenuData
()
}
{...
this
.
props
}
{...
this
.
props
}
/
>
/
>
)}
)}
...
...
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