血透系统PC前端

permission.js 605B

123456789101112131415161718192021222324252627
  1. import store from '@/store'
  2. /**
  3. * @param {Array} value
  4. * @returns {Boolean}
  5. * @example see @/views/permission/directive.vue
  6. */
  7. export default function checkPermission(value) {
  8. if (value && value instanceof Array && value.length > 0) {
  9. const roles = store.getters && store.getters.roles
  10. const permissionRoles = value
  11. const hasPermission = roles.some(role => {
  12. return permissionRoles.includes(role)
  13. })
  14. if (!hasPermission) {
  15. return false
  16. }
  17. return true
  18. } else {
  19. console.error(`need roles! Like v-permission="['admin','editor']"`)
  20. return false
  21. }
  22. }