移动端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 4 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 4 година
пре 4 година
пре 4 година
пре 3 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 4 година
пре 4 година
пре 4 година
пре 3 година
пре 4 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 4 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. '/applicationForm',
  32. '/applicationList',
  33. '/certificateList',
  34. '/certificateSee',
  35. '/informationList',
  36. '/circulationList',
  37. '/circulationAdd',
  38. '/onlineHomeLogin',
  39. '/lawEnforcement',
  40. '/lawEnforcement/caseList',
  41. '/lawEnforcement/productsList',
  42. '/lawEnforcement/user',
  43. '/lawEnforcement/programme',
  44. '/lawEnforcement/programmeDetail',
  45. '/lawEnforcement/programmeModify',
  46. '/lawEnforcement/programmeApproval',
  47. '/lawEnforcement/complaint',
  48. '/lawEnforcement/reply',
  49. '/lawEnforcement/changePassword',
  50. '/lawEnforcement/feedback',
  51. '/lawEnforcement/feedbackForm',
  52. '/lawEnforcement/agreement',
  53. '/lawEnforcement/work',
  54. '/lawEnforcement/workDetail',
  55. '/lawEnforcement/caseDetail',
  56. '/lawEnforcement/login',
  57. '/lawEnforcement/indexComplaint',
  58. '/lawEnforcement/schemeDetail',
  59. '/lawEnforcement/waitingProcessing',
  60. '/lawEnforcement/complaintAdd',
  61. '/homesteadLogin',
  62. ]
  63. router.beforeEach((to, from, next) => {
  64. NProgress.start()
  65. if (getToken()) {
  66. /* has token*/
  67. if (to.path === '/login') {
  68. next({ path: '/' })
  69. NProgress.done()
  70. } else {
  71. if (store.getters.roles.length === 0) {
  72. next()
  73. // 判断当前用户是否已拉取完user_info信息
  74. store.dispatch('GetInfo').then(res => {
  75. console.log(to.path)
  76. // 拉取user_info
  77. const roles = res.roles
  78. // store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
  79. // // 根据roles权限生成可访问的路由表
  80. // router.addRoutes(accessRoutes) // 动态添加可访问路由表
  81. // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  82. // })
  83. next()
  84. }).catch(err => {
  85. store.dispatch('LogOut').then(() => {
  86. console.log(to.path)
  87. // Message.error(err)
  88. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  89. next({ path: '/authenticRight/login' })
  90. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  91. next({ path: '/homestead/login' })
  92. } else if (to.path.indexOf('/onlineHome') !== -1) {
  93. next(`/onlineHomeLogin`)
  94. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  95. next(`/homesteadLogin`)
  96. }else if (to.path.indexOf('/lawEnforcement') !== -1) {
  97. next(`//lawEnforcement/login`)
  98. }else {
  99. next({ path: '/' })
  100. }
  101. })
  102. })
  103. } else {
  104. next()
  105. }
  106. }
  107. } else {
  108. // 没有token
  109. if (whiteList.indexOf(to.path) !== -1) {
  110. // 在免登录白名单,直接进入
  111. console.log(to.path)
  112. next()
  113. } else {
  114. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  115. next(`/authenticRight/login?redirect=${to.fullPath}`)
  116. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  117. next(`/homestead/login?redirect=${to.fullPath}`)
  118. } else if (to.path.indexOf('/onlineHome') !== -1) {
  119. next(`/onlineHomeLogin`)
  120. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  121. next(`/homesteadLogin`)
  122. }else if (to.path.indexOf('/lawEnforcement') !== -1) {
  123. next(`/lawEnforcement/login?redirect=${to.fullPath}`)
  124. } else {
  125. next(`/login?redirect=${to.fullPath}`)
  126. }
  127. // // 否则全部重定向到登录页
  128. //next('/index');
  129. NProgress.done()
  130. }
  131. }
  132. })
  133. router.afterEach(() => {
  134. NProgress.done()
  135. })