index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. import store from '../store'
  13. import { query } from '../utils/query'
  14. Vue.use(Router)
  15. const router = new Router({
  16. mode: 'history',
  17. routes: [
  18. {
  19. path: '/',
  20. name: 'main',
  21. component: Main
  22. },
  23. {
  24. path: '/strategy',
  25. name: 'strategy',
  26. component: Strategy
  27. },
  28. {
  29. path: '/appeal',
  30. name: 'appeal',
  31. component: Appeal
  32. },
  33. {
  34. path: '/appeal/appealDetail',
  35. name: 'appealDetail',
  36. component: AppealDetail
  37. },
  38. {
  39. path: '/appeal/appealDetails',
  40. name: 'appealDetails',
  41. component: AppealDetails
  42. },
  43. {
  44. path: '/audit',
  45. name: 'audit',
  46. component: Audit
  47. },
  48. {
  49. path: '/doBusiness',
  50. name: 'doBusiness',
  51. component: DoBusiness
  52. },
  53. {
  54. path: '/evaluate',
  55. name: 'evaluate',
  56. component: Evaluate
  57. },
  58. {
  59. path: '/evaluate/evTwoLevelMenu',
  60. name: 'evTwoLevelMenu',
  61. component: EvTwoLevelMenu
  62. }
  63. ]
  64. })
  65. router.beforeEach(async (to, from, next) => {
  66. const token = query().token || sessionStorage.getItem('token')
  67. if (store.state.token && Object.keys(store.state.userInfo).length > 0) {
  68. next()
  69. } else if (token) {
  70. store.commit('setSsoToken', token)
  71. await store.dispatch('loadUserInfo', { token })
  72. // 去除浏览器地址栏token
  73. if (query().token) {
  74. router.replace(location.pathname + location.search.replace(/(&?token=\w+&?)/, ''))
  75. }
  76. next()
  77. } else {
  78. let ssoServer = 'http://sso.sagacloud.cn'
  79. let redirectUrl = window.location.protocol + '//' + window.location.host + '/strategy'
  80. window.location.href = `${ssoServer}/login?redirectUrl=${redirectUrl}`
  81. }
  82. })
  83. export default router