移动端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

248 líneas
9.2 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. import Cookies from "js-cookie";
  7. NProgress.configure({ showSpinner: false })
  8. const whiteList = [
  9. '/index',
  10. '/login',
  11. '/auth-redirect',
  12. '/bind',
  13. '/register',
  14. '/news/index',
  15. '/news/newDetail',
  16. '/notice/index',
  17. '/supply/index',
  18. '/interaction/index',
  19. '/register/index',
  20. '/register/registerType',
  21. '/register/userRegister',
  22. '/register/companyRegister',
  23. '/biddingHall',
  24. '/authenticRight',
  25. '/authenticRight/login',
  26. '/project',
  27. '/policy',
  28. '/policyDetail',
  29. '/attestationDetail',
  30. '/noticeDetail',
  31. '/homestead/login',
  32. '/applicationForm',
  33. '/applicationList',
  34. '/certificateList',
  35. '/certificateSee',
  36. '/informationList',
  37. '/circulationList',
  38. '/circulationAdd',
  39. '/onlineHomeLogin',
  40. '/lawEnforcement',
  41. '/lawEnforcement/caseList',
  42. '/lawEnforcement/productsList',
  43. '/lawEnforcement/user',
  44. '/lawEnforcement/programme',
  45. '/lawEnforcement/programmeDetail',
  46. '/lawEnforcement/programmeModify',
  47. '/lawEnforcement/programmeApproval',
  48. '/lawEnforcement/complaint',
  49. '/lawEnforcement/reply',
  50. '/lawEnforcement/changePassword',
  51. '/lawEnforcement/feedback',
  52. '/lawEnforcement/feedbackForm',
  53. '/lawEnforcement/agreement',
  54. '/lawEnforcement/work',
  55. '/lawEnforcement/workDetail',
  56. '/lawEnforcement/caseDetail',
  57. '/lawEnforcement/login',
  58. '/lawEnforcement/indexComplaint',
  59. '/lawEnforcement/schemeDetail',
  60. '/lawEnforcement/waitingProcessing',
  61. '/lawEnforcement/complaintAdd',
  62. '/homesteadLogin',
  63. '/yinnongLogin',
  64. '/lawEnforcement/userRegister',
  65. '/lawEnforcement/companyRegister',
  66. '/sunVillage/login',
  67. //阳光村务公众号 -- 待删
  68. '/sunVillage/index',
  69. '/sunVillage/latestReport', //最新报道列表
  70. '/sunVillage/latestReport/details', //最新报道详情
  71. '/sunVillage/importantItems', //重大事项-列表
  72. '/sunVillage/importantItems/details', //重大事项-详情
  73. '/sunVillage/public', //三务公开
  74. '/sunVillage/public/details', //三务公开-详情
  75. '/sunVillage/financial', //惠民金融
  76. '/sunVillage/financial/details', //惠民金融-详情
  77. '/sunVillage/financial/products', //惠民金融 - 理财产品
  78. '/sunVillage/financial/loan', //惠民金融 - 理财产品
  79. '/sunVillage/injoint', //三资公开-财务公开
  80. '/sunVillage/injoint/details',//三资公开-财务公开-详情
  81. '/sunVillage/injoint/meansOf', //三资公开-清产核资
  82. '/sunVillage/injoint/meansOf_desc', //三资公开-清产核资-详情页
  83. '/sunVillage/injoint/assetsPublic', //三资公开-资产公开
  84. '/sunVillage/injoint/assetsPublic_desc', //三资公开-资产公开-详情
  85. '/sunVillage/injoint/publicResources', //三资公开-资源公开
  86. '/sunVillage/injoint/publicResources_desc', //三资公开-资源公开-详情
  87. '/sunVillage/consulting', //民生直通车
  88. '/sunVillage/consulting/inquiries', //民生直通车-咨询
  89. "/sunVillage/consulting/my_consulting", //民生直通车-我的咨询详情
  90. '/sunVillage/consulting/kanban', //民生直通车-民生看板
  91. '/sunVillage/consulting/kanban/focusList', //民生直通车-民生看板 -关注民生list
  92. '/sunVillage/consulting/kanban/focusDesc', //民生直通车-民生看板 -关注民生详情
  93. '/sunVillage/consulting/kanban/affairsList', //民生直通车-民生看板 - 民生办事list
  94. '/sunVillage/equity', //股权查询-股民信息
  95. '/sunVillage/equity_desc', // 股权查询-股民信息-详情
  96. '/sunVillage/shareBonus', //股权查询-股权分红
  97. '/sunVillage/shareBonus_num', //股权查询-股权分红-股数详情页
  98. '/sunVillage/shareBonus_amount', //股权查询-股权分红-分红详情页
  99. '/sunVillage/user/index', //个人中心
  100. '/sunVillage/user/mobile', //个人中心-修改手机号
  101. '/sunVillage/user/information', //个人中心-修改用户信息
  102. '/sunVillage/user/cooperative', //个人中心-修改所属合作社
  103. //阳光村务公众号 -- 待删
  104. //宅基地
  105. '/zjdLogin',
  106. '/onlineHome/workbench',
  107. //阳光村务--新
  108. '/sunVillage_info/login', //登录
  109. '/sunVillage_info/index', //首页
  110. '/sunVillage_info/list_tourists', //二页列表-游客
  111. '/sunVillage_info/fixedAssets', //固定资产
  112. '/sunVillage_info/information', //合同信息
  113. '/sunVillage_info/details', //详情页
  114. '/sunVillage_info/index_code', //详情页
  115. '/sunVillage_info/list_finance', //详情页
  116. '/sunVillage_info/list_issues', //详情页
  117. '/sunVillage_info/list_tourists_detail', //详情页
  118. '/sunVillage_info/list_issues_detail', //详情页
  119. '/sunVillage_info/list_finance_detail', //详情页
  120. '/sunVillage_info/list_finance_ranking', //详情页
  121. '/sunVillage_info/list_tourists_ranking', //详情页
  122. '/sunVillage_info/login_code', //详情页
  123. '/sunVillage_info/index_code_rights', //详情页
  124. '/sunVillage_info/list_vote', //详情页
  125. '/sunVillage_info/list_vote_detail', //详情页
  126. '/sunVillage_info/list_vote_form', //详情页
  127. // 新型经营主体
  128. 'newBusinessEntity/newsBulletin', //新闻公告
  129. '/newBusinessEntity/index', //首页
  130. '/newBusinessEntity/login', //登录
  131. '/newBusinessEntity/register', //注册
  132. '/newBusinessEntity/conter', //底部组件
  133. '/newBusinessEntity/newsDetails', //新闻详情
  134. '/newBusinessEntity/listBody', //主体名录
  135. '/newBusinessEntity/map' //地图
  136. ]
  137. router.beforeEach((to, from, next) => {
  138. NProgress.start()
  139. if (getToken()) {
  140. console.info(to)
  141. /* has token*/
  142. if (to.path === '/login') {
  143. next({ path: '/' })
  144. NProgress.done()
  145. } else {
  146. if (store.getters.roles.length === 0) {
  147. next()
  148. // 判断当前用户是否已拉取完user_info信息
  149. store.dispatch('GetInfo').then(res => {
  150. // 拉取user_info
  151. const roles = res.roles
  152. // store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
  153. // // 根据roles权限生成可访问的路由表
  154. // router.addRoutes(accessRoutes) // 动态添加可访问路由表
  155. // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  156. // })
  157. next()
  158. }).catch(err => {
  159. store.dispatch('LogOut').then(() => {
  160. try {
  161. let loginUrl = Cookies.get("_Login_url");
  162. if (loginUrl && loginUrl.indexOf("onlineHomeLogin") !== -1) {
  163. next({ path: '/onlineHomeLogin' })
  164. return;
  165. }
  166. } catch (e) { console.log(e); }
  167. // Message.error(err)
  168. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  169. next({ path: '/authenticRight/login' })
  170. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  171. next({ path: '/homestead/login' })
  172. } else if (to.path.indexOf('/onlineHome') !== -1) {
  173. //next(`/onlineHomeLogin`)
  174. next(`/zjdLogin`)
  175. } else if (to.path.indexOf('/yinnong') !== -1) {
  176. next(`/yinnongLogin`)
  177. } else if (window.location.href.indexOf('/sunVillage_info/') != -1) {
  178. window.location.href = '/sunVillage_info/login';
  179. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  180. next(`/homesteadLogin`)
  181. } else if (to.path.indexOf('/lawEnforcement') !== -1) {
  182. next(`//lawEnforcement/login`)
  183. } else if (to.path.indexOf('/sunVillage') !== -1) {
  184. next(`/sunVillage/login`)
  185. } else if (to.path.indexOf('/homestead/') !== -1) {
  186. next(`/homestead/login`)
  187. } else {
  188. next(`/yinnongLogin`)
  189. //next({ path: '/' })
  190. }
  191. })
  192. })
  193. } else {
  194. next()
  195. }
  196. }
  197. } else {
  198. // 没有token
  199. console.info(to);
  200. if (whiteList.indexOf(to.path) !== -1) {
  201. // 在免登录白名单,直接进入
  202. console.log(to.path)
  203. next()
  204. } else {
  205. try {
  206. let loginUrl = Cookies.get("_Login_url");
  207. if (loginUrl && loginUrl.indexOf("onlineHomeLogin") !== -1) {
  208. next({ path: `/onlineHomeLogin?redirect=${to.fullPath}` })
  209. return;
  210. }
  211. } catch (e) { console.log(e); }
  212. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  213. next(`/authenticRight/login?redirect=${to.fullPath}`)
  214. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  215. next(`/homestead/login?redirect=${to.fullPath}`)
  216. } else if (to.path.indexOf('/onlineHome') !== -1) {
  217. next(`/onlineHomeLogin`)
  218. } else if (to.path.indexOf('/yinnong') !== -1) {
  219. next(`/yinnongLogin`)
  220. } else if (window.location.href.indexOf('/sunVillage_info/') != -1) {
  221. window.location.href = '/sunVillage_info/login';
  222. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  223. next(`/homesteadLogin`)
  224. } else if (to.path.indexOf('/lawEnforcement') !== -1) {
  225. next(`/lawEnforcement/login?redirect=${to.fullPath}`)
  226. } else if (to.path.indexOf('/sunVillage') !== -1) {
  227. next(`/sunVillage/login`)
  228. } else {
  229. next(`/login?redirect=${to.fullPath}`)
  230. }
  231. // // 否则全部重定向到登录页
  232. //next('/index');
  233. NProgress.done()
  234. }
  235. }
  236. })
  237. router.afterEach(() => {
  238. NProgress.done()
  239. })