index.js 479 B

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