Files
claude-relay-service/web/admin-spa/src/router/index.js
shaw 414856f152 feat: 全新的Vue3管理后台(admin-spa)和路由重构
🎨 新增功能:
- 使用Vue3 + Vite构建的全新管理后台界面
- 支持Tab切换的API统计页面(统计查询/使用教程)
- 优雅的胶囊式Tab切换设计
- 同步了PR #106的会话窗口管理功能
- 完整的响应式设计和骨架屏加载状态

🔧 路由调整:
- 新版管理后台部署在 /admin-next/ 路径
- 将根路径 / 重定向到 /admin-next/api-stats
- 将 /web 页面路由重定向到新版,保留 /web/auth/* 认证路由
- 将 /apiStats 页面路由重定向到新版,保留API端点

🗑️ 清理工作:
- 删除旧版 web/admin/ 静态文件
- 删除旧版 web/apiStats/ 静态文件
- 清理相关的文件服务代码

🐛 修复问题:
- 修复重定向循环问题
- 修复环境变量配置
- 修复路由404错误
- 优化构建配置

🚀 生成方式:使用 Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-29 12:40:51 +08:00

122 lines
2.6 KiB
JavaScript

import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { APP_CONFIG } from '@/config/app'
// 路由懒加载
const LoginView = () => import('@/views/LoginView.vue')
const MainLayout = () => import('@/components/layout/MainLayout.vue')
const DashboardView = () => import('@/views/DashboardView.vue')
const ApiKeysView = () => import('@/views/ApiKeysView.vue')
const AccountsView = () => import('@/views/AccountsView.vue')
const TutorialView = () => import('@/views/TutorialView.vue')
const SettingsView = () => import('@/views/SettingsView.vue')
const ApiStatsView = () => import('@/views/ApiStatsView.vue')
const routes = [
{
path: '/',
redirect: '/api-stats'
},
{
path: '/login',
name: 'Login',
component: LoginView,
meta: { requiresAuth: false }
},
{
path: '/api-stats',
name: 'ApiStats',
component: ApiStatsView,
meta: { requiresAuth: false }
},
{
path: '/dashboard',
component: MainLayout,
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'Dashboard',
component: DashboardView
}
]
},
{
path: '/api-keys',
component: MainLayout,
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'ApiKeys',
component: ApiKeysView
}
]
},
{
path: '/accounts',
component: MainLayout,
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'Accounts',
component: AccountsView
}
]
},
{
path: '/tutorial',
component: MainLayout,
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'Tutorial',
component: TutorialView
}
]
},
{
path: '/settings',
component: MainLayout,
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'Settings',
component: SettingsView
}
]
}
]
const router = createRouter({
history: createWebHistory(APP_CONFIG.basePath),
routes
})
// 路由守卫
router.beforeEach((to, from, next) => {
const authStore = useAuthStore()
console.log('路由导航:', {
to: to.path,
from: from.path,
requiresAuth: to.meta.requiresAuth,
isAuthenticated: authStore.isAuthenticated
})
// API Stats 页面不需要认证,直接放行
if (to.path === '/api-stats' || to.path.startsWith('/api-stats')) {
next()
} else if (to.meta.requiresAuth && !authStore.isAuthenticated) {
next('/login')
} else if (to.path === '/login' && authStore.isAuthenticated) {
next('/dashboard')
} else {
next()
}
})
export default router