import store from '@/store/index'; const importDirective = Vue => { /** * privilege指令 v-privilege="options" * options = { * value: /当前按钮的唯一权限识别/, * } */ Vue.directive('privilege',{ inserted: function (el, binding, vnode) { //el:指令所绑定的元素,可以用来直接操作 DOM。 //binding:一个对象 //vnode:Vue 编译生成的虚拟节点。 // 获取当前路由name // 如果页面为同一模块下的子页面则取最上级权限 let routeName = vnode.context.$route.meta.privilegeExtend ? vnode.context.$route.meta.privilegeExtend : vnode.context.$route.name; // 超级管理员 // if (store.state.user.userLoginInfo.isSuperMan) { // return true; // } // 获取功能点权限 // let functionList = store.state.user.privilegeFunctionPointsMap.get(routeName); // 有权限 // if (functionList && functionList.includes(binding.value)) { //} else { // el.parentNode.removeChild(el); // } } }) }; export default importDirective;