index.js 462 B

123456789101112131415161718192021222324
  1. import {
  2. store
  3. } from "@/store/index.js"
  4. const hasRoles = (el, binding) => {
  5. const {
  6. value
  7. } = binding;
  8. const roles = store.userInfo.roles.map(item => item.roleKey);
  9. if (value && value instanceof Array && value.length > 0) {
  10. const hasRole = roles.some(role => {
  11. return value.includes(role)
  12. })
  13. console.log(hasRole);
  14. if (!hasRole) {
  15. el.remove()
  16. }
  17. } else {
  18. throw new Error('请填写当前操作权限值')
  19. }
  20. }
  21. export default hasRoles;