index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // router/index.js
  2. import { createRouter, createWebHistory } from 'vue-router'
  3. import { ElMessage } from 'element-plus'
  4. const routes = [
  5. // 添加更多路由信息
  6. {
  7. path: "/401",
  8. component: () => import("@/pages/401/NotFind.vue"),
  9. meta: {
  10. name: "401"
  11. }
  12. },
  13. {
  14. path: "/login",
  15. component: () => import("@/pages/login/LoginNow.vue"),
  16. meta: {
  17. name: "login"
  18. }
  19. },
  20. {
  21. path: "/77",
  22. component: () => import("@/pages/mapLoad/FatherMap.vue")
  23. },
  24. {
  25. path: "/draw",
  26. component: () => import("@/pages/components/draw/DrawDesigns.vue")
  27. },
  28. {
  29. path: "/home",
  30. component: () => import("@/pages/home/HomePage.vue"),
  31. meta: {
  32. name: "home"
  33. },
  34. children: [
  35. {
  36. path: "/home/report",
  37. component: () => import("@/pages/report/ReportVue.vue"),
  38. meta: {
  39. name: "report"
  40. },
  41. },
  42. {
  43. path: "/home/mission",
  44. component: () => import("@/pages/mission/MissionVue.vue"),
  45. meta: {
  46. name: "mission"
  47. }
  48. },
  49. {
  50. path: "/home/int",
  51. component: () => import("@/pages/intMap/IntMap.vue"),
  52. meta: {
  53. name: "int"
  54. }
  55. },
  56. {
  57. path: "/home/scdMap",
  58. component: () => import("@/pages/scdCanLook/ScdCanLook.vue"),
  59. meta: {
  60. name: "scdMap"
  61. }
  62. },
  63. {
  64. path: "/home/setting",
  65. component: () => import("@/pages/system/SystemPage.vue"),
  66. meta: {
  67. name: "setting"
  68. }
  69. },
  70. {
  71. path: "/home/system",
  72. component: () => import("@/pages/setting/SettingPage.vue"),
  73. meta: {
  74. name: "system"
  75. }
  76. },
  77. {
  78. path: "/home/netStructPicture",
  79. component: () => import("@/pages/netStructPicture"),
  80. meta: {
  81. name: "netStructPicture"
  82. }
  83. },
  84. {
  85. path: "/home/report/details",
  86. component: () => import("@/pages/report/components/ReportDetails.vue"),
  87. meta: {
  88. name: "reportDetails"
  89. }
  90. }
  91. ]
  92. }
  93. ]
  94. const router = createRouter({
  95. history: createWebHistory(),
  96. routes,
  97. })
  98. router.beforeEach((to, from, next) => {
  99. console.log(to, from);
  100. if (to.meta.name == null || to.meta.name == '' || to.meta.name == undefined) {
  101. next("/401")
  102. }
  103. // 假设您有一个名为 isAuthenticated 的全局变量来表示用户是否已登录
  104. let isAuthenticated = false; // 请替换为实际的登录状态判断逻辑
  105. let loginStatus = sessionStorage.getItem("loginStatus")
  106. if (loginStatus === 'true') {
  107. isAuthenticated = true
  108. }
  109. // 如果用户已登录,正常导航到目标路由
  110. if (isAuthenticated) {
  111. next();
  112. } else {
  113. // ElMessage({
  114. // type: "error",
  115. // message: "您还未登录"
  116. // })
  117. // 如果用户未登录,重定向到登录页
  118. if (to.path !== '/login') {
  119. next('/login');
  120. } else {
  121. // 如果用户已经在登录页,继续正常导航
  122. next();
  123. }
  124. }
  125. })
  126. export default router