移动端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

permission.js 11 KiB

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