| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- import { createRouter, createWebHashHistory } from 'vue-router'
- import { getToken } from '@/utils/storage'
- /**
- * 路由配置
- * meta.requiresAuth = true 需要登录才能访问
- * meta.requiresAuth = false 不需要登录
- */
- const routes = [
- {
- path: '/login',
- name: 'Login',
- component: () => import('@/views/login/index.vue'),
- meta: { requiresAuth: false, title: '登录' }
- },
- {
- path: '/',
- component: () => import('@/layout/index.vue'),
- meta: { requiresAuth: true },
- redirect: '/user/app',
- children: [
- {
- path: 'user/app',
- name: 'AppUser',
- component: () => import('@/views/user/app-user/index.vue'),
- meta: { requiresAuth: true, title: '账号管理', icon: 'User', hidden: true }
- },
- {
- path: 'user',
- name: 'User',
- meta: { requiresAuth: true, title: '用户管理', icon: 'UserFilled' },
- redirect: '/user/profile',
- children: [
- {
- path: 'profile',
- name: 'UserProfile',
- component: () => import('@/views/user/profile/index.vue'),
- meta: { requiresAuth: true, title: '用户列表', icon: 'User' }
- },
- {
- path: 'plan',
- name: 'UserPlan',
- component: () => import('@/views/user/plan/index.vue'),
- meta: { requiresAuth: true, title: '用户方案管理', icon: 'Document' }
- }
- ]
- },
- {
- path: 'user/device',
- name: 'UserDevice',
- component: () => import('@/views/user/device/index.vue'),
- meta: { requiresAuth: true, title: '用户设备管理', icon: 'Monitor', hidden: true }
- },
- {
- path: 'acupoint',
- name: 'Acupoint',
- component: () => import('@/views/acupoint/index.vue'),
- meta: { requiresAuth: true, title: '穴位管理', icon: 'FirstAidKit' }
- },
- {
- path: 'device',
- name: 'Device',
- component: () => import('@/views/device/index.vue'),
- meta: { requiresAuth: true, title: '设备管理', icon: 'Monitor' }
- },
- {
- path: 'device/users',
- name: 'DeviceUsers',
- component: () => import('@/views/device/users.vue'),
- meta: { requiresAuth: true, title: '设备用户管理', hidden: true }
- },
- {
- path: 'moxibustion',
- name: 'Moxibustion',
- component: () => import('@/views/moxibustion/index.vue'),
- meta: { requiresAuth: true, title: '艾灸手法管理', icon: 'Promotion' }
- },
- {
- path: 'plan',
- name: 'Plan',
- component: () => import('@/views/plan/index.vue'),
- meta: { requiresAuth: true, title: '方案管理', icon: 'Notebook' }
- },
- {
- path: 'simulation',
- name: 'Simulation',
- component: () => import('@/views/simulation/index.vue'),
- meta: { requiresAuth: true, title: '方案模拟测试', icon: 'DataAnalysis' }
- },
- {
- path: 'content',
- name: 'Content',
- component: () => import('@/views/content/index.vue'),
- meta: { requiresAuth: true, title: '内容管理', icon: 'Document' }
- },
- {
- path: 'system',
- name: 'System',
- meta: { requiresAuth: true, title: '系统管理', icon: 'Setting' },
- redirect: '/system/admin',
- children: [
- {
- path: 'admin',
- name: 'Admin',
- component: () => import('@/views/admin/index.vue'),
- meta: { requiresAuth: true, title: '管理员管理', icon: 'Avatar' }
- },
- {
- path: 'user-category',
- name: 'UserCategory',
- component: () => import('@/views/system/user-category/index.vue'),
- meta: { requiresAuth: true, title: '用户类别', icon: 'Collection' }
- },
- {
- path: 'log',
- name: 'Log',
- component: () => import('@/views/log/index.vue'),
- meta: { requiresAuth: true, title: '系统日志', icon: 'Document' }
- }
- ]
- }
- ]
- },
- {
- path: '/404',
- name: '404',
- component: () => import('@/views/404.vue'),
- meta: { requiresAuth: false, title: '页面不存在' }
- },
- // 未匹配到的路由重定向到 404
- {
- path: '/:pathMatch(.*)*',
- redirect: '/404'
- }
- ]
- const router = createRouter({
- history: createWebHashHistory(),
- routes
- })
- // 全局路由守卫
- router.beforeEach((to, from, next) => {
- // 设置页面标题
- if (to.meta?.title) {
- document.title = `${to.meta.title} - 艾灸椅管理后台`
- }
- const token = getToken()
- const requiresAuth = to.meta?.requiresAuth !== false // 默认需要登录
- if (requiresAuth && !token) {
- // 需要登录但未登录,跳转到登录页
- next({ path: '/login', query: { redirect: to.fullPath } })
- } else if (to.path === '/login' && token) {
- // 已登录用户访问登录页,跳转到首页
- next('/')
- } else {
- next()
- }
- })
- export default router
|