index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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(query().loginFromlz||store.state.formLz){
  75. store.commit('setFromLz',true);
  76. next()
  77. }else{
  78. if (store.state.token && Object.keys(store.state.userInfo).length > 0) {
  79. next()
  80. } else if (token) {
  81. store.commit('setSsoToken', token)
  82. await store.dispatch('loadUserInfo', {
  83. token
  84. })
  85. // 去除浏览器地址栏token
  86. if (query().token) {
  87. router.replace(location.pathname + location.search.replace(/(&?token=\w+&?)/, ''))
  88. }
  89. next()
  90. } else {
  91. let lastRoute = {
  92. path: to.path,
  93. params: to.params,
  94. query: to.query
  95. }
  96. store.commit('setLastRoute', lastRoute)
  97. let ssoServer = 'http://10.199.143.85:7003'
  98. let redirectUrl = window.location.protocol + '//' + window.location.host + '/auth'
  99. window.location.href = `${ssoServer}/login?redirectUrl=${redirectUrl}`
  100. }
  101. }
  102. })
  103. export default router