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

297 líneas
11 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. '/notice/inviteTendersDetail',
  18. '/notice/winTheBiddingDetail',
  19. '/project/projectNeedsDetail',
  20. '/chungeng/userSSOLogin',
  21. '/chungeng/farmerSSOLogin',
  22. '/supply/index',
  23. '/interaction/index',
  24. '/register/index',
  25. '/register/registerType',
  26. '/register/userRegister',
  27. '/register/companyRegister',
  28. '/biddingHall',
  29. '/authenticRight',
  30. '/authenticRight/login',
  31. '/project',
  32. '/policy',
  33. '/policyDetail',
  34. '/attestationDetail',
  35. '/noticeDetail',
  36. '/homestead/login',
  37. '/applicationForm',
  38. '/applicationList',
  39. '/certificateList',
  40. '/certificateSee',
  41. '/informationList',
  42. '/circulationList',
  43. '/circulationAdd',
  44. '/onlineHomeLogin',
  45. '/lawEnforcement',
  46. '/lawEnforcement/caseList',
  47. '/lawEnforcement/productsList',
  48. '/lawEnforcement/user',
  49. '/lawEnforcement/programme',
  50. '/lawEnforcement/programmeDetail',
  51. '/lawEnforcement/programmeModify',
  52. '/lawEnforcement/programmeApproval',
  53. '/lawEnforcement/complaint',
  54. '/lawEnforcement/reply',
  55. '/lawEnforcement/changePassword',
  56. '/lawEnforcement/feedback',
  57. '/lawEnforcement/feedbackForm',
  58. '/lawEnforcement/agreement',
  59. '/lawEnforcement/work',
  60. '/lawEnforcement/workDetail',
  61. '/lawEnforcement/caseDetail',
  62. '/lawEnforcement/login',
  63. '/lawEnforcement/indexComplaint',
  64. '/lawEnforcement/schemeDetail',
  65. '/lawEnforcement/waitingProcessing',
  66. '/lawEnforcement/complaintAdd',
  67. '/homesteadLogin',
  68. '/yinnongLogin',
  69. '/lawEnforcement/userRegister',
  70. '/lawEnforcement/companyRegister',
  71. //宅基地
  72. '/zjdLogin',
  73. '/onlineHome/workbench',
  74. //阳光村务--新
  75. '/sunVillage_info/login', //登录
  76. '/sunVillage_info/index', //首页
  77. '/sunVillage_info/list_tourists', //二页列表-游客
  78. '/sunVillage_info/fixedAssets', //固定资产
  79. '/sunVillage_info/information', //合同信息
  80. '/sunVillage_info/details', //详情页
  81. '/sunVillage_info/index_code', //农户首页
  82. '/sunVillage_info/list_finance', //财务公开
  83. '/sunVillage_info/list_issues', //零工公开
  84. '/sunVillage_info/list_photo', //一张图公开
  85. '/sunVillage_info/list_contract', //合同公开
  86. '/sunVillage_info/list_contract_detail', //合同公开详情页
  87. '/sunVillage_info/list_tourists_detail', //详情页
  88. '/sunVillage_info/list_issues_detail', //详情页
  89. '/sunVillage_info/list_finance_detail', //详情页
  90. '/sunVillage_info/list_photo_detail', //详情页
  91. '/sunVillage_info/list_finance_ranking', //详情页
  92. '/sunVillage_info/list_tourists_ranking', //详情页
  93. '/sunVillage_info/list_tourists_registration_detail_visitor', //零工详情页
  94. '/sunVillage_info/login_code', //详情页
  95. '/sunVillage_info/index_code_rights', //详情页
  96. '/sunVillage_info/list_vote', //详情页
  97. '/sunVillage_info/list_vote_detail', //详情页
  98. '/sunVillage_info/list_vote_form', //详情页
  99. '/sunVillage_info/suishoupai', //随手拍
  100. '/sunVillage_info/list_complaint', //详情页
  101. '/sunVillage_info/list_complaint_add', //详情页
  102. '/sunVillage_info/list_complaint_detail', //详情页
  103. '/sunVillage_info/list_message', //详情页
  104. '/sunVillage_info/list_message_add', //详情页
  105. '/sunVillage_info/list_message_detail', //详情页
  106. '/sunVillage_info/homeApplication/applicationList', //列表页面
  107. '/sunVillage_info/proposerLite',
  108. '/sunVillage_info/paidExit/paidExitList', //列表页面
  109. '/sunVillage_info/paidExitAdd',
  110. '/sunVillage_info/paidExitModify',
  111. '/sunVillage_info/paidExitDetail',
  112. '/sunVillage_info/arbitrationList',
  113. '/sunVillage_info/arbitrationDetail',
  114. '/sunVillage_info/familyMember',
  115. '/sunVillage_info/familyMemberDetail',
  116. '/sunVillage_info/list_cbfsq',
  117. '/sunVillage_info/list_signature',
  118. '/sunVillage_info/list_official',
  119. '/sunVillage_info/list_signature_add',
  120. '/sunVillage_info/list_multipleLotsNh',
  121. '/sunVillage_info/list_multipleLotsNh_detail',
  122. '/sunVillage_info/list_cbf',
  123. '/sunVillage_info/list_cbht_detail',
  124. '/sunVillage_info/list_resources_ranking',
  125. '/sunVillage_info/list_property_ranking',
  126. '/sunVillage_info/list_contract_ranking',
  127. '/sunVillage_info/identity_check',
  128. '/sunVillage_info/assetMapOpen',
  129. // 新型经营主体
  130. 'newBusinessEntity/newsBulletin', //新闻公告
  131. '/newBusinessEntity/index', //首页
  132. '/newBusinessEntity/login', //登录
  133. '/newBusinessEntity/register', //注册
  134. '/newBusinessEntity/conter', //底部组件
  135. '/newBusinessEntity/newsDetails', //新闻详情
  136. '/newBusinessEntity/listBody', //主体名录
  137. '/newBusinessEntity/map', //地图
  138. //农业大托管
  139. '/agriculturalTrusteeship/index',//首页
  140. '/agriculturalTrusteeship/login',//登录
  141. '/agriculturalTrusteeship/insuranceList',//保险列表
  142. '/agriculturalTrusteeship/insuranceProjectList',//保险产品列表
  143. '/agriculturalTrusteeship/insuranceProjectDetail',//保险产品详情
  144. '/agriculturalTrusteeship/societyList',//社会化列表
  145. '/agriculturalTrusteeship/societyProjectList',//社会化产品列表
  146. '/agriculturalTrusteeship/societyProjectDetail',//社会化产品详情
  147. '/agriculturalTrusteeship/shopList',//保险列表首页
  148. '/agriculturalTrusteeship/shopNeedsList',//保险列表首页
  149. '/agriculturalTrusteeship/shopOrganizationDetail',//保险列表首页
  150. '/agriculturalTrusteeship/shopDepositDetail',//保险列表首页
  151. '/agriculturalTrusteeship/shopDetail',//保险列表详情
  152. '/agriculturalTrusteeship/shopEdit',//保险列表详情
  153. '/agriculturalTrusteeship/shopAdd',//保险列表首页
  154. '/agriculturalTrusteeship/serviceEdit',//保险列表首页
  155. '/agriculturalTrusteeship/socializationIndex',//社会化服务组织待处理
  156. '/agriculturalTrusteeship/socializationProject',//社会化服务组织产品
  157. '/agriculturalTrusteeship/socializationProjectDetail',//社会化服务组织产品详情
  158. '/agriculturalTrusteeship/socializationProjectEdit',//社会化服务组织产品修改
  159. '/agriculturalTrusteeship/socializationBill',//社会化服务组织订单
  160. '/agriculturalTrusteeship/socializationBillDetail',//社会化服务组织订单详情
  161. '/agriculturalTrusteeship/socializationBillOrder',//社会化服务组织订单详情
  162. '/agriculturalTrusteeship/socializationUser',//社会化服务组织个人中心
  163. '/agriculturalTrusteeship/socializationUserEdit',//社会化服务组织个人信息
  164. '/agriculturalTrusteeship/socializationRelease',//社会化服务组织发布产品
  165. '/agriculturalTrusteeship/socializationDraft',//社会化服务组织草稿箱
  166. '/agriculturalTrusteeship/socializationDraftEdit',//社会化服务组织草稿箱修改
  167. //'/agriculturalTrusteeship/buyerIndex',//买家选购
  168. //'/agriculturalTrusteeship/buyerWaitBill',//买家选购-等待处理
  169. // '/agriculturalTrusteeship/buyerAllBill',//买家选购-所有订单
  170. // '/agriculturalTrusteeship/placeOrder',//买家选购-下单页
  171. // '/agriculturalTrusteeship/billDetail',//买家选购-订单详情
  172. // '/agriculturalTrusteeship/billDetail2',//买家选购-订单详情
  173. // '/agriculturalTrusteeship/billDetail3',//买家选购-订单详情
  174. // '/agriculturalTrusteeship/billDetail4',//买家选购-订单详情
  175. // '/agriculturalTrusteeship/evaluate',//买家选购-服务评价
  176. '/plotPremisesMobile/index',//闲置资源
  177. //承包地确权
  178. '/contracted/login',//登录
  179. '/contracted/index',//首页
  180. ]
  181. router.beforeEach((to, from, next) => {
  182. NProgress.start()
  183. if (getToken()) {
  184. /* has token*/
  185. if (to.path === '/login') {
  186. next({ path: '/' })
  187. NProgress.done()
  188. } else {
  189. if (store.getters.roles.length === 0) {
  190. next()
  191. // 判断当前用户是否已拉取完user_info信息
  192. store.dispatch('GetInfo').then(res => {
  193. // 拉取user_info
  194. const roles = res.roles
  195. // store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
  196. // // 根据roles权限生成可访问的路由表
  197. // router.addRoutes(accessRoutes) // 动态添加可访问路由表
  198. // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  199. // })
  200. next()
  201. }).catch(err => {
  202. // store.dispatch('LogOut').then(() => {
  203. // try {
  204. // let loginUrl = Cookies.get("_Login_url");
  205. // if (loginUrl && loginUrl.indexOf("onlineHomeLogin") !== -1) {
  206. // next({ path: '/onlineHomeLogin' })
  207. // return;
  208. // }
  209. // } catch (e) { console.log(e); }
  210. // // Message.error(err)
  211. // if ('/authenticRight'.indexOf(to.path) !== -1) {
  212. // next({ path: '/authenticRight/login' })
  213. // } else if ('/homestead'.indexOf(to.path) !== -1) {
  214. // next({ path: '/homestead/login' })
  215. // } else if (to.path.indexOf('/onlineHome') !== -1) {
  216. // //next(`/onlineHomeLogin`)
  217. // next(`/zjdLogin`)
  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`)
  226. // } else if (to.path.indexOf('/sunVillage') !== -1) {
  227. // next(`/sunVillage/login`)
  228. // } else {
  229. // next(`/yinnongLogin`)
  230. // //next({ path: '/' })
  231. // }
  232. // })
  233. })
  234. } else {
  235. next()
  236. }
  237. }
  238. } else {
  239. // 没有token
  240. //console.info(to);
  241. if (whiteList.indexOf(to.path) !== -1) {
  242. // 在免登录白名单,直接进入
  243. //console.log(to.path)
  244. next()
  245. } else {
  246. try {
  247. let loginUrl = Cookies.get("_Login_url");
  248. if (loginUrl && loginUrl.indexOf("onlineHomeLogin") !== -1) {
  249. next({ path: `/onlineHomeLogin?redirect=${to.fullPath}` })
  250. return;
  251. }
  252. } catch (e) { console.log(e); }
  253. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  254. next(`/authenticRight/login?redirect=${to.fullPath}`)
  255. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  256. next(`/homestead/login?redirect=${to.fullPath}`)
  257. } else if (to.path.indexOf('/onlineHome') !== -1) {
  258. next(`/onlineHomeLogin`)
  259. } else if (to.path.indexOf('/yinnong') !== -1) {
  260. next(`/yinnongLogin`)
  261. } else if (window.location.href.indexOf('/sunVillage_info/') != -1) {
  262. window.location.href = '/sunVillage_info/login';
  263. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  264. next(`/homesteadLogin`)
  265. } else if (to.path.indexOf('/lawEnforcement') !== -1) {
  266. next(`/lawEnforcement/login?redirect=${to.fullPath}`)
  267. } else if (to.path.indexOf('/sunVillage') !== -1) {
  268. next(`/sunVillage/login`)
  269. } else {
  270. next(`/login?redirect=${to.fullPath}`)
  271. }
  272. // // 否则全部重定向到登录页
  273. //next('/index');
  274. NProgress.done()
  275. }
  276. }
  277. })
  278. router.afterEach(() => {
  279. NProgress.done()
  280. })