移动端
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.

permission.js 4.2 KiB

4 年之前
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 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. '/lawEnforcement/userRegister',
  63. '/lawEnforcement/companyRegister',
  64. ]
  65. router.beforeEach((to, from, next) => {
  66. NProgress.start()
  67. if (getToken()) {
  68. /* has token*/
  69. if (to.path === '/login') {
  70. next({ path: '/' })
  71. NProgress.done()
  72. } else {
  73. if (store.getters.roles.length === 0) {
  74. next()
  75. // 判断当前用户是否已拉取完user_info信息
  76. store.dispatch('GetInfo').then(res => {
  77. console.log(to.path)
  78. // 拉取user_info
  79. const roles = res.roles
  80. // store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
  81. // // 根据roles权限生成可访问的路由表
  82. // router.addRoutes(accessRoutes) // 动态添加可访问路由表
  83. // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  84. // })
  85. next()
  86. }).catch(err => {
  87. store.dispatch('LogOut').then(() => {
  88. console.log(to.path)
  89. // Message.error(err)
  90. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  91. next({ path: '/authenticRight/login' })
  92. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  93. next({ path: '/homestead/login' })
  94. } else if (to.path.indexOf('/onlineHome') !== -1) {
  95. next(`/onlineHomeLogin`)
  96. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  97. next(`/homesteadLogin`)
  98. }else if (to.path.indexOf('/lawEnforcement') !== -1) {
  99. next(`//lawEnforcement/login`)
  100. }else {
  101. next({ path: '/' })
  102. }
  103. })
  104. })
  105. } else {
  106. next()
  107. }
  108. }
  109. } else {
  110. // 没有token
  111. if (whiteList.indexOf(to.path) !== -1) {
  112. // 在免登录白名单,直接进入
  113. console.log(to.path)
  114. next()
  115. } else {
  116. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  117. next(`/authenticRight/login?redirect=${to.fullPath}`)
  118. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  119. next(`/homestead/login?redirect=${to.fullPath}`)
  120. } else if (to.path.indexOf('/onlineHome') !== -1) {
  121. next(`/onlineHomeLogin`)
  122. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  123. next(`/homesteadLogin`)
  124. }else if (to.path.indexOf('/lawEnforcement') !== -1) {
  125. next(`/lawEnforcement/login?redirect=${to.fullPath}`)
  126. } else {
  127. next(`/login?redirect=${to.fullPath}`)
  128. }
  129. // // 否则全部重定向到登录页
  130. //next('/index');
  131. NProgress.done()
  132. }
  133. }
  134. })
  135. router.afterEach(() => {
  136. NProgress.done()
  137. })