移动端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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