Skip to content

Commit c18ae7b

Browse files
authored
增加Action权限验证功能
在所有操作按钮地方增加一个Vue指令 v-action:add add:操作名称 (可以自定义) 在roles的基础上面进行扩展的操作权限验证。判断add是否在 roles.actionList存在来验证是否有次功能的操作权限。
1 parent 8688c8e commit c18ae7b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/permission.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,37 @@ router.beforeEach((to, from, next) => {
6666
router.afterEach(() => {
6767
NProgress.done() // finish progress bar
6868
})
69+
70+
71+
72+
73+
/**Action 权限指令**/
74+
const action = Vue.directive('action', {
75+
bind: function (el, binding, vnode) {
76+
const actionName = binding.arg
77+
const roles = store.getters.roles
78+
const permissionId = vnode.context.$route.meta.permission
79+
let actions = []
80+
roles.permissions.forEach(p => {
81+
if (p.permissionId != permissionId) {
82+
return
83+
}
84+
actions = p.actionList
85+
})
86+
if (actions.indexOf(actionName) < 0) {
87+
setTimeout(() => {
88+
if(el.parentNode == null){
89+
el.style.display = 'none'
90+
}
91+
else{
92+
el.parentNode.removeChild(el)
93+
}
94+
}, 10)
95+
96+
}
97+
}
98+
})
99+
100+
export {
101+
action
102+
}

0 commit comments

Comments
 (0)