移动端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

290 行
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/login_code', //详情页
  94. '/sunVillage_info/index_code_rights', //详情页
  95. '/sunVillage_info/list_vote', //详情页
  96. '/sunVillage_info/list_vote_detail', //详情页
  97. '/sunVillage_info/list_vote_form', //详情页
  98. '/sunVillage_info/suishoupai', //随手拍
  99. '/sunVillage_info/list_complaint', //详情页
  100. '/sunVillage_info/list_complaint_add', //详情页
  101. '/sunVillage_info/list_complaint_detail', //详情页
  102. '/sunVillage_info/list_message', //详情页
  103. '/sunVillage_info/list_message_add', //详情页
  104. '/sunVillage_info/list_message_detail', //详情页
  105. '/sunVillage_info/homeApplication/applicationList', //列表页面
  106. '/sunVillage_info/proposerLite',
  107. '/sunVillage_info/paidExit/paidExitList', //列表页面
  108. '/sunVillage_info/paidExitAdd',
  109. '/sunVillage_info/paidExitModify',
  110. '/sunVillage_info/paidExitDetail',
  111. '/sunVillage_info/arbitrationList',
  112. '/sunVillage_info/arbitrationDetail',
  113. '/sunVillage_info/familyMember',
  114. '/sunVillage_info/familyMemberDetail',
  115. '/sunVillage_info/list_signature',
  116. '/sunVillage_info/list_official',
  117. '/sunVillage_info/list_signature_add',
  118. '/sunVillage_info/list_multipleLotsNh',
  119. '/sunVillage_info/list_multipleLotsNh_detail',
  120. '/sunVillage_info/list_cbf',
  121. '/sunVillage_info/list_cbht_detail',
  122. '/sunVillage_info/list_resources_ranking',
  123. '/sunVillage_info/list_property_ranking',
  124. '/sunVillage_info/list_contract_ranking',
  125. // 新型经营主体
  126. 'newBusinessEntity/newsBulletin', //新闻公告
  127. '/newBusinessEntity/index', //首页
  128. '/newBusinessEntity/login', //登录
  129. '/newBusinessEntity/register', //注册
  130. '/newBusinessEntity/conter', //底部组件
  131. '/newBusinessEntity/newsDetails', //新闻详情
  132. '/newBusinessEntity/listBody', //主体名录
  133. '/newBusinessEntity/map', //地图
  134. //农业大托管
  135. '/agriculturalTrusteeship/index',//首页
  136. '/agriculturalTrusteeship/login',//登录
  137. '/agriculturalTrusteeship/insuranceList',//保险列表
  138. '/agriculturalTrusteeship/insuranceProjectList',//保险产品列表
  139. '/agriculturalTrusteeship/insuranceProjectDetail',//保险产品详情
  140. '/agriculturalTrusteeship/societyList',//社会化列表
  141. '/agriculturalTrusteeship/societyProjectList',//社会化产品列表
  142. '/agriculturalTrusteeship/societyProjectDetail',//社会化产品详情
  143. '/agriculturalTrusteeship/shopList',//保险列表首页
  144. '/agriculturalTrusteeship/shopNeedsList',//保险列表首页
  145. '/agriculturalTrusteeship/shopOrganizationDetail',//保险列表首页
  146. '/agriculturalTrusteeship/shopDepositDetail',//保险列表首页
  147. '/agriculturalTrusteeship/shopDetail',//保险列表详情
  148. '/agriculturalTrusteeship/shopEdit',//保险列表详情
  149. '/agriculturalTrusteeship/shopAdd',//保险列表首页
  150. '/agriculturalTrusteeship/serviceEdit',//保险列表首页
  151. '/agriculturalTrusteeship/socializationIndex',//社会化服务组织待处理
  152. '/agriculturalTrusteeship/socializationProject',//社会化服务组织产品
  153. '/agriculturalTrusteeship/socializationProjectDetail',//社会化服务组织产品详情
  154. '/agriculturalTrusteeship/socializationProjectEdit',//社会化服务组织产品修改
  155. '/agriculturalTrusteeship/socializationBill',//社会化服务组织订单
  156. '/agriculturalTrusteeship/socializationBillDetail',//社会化服务组织订单详情
  157. '/agriculturalTrusteeship/socializationBillOrder',//社会化服务组织订单详情
  158. '/agriculturalTrusteeship/socializationUser',//社会化服务组织个人中心
  159. '/agriculturalTrusteeship/socializationUserEdit',//社会化服务组织个人信息
  160. '/agriculturalTrusteeship/socializationRelease',//社会化服务组织发布产品
  161. '/agriculturalTrusteeship/socializationDraft',//社会化服务组织草稿箱
  162. '/agriculturalTrusteeship/socializationDraftEdit',//社会化服务组织草稿箱修改
  163. //'/agriculturalTrusteeship/buyerIndex',//买家选购
  164. //'/agriculturalTrusteeship/buyerWaitBill',//买家选购-等待处理
  165. // '/agriculturalTrusteeship/buyerAllBill',//买家选购-所有订单
  166. // '/agriculturalTrusteeship/placeOrder',//买家选购-下单页
  167. // '/agriculturalTrusteeship/billDetail',//买家选购-订单详情
  168. // '/agriculturalTrusteeship/billDetail2',//买家选购-订单详情
  169. // '/agriculturalTrusteeship/billDetail3',//买家选购-订单详情
  170. // '/agriculturalTrusteeship/billDetail4',//买家选购-订单详情
  171. // '/agriculturalTrusteeship/evaluate',//买家选购-服务评价
  172. '/plotPremisesMobile/index',//闲置资源
  173. ]
  174. router.beforeEach((to, from, next) => {
  175. NProgress.start()
  176. if (getToken()) {
  177. /* has token*/
  178. if (to.path === '/login') {
  179. next({ path: '/' })
  180. NProgress.done()
  181. } else {
  182. if (store.getters.roles.length === 0) {
  183. next()
  184. // 判断当前用户是否已拉取完user_info信息
  185. store.dispatch('GetInfo').then(res => {
  186. // 拉取user_info
  187. const roles = res.roles
  188. // store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
  189. // // 根据roles权限生成可访问的路由表
  190. // router.addRoutes(accessRoutes) // 动态添加可访问路由表
  191. // next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  192. // })
  193. next()
  194. }).catch(err => {
  195. store.dispatch('LogOut').then(() => {
  196. try {
  197. let loginUrl = Cookies.get("_Login_url");
  198. if (loginUrl && loginUrl.indexOf("onlineHomeLogin") !== -1) {
  199. next({ path: '/onlineHomeLogin' })
  200. return;
  201. }
  202. } catch (e) { console.log(e); }
  203. // Message.error(err)
  204. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  205. next({ path: '/authenticRight/login' })
  206. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  207. next({ path: '/homestead/login' })
  208. } else if (to.path.indexOf('/onlineHome') !== -1) {
  209. //next(`/onlineHomeLogin`)
  210. next(`/zjdLogin`)
  211. } else if (to.path.indexOf('/yinnong') !== -1) {
  212. next(`/yinnongLogin`)
  213. } else if (window.location.href.indexOf('/sunVillage_info/') != -1) {
  214. window.location.href = '/sunVillage_info/login';
  215. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  216. next(`/homesteadLogin`)
  217. } else if (to.path.indexOf('/lawEnforcement') !== -1) {
  218. next(`//lawEnforcement/login`)
  219. } else if (to.path.indexOf('/sunVillage') !== -1) {
  220. next(`/sunVillage/login`)
  221. } else if (to.path.indexOf('/homestead/') !== -1) {
  222. next(`/homestead/login`)
  223. } else {
  224. next(`/yinnongLogin`)
  225. //next({ path: '/' })
  226. }
  227. })
  228. })
  229. } else {
  230. next()
  231. }
  232. }
  233. } else {
  234. // 没有token
  235. console.info(to);
  236. if (whiteList.indexOf(to.path) !== -1) {
  237. // 在免登录白名单,直接进入
  238. console.log(to.path)
  239. next()
  240. } else {
  241. try {
  242. let loginUrl = Cookies.get("_Login_url");
  243. if (loginUrl && loginUrl.indexOf("onlineHomeLogin") !== -1) {
  244. next({ path: `/onlineHomeLogin?redirect=${to.fullPath}` })
  245. return;
  246. }
  247. } catch (e) { console.log(e); }
  248. if ('/authenticRight/index'.indexOf(to.path) !== -1) {
  249. next(`/authenticRight/login?redirect=${to.fullPath}`)
  250. } else if ('/homestead/index'.indexOf(to.path) !== -1) {
  251. next(`/homestead/login?redirect=${to.fullPath}`)
  252. } else if (to.path.indexOf('/onlineHome') !== -1) {
  253. next(`/onlineHomeLogin`)
  254. } else if (to.path.indexOf('/yinnong') !== -1) {
  255. next(`/yinnongLogin`)
  256. } else if (window.location.href.indexOf('/sunVillage_info/') != -1) {
  257. window.location.href = '/sunVillage_info/login';
  258. } else if (to.path.indexOf('/homesteadSurvey') !== -1) {
  259. next(`/homesteadLogin`)
  260. } else if (to.path.indexOf('/lawEnforcement') !== -1) {
  261. next(`/lawEnforcement/login?redirect=${to.fullPath}`)
  262. } else if (to.path.indexOf('/sunVillage') !== -1) {
  263. next(`/sunVillage/login`)
  264. } else {
  265. next(`/login?redirect=${to.fullPath}`)
  266. }
  267. // // 否则全部重定向到登录页
  268. //next('/index');
  269. NProgress.done()
  270. }
  271. }
  272. })
  273. router.afterEach(() => {
  274. NProgress.done()
  275. })