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
7549eb80
Commit
7549eb80
authored
7 years ago
by
Pan
Browse files
Options
Downloads
Patches
Plain Diff
fix eslint && refine code
parent
1072572a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/filters/index.js
+1
-4
1 addition, 4 deletions
src/filters/index.js
src/store/modules/permission.js
+16
-16
16 additions, 16 deletions
src/store/modules/permission.js
with
17 additions
and
20 deletions
src/filters/index.js
+
1
−
4
View file @
7549eb80
...
...
@@ -104,8 +104,5 @@ export function html2Text(val) {
export
function
toThousandslsFilter
(
num
)
{
return
(
+
num
||
0
).
toString
()
.
replace
(
/^
\-?\d
+/g
,
function
(
m
)
{
return
m
.
replace
(
/
(?=(?!\b)(\d{3})
+$
)
/g
,
'
,
'
);
});
return
(
+
num
||
0
).
toString
().
replace
(
/^-
?\d
+/g
,
m
=>
m
.
replace
(
/
(?=(?!\b)(\d{3})
+$
)
/g
,
'
,
'
));
}
This diff is collapsed.
Click to expand it.
src/store/modules/permission.js
+
16
−
16
View file @
7549eb80
import
{
asyncRouterMap
,
constantRouterMap
}
from
'
src/router
'
;
/**
* 通过meta.role判断是否与当前用户权限匹配
* @param roles
* @param route
*/
function
hasPermission
(
roles
,
route
)
{
if
(
route
.
meta
&&
route
.
meta
.
role
)
{
return
roles
.
some
(
role
=>
route
.
meta
.
role
.
indexOf
(
role
)
>=
0
)
...
...
@@ -12,39 +17,35 @@ function hasPermission(roles, route) {
* 递归过滤异步路由表,返回符合用户角色权限的路由表
* @param asyncRouterMap
* @param roles
* @returns {Array.<T>|*}
*/
function
filterAsyncRouter
(
asyncRouterMap
,
roles
)
{
le
t
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
cons
t
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
,
addRouters
:
[]
},
mutations
:
{
SET_ROUTERS
:
(
state
,
routers
)
=>
{
state
.
addRouters
=
routers
;
state
.
routers
=
constantRouterMap
.
concat
(
routers
);
}
},
actions
:
{
GenerateRoutes
({
commit
},
data
)
{
return
new
Promise
(
resolve
=>
{
const
{
roles
}
=
data
;
const
{
roles
}
=
data
let
accessedRouters
if
(
roles
.
indexOf
(
'
admin
'
)
>=
0
)
{
accessedRouters
=
asyncRouterMap
...
...
@@ -58,5 +59,4 @@ const permission = {
}
};
export
default
permission
;
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