移动端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

4 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
3 роки тому
3 роки тому
4 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. '/authenticRight',
  24. '/authenticRight/login',
  25. '/project',
  26. '/policy',
  27. '/policyDetail',
  28. '/attestationDetail',
  29. '/noticeDetail',
  30. '/homestead/login',
  31. ]
  32. router.beforeEach((to, from, next) => {
  33. NProgress.start()
  34. if (getToken()) {
  35. /* has token*/
  36. if (to.path === '/login') {
  37. next({ path: '/' })
  38. NProgress.done()
  39. } else {
  40. if (store.getters.roles.length === 0) {
  41. next()
  42. // 判断当前用户是否已拉取完user_info信息
  43. store.dispatch('GetInfo').then(res => {
  44. // 拉取user_info
  45. const roles = res.roles
  46. // store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
  47. // // 根据roles权限生成可访问的路由表
  48. // router.addRoutes(accessRoutes) // 动态添加可访问路由表
  49. // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  50. // })
  51. next()
  52. }).catch(err => {
  53. store.dispatch('LogOut').then(() => {
  54. // Message.error(err)
  55. next({ path: '/' })
  56. })
  57. })
  58. } else {
  59. next()
  60. }
  61. }
  62. } else {
  63. // 没有token
  64. if (whiteList.indexOf(to.path) !== -1) {
  65. // 在免登录白名单,直接进入
  66. next()
  67. } else {
  68. if ('/homestead/index'.indexOf(to.path) !== -1) {
  69. next(`/homestead/login?redirect=${to.fullPath}`)
  70. } else {
  71. next(`/login?redirect=${to.fullPath}`)
  72. }
  73. // // 否则全部重定向到登录页
  74. //next('/index');
  75. NProgress.done()
  76. }
  77. }
  78. })
  79. router.afterEach(() => {
  80. NProgress.done()
  81. })