暫無描述

permission.js 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import router from './router'
  2. import store from './store'
  3. import NProgress from 'nprogress' // Progress 进度条
  4. import 'nprogress/nprogress.css'// Progress 进度条样式
  5. import { Message } from 'element-ui'
  6. import { getToken } from '@/utils/auth' // 验权
  7. const whiteList = ['/login', '/game/round', `/game`] // 不重定向白名单
  8. router.beforeEach((to, from, next) => {
  9. NProgress.start()
  10. if (getToken()) {
  11. if (to.path === '/login') {
  12. next({ path: '/' })
  13. } else {
  14. if (store.getters.roles.length === 0) {
  15. store.dispatch('GetInfo').then(res => { // 拉取用户信息
  16. next()
  17. }).catch(() => {
  18. store.dispatch('FedLogOut').then(() => {
  19. Message.error('验证失败,请重新登录')
  20. next({ path: '/login' })
  21. })
  22. })
  23. } else {
  24. next()
  25. }
  26. }
  27. } else {
  28. if (whiteList.indexOf(to.path) !== -1) {
  29. next()
  30. } else {
  31. next('/login')
  32. NProgress.done()
  33. }
  34. }
  35. })
  36. router.afterEach(() => {
  37. NProgress.done() // 结束Progress
  38. })