stdproject/frontend/src/router/index.ts
2025-06-20 14:33:16 +08:00

159 lines
3.4 KiB
TypeScript

import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/store/user'
// 路由配置
const routes:any = [
{
path: '/',
redirect: '/AppFrame'
},
// 登录页面路由配置
{
path: '/login',
name: 'Login',
component: () => import('@/data-public/Login.vue'), // 使用标准组件路径
meta: {
title: '登录',
requiresAuth: false
}
},
{
path: '/dashboard',
name: 'Dashboard',
component: () => import('@/data-public/Dashboard.vue'),
meta: {
title: '仪表板',
requiresAuth: true
}
},
{
path: '/users',
name: 'Users',
component: () => import('@/data-public/Users.vue'),
meta: {
title: '用户管理',
requiresAuth: true
}
},
{
path: '/roles',
name: 'Roles',
component: () => import('@/data-public/Roles.vue'),
meta: {
title: '角色管理',
requiresAuth: true
}
},
{
path: '/organizations',
name: 'Organizations',
component: () => import('@/data-public/Organizations.vue'),
meta: {
title: '组织管理',
requiresAuth: true
}
},
{
path: '/dictionaries',
name: 'Dictionaries',
component: () => import('@/data-public/Dictionaries.vue'),
meta: {
title: '字典管理',
requiresAuth: true
}
},
// {
// path: '/FormCreateDesigner',
// name: 'FormCreateDesigner',
// component: () => import('@/data-public/FormCreateDesigner.vue'),
// meta: {
// title: '字典管理',
// requiresAuth: true
// }
// }
{
path: '/FormCreate',
name: 'FormCreate',
component: () => import('@/views/BuiltInPage/FormCreate.vue'),
meta: {
title: '表单管理',
requiresAuth: true
}
}
,{
path: '/visualization',
name: 'visualization',
component: () => import('@/data-visualization/index.vue'),
meta: {
title: '数据大屏',
requiresAuth: true
}
},
{
path: '/:pathMatch(.*)*',
name: '404',
component: () => import('@/data-public/error-page/404.vue'),
meta: {
title: '页面未找到',
requiresAuth: false
}
},
{
path: '/Permission',
name: 'Permission',
component: () => import('@/views/system/manage/index.vue'),
meta: {
title: '权限管理',
requiresAuth: true
}
},
{
path: '/UserLogin',
name: 'UserLogin',
component: () => import('@/views/system/userlogin/login_container.vue'),
meta: {
title: '登录',
requiresAuth: false
}
},
{
path: '/AppFrame',
name: 'AppFrame',
component: () => import('@/views/system/userlogin/appframe_container.vue'),
meta: {
title: '首页',
requiresAuth: true
}
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
// 路由守卫
router.beforeEach((to, from, next) => {
const userStore = useUserStore()
// 设置页面标题
document.title = to.meta.title ? `${to.meta.title} - StdProject` : 'StdProject'
const token = localStorage.getItem('token') || ''
// 检查是否需要认证
if (to.meta.requiresAuth) {
if (!!token) {
next()
} else {
next('/UserLogin') // 未认证重定向到登录页
}
} else {
// 如果已登录且访问登录页,重定向到仪表板
if (to.path === '/UserLogin' && userStore.isAuthenticated) {
next('/AppFrame')
} else {
next()
}
}
})
export default router