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
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Sean King
admin-fe
Commits
03691739
Commit
03691739
authored
6 years ago
by
Pan
Browse files
Options
Downloads
Patches
Plain Diff
add:[permission]: add checkPermission function
parent
3f479664
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/utils/permission.js
+26
-0
26 additions, 0 deletions
src/utils/permission.js
src/views/permission/directive.vue
+13
-0
13 additions, 0 deletions
src/views/permission/directive.vue
with
39 additions
and
0 deletions
src/utils/permission.js
0 → 100644
+
26
−
0
View file @
03691739
import
store
from
'
@/store
'
/**
* @param {Array} value
* @returns {Boolean}
* @example see @/views/permission/directive.vue
*/
export
default
function
checkPermission
(
value
)
{
if
(
value
&&
value
instanceof
Array
&&
value
.
length
>
0
)
{
const
roles
=
store
.
getters
&&
store
.
getters
.
roles
const
permissionRoles
=
value
const
hasPermission
=
roles
.
some
(
role
=>
{
return
permissionRoles
.
includes
(
role
)
})
if
(
!
hasPermission
)
{
return
false
}
return
true
}
else
{
console
.
error
(
`need roles! Like v-permission="['admin','editor']"`
)
return
false
}
}
This diff is collapsed.
Click to expand it.
src/views/permission/directive.vue
+
13
−
0
View file @
03691739
...
...
@@ -16,11 +16,23 @@
<el-tag
class=
"permission-tag"
size=
"small"
>
editor
</el-tag>
can see this
</span>
</div>
<div
style=
"margin-top:30px;"
:key=
"'checkPermission'+key"
>
<code>
In some cases it is not suitable to use v-permission, such as element Tab component which can only be achieved by manually setting the v-if.
<br>
e.g.
</code>
<el-tabs
type=
"border-card"
style=
"width:500px;"
>
<el-tab-pane
v-if=
"checkPermission(['admin'])"
label=
"Admin"
>
Admin can see this
</el-tab-pane>
<el-tab-pane
v-if=
"checkPermission(['editor'])"
label=
"Editor"
>
Editor can see this
</el-tab-pane>
<el-tab-pane
v-if=
"checkPermission(['admin','editor'])"
label=
"Admin-OR-Editor"
>
Both admin or editor can see this
</el-tab-pane>
</el-tabs>
</div>
</div>
</
template
>
<
script
>
import
permission
from
'
@/directive/permission/index.js
'
// 权限判断指令
import
checkPermission
from
'
@/utils/permission
'
// 权限判断函数
import
SwitchRoles
from
'
./components/SwitchRoles
'
export
default
{
...
...
@@ -33,6 +45,7 @@ export default{
}
},
methods
:
{
checkPermission
,
handleRolesChange
()
{
this
.
key
++
}
...
...
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