auth.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2023 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. * 用例:<div v-auth="['admin']">text</div>
  14. * */
  15. import store from '@/store';
  16. import { includeArray } from '@/libs/auth';
  17. export default {
  18. async install(Vue, options) {
  19. Vue.directive('auth', {
  20. inserted(el, binding, vnode) {
  21. // const { value } = binding;
  22. // const access = store.state.userInfo.access;
  23. // if (value && value instanceof Array && value.length && access && access.length) {
  24. // const isPermission = includeArray(value, access);
  25. // if (!isPermission) {
  26. // el.parentNode && el.parentNode.removeChild(el);
  27. // }
  28. // }
  29. },
  30. });
  31. },
  32. };