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
8bc421a7
Commit
8bc421a7
authored
Dec 04, 2018
by
陈小聪
Committed by
陈帅
Dec 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐛
fix route noAuthority nowork Close: 2998 (#3052)
parent
29477bb4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
31 deletions
+20
-31
src/layouts/BasicLayout.js
src/layouts/BasicLayout.js
+19
-25
src/models/menu.js
src/models/menu.js
+1
-6
No files found.
src/layouts/BasicLayout.js
View file @
8bc421a7
...
@@ -91,31 +91,27 @@ class BasicLayout extends React.PureComponent {
...
@@ -91,31 +91,27 @@ class BasicLayout extends React.PureComponent {
};
};
}
}
/**
* 获取面包屑映射
* @param {Object} menuData 菜单配置
*/
getBreadcrumbNameMap
()
{
const
routerMap
=
{};
const
{
menuData
}
=
this
.
props
;
const
flattenMenuData
=
data
=>
{
data
.
forEach
(
menuItem
=>
{
if
(
menuItem
.
children
)
{
flattenMenuData
(
menuItem
.
children
);
}
// Reduce memory usage
routerMap
[
menuItem
.
path
]
=
menuItem
;
});
};
flattenMenuData
(
menuData
);
return
routerMap
;
}
matchParamsPath
=
(
pathname
,
breadcrumbNameMap
)
=>
{
matchParamsPath
=
(
pathname
,
breadcrumbNameMap
)
=>
{
const
pathKey
=
Object
.
keys
(
breadcrumbNameMap
).
find
(
key
=>
pathToRegexp
(
key
).
test
(
pathname
));
const
pathKey
=
Object
.
keys
(
breadcrumbNameMap
).
find
(
key
=>
pathToRegexp
(
key
).
test
(
pathname
));
return
breadcrumbNameMap
[
pathKey
];
return
breadcrumbNameMap
[
pathKey
];
};
};
getRouterAuthority
=
(
pathname
,
routeData
)
=>
{
let
routeAuthority
=
[
'
noAuthority
'
];
const
getAuthority
=
(
key
,
routes
)
=>
{
routes
.
map
(
route
=>
{
if
(
route
.
path
===
key
)
{
routeAuthority
=
route
.
authority
;
}
else
if
(
route
.
routes
)
{
routeAuthority
=
getAuthority
(
key
,
route
.
routes
);
}
return
route
;
});
return
routeAuthority
;
};
return
getAuthority
(
pathname
,
routeData
);
};
getPageTitle
=
(
pathname
,
breadcrumbNameMap
)
=>
{
getPageTitle
=
(
pathname
,
breadcrumbNameMap
)
=>
{
const
currRouterData
=
this
.
matchParamsPath
(
pathname
,
breadcrumbNameMap
);
const
currRouterData
=
this
.
matchParamsPath
(
pathname
,
breadcrumbNameMap
);
...
@@ -166,11 +162,12 @@ class BasicLayout extends React.PureComponent {
...
@@ -166,11 +162,12 @@ class BasicLayout extends React.PureComponent {
isMobile
,
isMobile
,
menuData
,
menuData
,
breadcrumbNameMap
,
breadcrumbNameMap
,
route
:
{
routes
},
fixedHeader
,
fixedHeader
,
}
=
this
.
props
;
}
=
this
.
props
;
const
isTop
=
PropsLayout
===
'
topmenu
'
;
const
isTop
=
PropsLayout
===
'
topmenu
'
;
const
routerConfig
=
this
.
matchParamsPath
(
pathname
,
breadcrumbNameMap
);
const
routerConfig
=
this
.
getRouterAuthority
(
pathname
,
routes
);
const
contentStyle
=
!
fixedHeader
?
{
paddingTop
:
0
}
:
{};
const
contentStyle
=
!
fixedHeader
?
{
paddingTop
:
0
}
:
{};
const
layout
=
(
const
layout
=
(
<
Layout
>
<
Layout
>
...
@@ -198,10 +195,7 @@ class BasicLayout extends React.PureComponent {
...
@@ -198,10 +195,7 @@ class BasicLayout extends React.PureComponent {
{...
this
.
props
}
{...
this
.
props
}
/
>
/
>
<
Content
className
=
{
styles
.
content
}
style
=
{
contentStyle
}
>
<
Content
className
=
{
styles
.
content
}
style
=
{
contentStyle
}
>
<
Authorized
<
Authorized
authority
=
{
routerConfig
}
noMatch
=
{
<
Exception403
/>
}
>
authority
=
{
routerConfig
&&
routerConfig
.
authority
}
noMatch
=
{
<
Exception403
/>
}
>
{
children
}
{
children
}
<
/Authorized
>
<
/Authorized
>
<
/Content
>
<
/Content
>
...
...
src/models/menu.js
View file @
8bc421a7
...
@@ -62,12 +62,7 @@ const filterMenuData = menuData => {
...
@@ -62,12 +62,7 @@ const filterMenuData = menuData => {
}
}
return
menuData
return
menuData
.
filter
(
item
=>
item
.
name
&&
!
item
.
hideInMenu
)
.
filter
(
item
=>
item
.
name
&&
!
item
.
hideInMenu
)
.
map
(
item
=>
{
.
map
(
item
=>
check
(
item
.
authority
,
getSubMenu
(
item
)))
// make dom
const
ItemDom
=
getSubMenu
(
item
);
const
data
=
check
(
item
.
authority
,
ItemDom
);
return
data
;
})
.
filter
(
item
=>
item
);
.
filter
(
item
=>
item
);
};
};
/**
/**
...
...
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