This commit is contained in:
13
layouts/Permissions/index.js
Normal file
13
layouts/Permissions/index.js
Normal file
@ -0,0 +1,13 @@
|
||||
import permissions from './permissions'
|
||||
|
||||
const install = function (Vue) {
|
||||
Vue.directive('permissions', permissions)
|
||||
}
|
||||
|
||||
if (window.Vue) {
|
||||
window['permissions'] = permissions
|
||||
Vue.use(install)
|
||||
}
|
||||
|
||||
permissions.install = install
|
||||
export default permissions
|
||||
13
layouts/Permissions/permissions.js
Normal file
13
layouts/Permissions/permissions.js
Normal file
@ -0,0 +1,13 @@
|
||||
import store from '@/store'
|
||||
|
||||
export default {
|
||||
inserted(element, binding) {
|
||||
const { value } = binding
|
||||
const permissions = store.getters['user/permissions']
|
||||
if (value && value instanceof Array && value.length > 0) {
|
||||
const hasPermission = permissions.some((role) => value.includes(role))
|
||||
if (!hasPermission)
|
||||
element.parentNode && element.parentNode.removeChild(element)
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user