12345678910111213141516171819202122232425262728 |
- import Vue from 'vue'
- import store from '@/store'
- /**
- * hasPermission 权限指令
- * 指令用法:
- * - 在需要控制 hasPermission 级别权限的组件上使用 v-hasPermission:[method] , 如下:
- * <i-button v-hasPermission:add >添加用户</a-button>
- * <a-button v-hasPermission:delete>删除用户</a-button>
- * <a v-hasPermission:edit @click="edit(record)">修改</a>
- *
- * - 当前用户没有权限时,组件上使用了该指令则会被隐藏
- * - 当后台权限跟 pro 提供的模式不同时,只需要针对这里的权限过滤进行修改即可
- *
- * @see https://github.com/sendya/ant-design-pro-vue/pull/53
- */
- const hasPermission = Vue.directive('hasPermission', {
- inserted: function (el, binding, vnode) {
- // console.log(binding.value)
- const roles = store.getters.roles
- const permissionList = roles.permissionList
- if (!permissionList.includes(binding.value)) {
- el.parentNode && el.parentNode.removeChild(el) || (el.style.display = 'none')
- }
- }
- })
- export default hasPermission
|