parent
77c9fb958e
commit
86a6c31b60
23 changed files with 167 additions and 98 deletions
@ -0,0 +1,27 @@ |
||||
/** |
||||
* @description 鉴权指令 |
||||
* 当传入的权限当前用户没有时,会移除该组件 |
||||
* 用例:<Tag v-auth>text</Tag> 或者:<Tag v-auth="'user:编辑'">text</Tag> |
||||
* */ |
||||
import store from '@/store' |
||||
|
||||
export default { |
||||
inserted (el, binding, vnode) { |
||||
let btnText = '' |
||||
// 如果有传值,就取传的值,否则,就取页面路由和按钮名字拼接起来
|
||||
if(binding.value){ |
||||
btnText = binding.value |
||||
}else{ |
||||
btnText = `${vnode.context.$route.path}:${el.innerText}` |
||||
} |
||||
const btnPermissions = store.state.btns |
||||
console.log("🚀 ~ file: index.js ~ line 18 ~ inserted ~ btnPermissions", btnPermissions, btnText) |
||||
if (btnText && btnPermissions && btnPermissions.length) { |
||||
const isPermission = btnPermissions.includes(btnText) |
||||
// 如果按钮集合里没有该权限,就把该按钮给去除
|
||||
if (!isPermission) { |
||||
el.parentNode && el.parentNode.removeChild(el) |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
/** |
||||
* 插件 |
||||
* */ |
||||
|
||||
import directiveAuth from './auth' |
||||
|
||||
export default { |
||||
async install (Vue) { |
||||
// 指令
|
||||
Vue.directive('auth', directiveAuth) |
||||
} |
||||
} |
Loading…
Reference in new issue