移动端
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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