stdproject/frontend/src/router/index.ts

114 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-05-30 13:43:31 +08:00
import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/store/user'
// 路由配置
2025-06-07 09:22:52 +08:00
const routes:any = [
2025-05-30 13:43:31 +08:00
{
path: '/',
redirect: '/dashboard'
},
2025-06-07 09:22:52 +08:00
// 登录页面路由配置
2025-05-30 13:43:31 +08:00
{
path: '/login',
name: 'Login',
2025-06-07 09:22:52 +08:00
component: () => import('@/data-public/Login.vue'), // 使用标准组件路径
2025-05-30 13:43:31 +08:00
meta: {
title: '登录',
requiresAuth: false
}
},
{
path: '/dashboard',
name: 'Dashboard',
2025-06-07 09:22:52 +08:00
component: () => import('@/data-public/Dashboard.vue'),
2025-05-30 13:43:31 +08:00
meta: {
title: '仪表板',
requiresAuth: true
}
},
{
path: '/users',
name: 'Users',
2025-06-07 09:22:52 +08:00
component: () => import('@/data-public/Users.vue'),
2025-05-30 13:43:31 +08:00
meta: {
title: '用户管理',
requiresAuth: true
}
},
{
path: '/roles',
name: 'Roles',
2025-06-07 09:22:52 +08:00
component: () => import('@/data-public/Roles.vue'),
2025-05-30 13:43:31 +08:00
meta: {
title: '角色管理',
requiresAuth: true
}
},
{
path: '/organizations',
name: 'Organizations',
2025-06-07 09:22:52 +08:00
component: () => import('@/data-public/Organizations.vue'),
2025-05-30 13:43:31 +08:00
meta: {
title: '组织管理',
requiresAuth: true
}
},
{
path: '/dictionaries',
name: 'Dictionaries',
2025-06-07 09:22:52 +08:00
component: () => import('@/data-public/Dictionaries.vue'),
2025-05-30 13:43:31 +08:00
meta: {
title: '字典管理',
requiresAuth: true
}
},
2025-05-30 16:20:02 +08:00
{
path: '/FormCreateDesigner',
name: 'FormCreateDesigner',
2025-06-07 09:22:52 +08:00
component: () => import('@/data-public/FormCreateDesigner.vue'),
2025-05-30 16:20:02 +08:00
meta: {
title: '字典管理',
requiresAuth: true
}
},
2025-05-30 13:43:31 +08:00
{
path: '/:pathMatch(.*)*',
2025-05-30 14:40:25 +08:00
name: '404',
2025-06-07 09:22:52 +08:00
component: () => import('@/data-public/error-page/404.vue'),
2025-05-30 13:43:31 +08:00
meta: {
title: '页面未找到',
requiresAuth: false
}
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
// 路由守卫
router.beforeEach((to, from, next) => {
const userStore = useUserStore()
// 设置页面标题
document.title = to.meta.title ? `${to.meta.title} - StdProject` : 'StdProject'
// 检查是否需要认证
if (to.meta.requiresAuth) {
if (userStore.isAuthenticated) {
next()
} else {
next('/login')
}
} else {
// 如果已登录且访问登录页,重定向到仪表板
if (to.path === '/login' && userStore.isAuthenticated) {
next('/dashboard')
} else {
next()
}
}
})
export default router