deepchart后台管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.9 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import Layout from '../layout/Layout.vue'
  3. const routes = [
  4. {
  5. path: '/',
  6. redirect: '/userPermissions/market'
  7. },
  8. {
  9. path: '/login',
  10. name: 'login',
  11. component: () => import('../views/Login.vue'),
  12. meta: {
  13. title: '登录',
  14. hiddenSidebar: true,
  15. requireAuth: false // 登录页不需要登录
  16. }
  17. },
  18. {
  19. path: '',
  20. component: Layout,
  21. meta: {
  22. requireAuth: true // Layout下所有子路由都需要登录
  23. },
  24. children: [
  25. {
  26. path: 'userPermissions',
  27. name: 'userPermissions',
  28. meta: { title: '用户权限管理', icon: "UserFilled", showSidebar: true, isParentNav: true },
  29. children: [
  30. {
  31. path: 'market',
  32. name: 'market',
  33. component: () => import('../views/UserPermissions/Market.vue'),
  34. meta: { title: '行情期限', showSidebar: true }
  35. },
  36. {
  37. path: 'module',
  38. name: 'module',
  39. component: () => import('../views/UserPermissions/Module.vue'),
  40. meta: { title: '模块期限', showSidebar: true }
  41. },
  42. // 深度探索--操作日志
  43. {
  44. path: 'logDeepexplore',
  45. name: 'logDeepexplore',
  46. component: () => import('../views/UserPermissions/LogDeepExplore.vue'),
  47. meta: { hidden: true }
  48. },
  49. // DeepMate--操作日志
  50. {
  51. path: 'logDeepMate',
  52. name: 'logDeepMate',
  53. component: () => import('../views/UserPermissions/LogDeepMate.vue'),
  54. meta: { hidden: true }
  55. },
  56. // 行情期限--操作日志
  57. {
  58. path: 'logMarket',
  59. name: 'logMarket',
  60. component: () => import('../views/UserPermissions/LogMarket.vue'),
  61. meta: { hidden: true }
  62. },
  63. // 导出列表页面
  64. {
  65. path: 'export',
  66. name: 'export',
  67. component: () => import('../views/UserPermissions/Export.vue'),
  68. meta: { hidden: true }
  69. }
  70. ]
  71. }
  72. ]
  73. }
  74. ]
  75. const router = createRouter({
  76. history: createWebHistory(import.meta.env.BASE_URL),
  77. routes
  78. })
  79. // 全局前置守卫
  80. router.beforeEach((to, from, next) => {
  81. // 登录状态判断
  82. const token = localStorage.getItem('token')
  83. // 权限拦截逻辑
  84. if (to.meta.requireAuth) {
  85. // 目标页面需要登录:已登录→放行,未登录→跳登录页
  86. if (token) {
  87. next() // 已登录,放行
  88. } else {
  89. next({ path: '/login' }) // 跳登录页
  90. }
  91. } else {
  92. // 目标页面不需要登录:已登录→跳首页,未登录→放行
  93. if (token && to.path === '/login') {
  94. next('/') // 自动跳首页
  95. } else {
  96. next() // 未登录,放行到登录页
  97. }
  98. }
  99. })
  100. export default router