移动端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

permission.js 3.8 KiB

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