index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import Vue from 'vue'
  2. import store from '@/store'
  3. import VueRouter from 'vue-router'
  4. import { query } from '@/utils/query'
  5. Vue.use(VueRouter)
  6. const routes = [
  7. // 登陆页面
  8. // {
  9. // path: '/',
  10. // redirect: '/home/overview', // 只有区域,及区域以上用户才能进入总部首页这一套
  11. // },
  12. {
  13. path: '/404',
  14. component: () => import('../components/404'),
  15. },
  16. {
  17. path: '/group',
  18. component: () => import('../views/statistics/index'),
  19. },
  20. // home
  21. {
  22. path: '/home',
  23. name: 'home',
  24. component: () => import('../views/index'),
  25. redirect: '/home/homepage',
  26. children: [
  27. {
  28. path: 'homepage',
  29. component: () => import('../views/homepage'),
  30. },
  31. //概览
  32. {
  33. path: 'overview',
  34. component: () => import('../views/overview'),
  35. },
  36. // 楼层功能
  37. {
  38. path: 'floorFunc',
  39. component: () => import('../views/floorFunc'),
  40. },
  41. // 设备设施
  42. {
  43. path: 'equipment',
  44. component: () => import('../views/equipment'),
  45. },
  46. // 其他功能
  47. {
  48. path: 'other',
  49. component: () => import('../views/other'),
  50. },
  51. // 分析
  52. {
  53. path: 'analysis',
  54. component: () => import('../views/analysis'),
  55. },
  56. //图例库管理
  57. {
  58. path: 'legendLibrary',
  59. component: () => import('../views/legendLibrary'),
  60. },
  61. //图例绘制规则
  62. {
  63. path: 'legendRules',
  64. component: () => import('../views/legendRules'),
  65. },
  66. ],
  67. },
  68. ]
  69. const router = new VueRouter({
  70. mode: 'history',
  71. base: process.env.BASE_URL,
  72. routes,
  73. })
  74. //不需要token的路由
  75. const ignore = ['/404']
  76. router.beforeEach(async (to, from, next) => {
  77. if (!ignore.includes(to.path)) {
  78. const token = store.getters['ssoToken'] || query().token
  79. if (token) {
  80. store.commit('SETSSOTOKEN', token)
  81. if (to.path == '/') {
  82. next('/group')
  83. }
  84. if (to.path == '/group' || to.path == '/home/homepage') {
  85. if (store.state.accessLevel == -1) {
  86. await store.dispatch('getUserInfo', router)
  87. await store.dispatch('getBrand')
  88. await store.dispatch('getFact')
  89. }
  90. }
  91. await store.dispatch('getFloors')
  92. await store.dispatch('getBrand')
  93. await store.dispatch('getFact')
  94. next()
  95. } else {
  96. let lastRoute = {
  97. path: to.path,
  98. params: to.params,
  99. query: to.query,
  100. }
  101. store.commit('SETLASTROUTER', lastRoute)
  102. let ssoServer = 'http://oauth.wanda-dev.cn'
  103. let systemcode = 'CAD156',
  104. signal = new Date().getTime(),
  105. version = '1.0.0'
  106. window.location.href = `${ssoServer}/login?systemcode=${systemcode}&signal=${signal}&version=${version}`
  107. }
  108. } else {
  109. next()
  110. return
  111. }
  112. })
  113. export default router