auth.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. /**
  11. * @description 鉴权指令
  12. * 当传入的权限当前用户没有时,会移除该组件
  13. * 用例:<Tag v-auth="['admin']">text</Tag>
  14. * */
  15. import store from '@/store';
  16. import { includeArray } from '@/libs/auth';
  17. export default {
  18. inserted(el, binding, vnode) {
  19. const { value } = binding;
  20. const access = store.state.userInfo.access;
  21. if (value && value instanceof Array && value.length && access && access.length) {
  22. const isPermission = includeArray(value, access);
  23. if (!isPermission) {
  24. // el.parentNode && el.parentNode.removeChild(el);
  25. }
  26. }
  27. },
  28. };