index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. const Main = () => import('@/views/main/index')
  4. const Strategy = () => import('@/views/strategy/index')
  5. const Appeal = () => import('@/views/appeal/index')
  6. const AppealDetail = () => import('@/views/appeal/appealDetail')
  7. const AppealDetails = () => import('@/views/appeal/appealDetails')
  8. const Audit = () => import('@/views/audit/index')
  9. const DoBusiness = () => import('@/views/doBusiness/index')
  10. const Evaluate = () => import('@/views/evaluate/index')
  11. const EvTwoLevelMenu = () => import('@/views/evaluate/evTwoLevelMenu')
  12. const Auth = () => import('@/views/auth/index')
  13. import store from '../store'
  14. import {
  15. query
  16. } from '../utils/query'
  17. Vue.use(Router)
  18. const router = new Router({
  19. mode: 'history',
  20. routes: [{
  21. path: '/',
  22. name: 'main',
  23. component: Main
  24. },
  25. {
  26. path: '/auth',
  27. name: 'auth',
  28. component: Auth
  29. },
  30. {
  31. path: '/strategy',
  32. name: 'strategy',
  33. component: Strategy
  34. },
  35. {
  36. path: '/appeal',
  37. name: 'appeal',
  38. component: Appeal
  39. },
  40. {
  41. path: '/appeal/appealDetail',
  42. name: 'appealDetail',
  43. component: AppealDetail
  44. },
  45. {
  46. path: '/appeal/appealDetails',
  47. name: 'appealDetails',
  48. component: AppealDetails
  49. },
  50. {
  51. path: '/audit',
  52. name: 'audit',
  53. component: Audit
  54. },
  55. {
  56. path: '/doBusiness',
  57. name: 'doBusiness',
  58. component: DoBusiness
  59. },
  60. {
  61. path: '/evaluate',
  62. name: 'evaluate',
  63. component: Evaluate
  64. },
  65. {
  66. path: '/evaluate/evTwoLevelMenu/:date/:name',
  67. name: 'evTwoLevelMenu',
  68. component: EvTwoLevelMenu
  69. }
  70. ]
  71. })
  72. router.beforeEach(async (to, from, next) => {
  73. const token = query().token || sessionStorage.getItem('token')
  74. if (store.state.token && Object.keys(store.state.userInfo).length > 0) {
  75. next()
  76. } else if (token) {
  77. store.commit('setSsoToken', token)
  78. await store.dispatch('loadUserInfo', {
  79. token
  80. })
  81. // 去除浏览器地址栏token
  82. if (query().token) {
  83. router.replace(location.pathname + location.search.replace(/(&?token=\w+&?)/, ''))
  84. }
  85. next()
  86. } else {
  87. let lastRoute = {
  88. path: to.path,
  89. params: to.params,
  90. query: to.query
  91. }
  92. store.commit('setLastRoute', lastRoute)
  93. let ssoServer = 'http://10.199.143.85:7003'
  94. let redirectUrl = window.location.protocol + '//' + window.location.host + '/auth'
  95. window.location.href = `${ssoServer}/login?redirectUrl=${redirectUrl}`
  96. }
  97. })
  98. export default router