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

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