移动端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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