import { createRouter, createWebHistory } from 'vue-router' import { useUserStore } from '@/store/user' // 路由配置 const routes:any = [ { path: '/', redirect: '/dashboard' }, // 登录页面路由配置 { 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/permissionset/index.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' // 检查是否需要认证 if (to.meta.requiresAuth) { next() // if (userStore.isAuthenticated) { // next() // } else { // next('/login') // } } else { // 如果已登录且访问登录页,重定向到仪表板 if (to.path === '/login' && userStore.isAuthenticated) { next('/dashboard') } else { next() } } }) export default router