import { createRouter, createWebHistory } from 'vue-router' import AdminLayout from '@/layouts/AdminLayout.vue' const routes = [ { path: '/login', redirect: to => ({ path: '/', query: to.query }) }, { path: '/', name: 'Landing', component: () => import('@/views/Landing.vue') }, { path: '/dashboard', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Dashboard', component: () => import('@/views/Dashboard.vue'), meta: { title: '概览' } }, ] }, { path: '/users', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Users', component: () => import('@/views/Users.vue'), meta: { title: '用户' } }, ] }, { path: '/stats', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Stats', component: () => import('@/views/Stats.vue'), meta: { title: '统计' } }, ] }, { path: '/logs', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Logs', component: () => import('@/views/Logs.vue'), meta: { title: '日志' } }, ] }, { path: '/payments', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Payments', component: () => import('@/views/Payments.vue'), meta: { title: '支付管理' } }, ] }, { path: '/credits', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Credits', component: () => import('@/views/CreditManagement.vue'), meta: { title: '信用管理' } }, ] }, { path: '/config', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Config', component: () => import('@/views/Config.vue'), meta: { title: '配置' } }, ] }, { path: '/quota', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Quota', component: () => import('@/views/Quota.vue'), meta: { title: '翻译配额' } }, ] }, { path: '/certifications', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Certifications', component: () => import('@/views/Certifications.vue'), meta: { title: '认证审核' } }, ] }, { path: '/invoices', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'Invoices', component: () => import('@/views/Invoices.vue'), meta: { title: '发票管理' } }, ] }, { path: '/system/search-config', component: AdminLayout, meta: { requiresAuth: true }, children: [ { path: '', name: 'SearchConfig', component: () => import('@/views/SearchConfig.vue'), meta: { title: '搜索配置' } }, { path: 'ai-providers', name: 'AIProviders', component: () => import('@/views/AIProviders.vue'), meta: { title: 'AI 模型配置' } }, ] }, ] const router = createRouter({ history: createWebHistory('/admin/'), routes }) router.beforeEach((to, from, next) => { if (to.meta?.requiresAuth) { const token = localStorage.getItem('admin_token') if (!token) next({ name: 'Login', query: { redirect: to.fullPath } }) else next() } else { next() } }) export default router