Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
admin-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pleroma
admin-fe
Commits
1072572a
Commit
1072572a
authored
7 years ago
by
孙晨光
Committed by
花裤衩
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
update: 递归过滤异步路由表
parent
046d1369
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/store/modules/permission.js
+26
-17
26 additions, 17 deletions
src/store/modules/permission.js
with
26 additions
and
17 deletions
src/store/modules/permission.js
+
26
−
17
View file @
1072572a
...
...
@@ -8,6 +8,26 @@ function hasPermission(roles, route) {
}
}
/**
* 递归过滤异步路由表,返回符合用户角色权限的路由表
* @param asyncRouterMap
* @param roles
* @returns {Array.<T>|*}
*/
function
filterAsyncRouter
(
asyncRouterMap
,
roles
)
{
let
accessedRouters
=
asyncRouterMap
.
filter
(
route
=>
{
if
(
hasPermission
(
roles
,
route
))
{
if
(
route
.
children
&&
route
.
children
.
length
)
{
route
.
children
=
filterAsyncRouter
(
route
.
children
,
roles
)
}
return
true
}
return
false
})
return
accessedRouters
}
const
permission
=
{
state
:
{
routers
:
constantRouterMap
,
...
...
@@ -25,23 +45,12 @@ const permission = {
GenerateRoutes
({
commit
},
data
)
{
return
new
Promise
(
resolve
=>
{
const
{
roles
}
=
data
;
const
accessedRouters
=
asyncRouterMap
.
filter
(
v
=>
{
if
(
roles
.
indexOf
(
'
admin
'
)
>=
0
)
return
true
;
if
(
hasPermission
(
roles
,
v
))
{
if
(
v
.
children
&&
v
.
children
.
length
>
0
)
{
v
.
children
=
v
.
children
.
filter
(
child
=>
{
if
(
hasPermission
(
roles
,
child
))
{
return
child
}
return
false
;
});
return
v
}
else
{
return
v
}
}
return
false
;
});
let
accessedRouters
if
(
roles
.
indexOf
(
'
admin
'
)
>=
0
)
{
accessedRouters
=
asyncRouterMap
}
else
{
accessedRouters
=
filterAsyncRouter
(
asyncRouterMap
,
roles
)
}
commit
(
'
SET_ROUTERS
'
,
accessedRouters
);
resolve
();
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment