移动端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

79 行
1.9 KiB

  1. import router from './router'
  2. import store from './store'
  3. import NProgress from 'nprogress'
  4. import 'nprogress/nprogress.css'
  5. import { getToken } from '@/utils/auth'
  6. NProgress.configure({ showSpinner: false })
  7. const whiteList = [
  8. '/index',
  9. '/login',
  10. '/auth-redirect',
  11. '/bind',
  12. '/register',
  13. '/news/index',
  14. '/news/newDetail',
  15. '/notice/index',
  16. '/supply/index',
  17. '/interaction/index',
  18. '/register/index',
  19. '/register/registerType',
  20. '/register/userRegister',
  21. '/register/companyRegister',
  22. '/biddingHall',
  23. '/project',
  24. '/policy',
  25. '/policyDetail',
  26. '/attestationDetail',
  27. '/noticeDetail',
  28. ]
  29. router.beforeEach((to, from, next) => {
  30. NProgress.start()
  31. if (getToken()) {
  32. /* has token*/
  33. if (to.path === '/login') {
  34. next({ path: '/' })
  35. NProgress.done()
  36. } else {
  37. if (store.getters.roles.length === 0) {
  38. next()
  39. // 判断当前用户是否已拉取完user_info信息
  40. store.dispatch('GetInfo').then(res => {
  41. // 拉取user_info
  42. const roles = res.roles
  43. // store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
  44. // // 根据roles权限生成可访问的路由表
  45. // router.addRoutes(accessRoutes) // 动态添加可访问路由表
  46. // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  47. // })
  48. next()
  49. }).catch(err => {
  50. store.dispatch('LogOut').then(() => {
  51. // Message.error(err)
  52. next({ path: '/' })
  53. })
  54. })
  55. } else {
  56. next()
  57. }
  58. }
  59. } else {
  60. // 没有token
  61. if (whiteList.indexOf(to.path) !== -1) {
  62. // 在免登录白名单,直接进入
  63. next()
  64. } else {
  65. next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
  66. //next('/index');
  67. NProgress.done()
  68. }
  69. }
  70. })
  71. router.afterEach(() => {
  72. NProgress.done()
  73. })