Files
Atlas/web/src/router/index.ts
T
renjue 2b020bb782
CI / docker (push) Successful in 2m58s
实现 Atlas AI 平台一期能力并完成品牌化改造。
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 23:35:19 +08:00

61 lines
2.0 KiB
TypeScript

import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import UserLayout from '@/layouts/UserLayout.vue'
import AdminLayout from '@/layouts/AdminLayout.vue'
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/',
component: UserLayout,
meta: { public: true },
children: [
{ path: '', redirect: '/chat' },
{ path: 'chat', name: 'chat', component: () => import('@/views/ChatView.vue') },
{ path: 'image', name: 'image', component: () => import('@/views/ImageStudioView.vue') },
{ path: 'image/text', redirect: '/image' },
{ path: 'image/edit', redirect: '/image' },
{ path: 'history', name: 'history', component: () => import('@/views/HistoryView.vue') },
],
},
{
path: '/admin/login',
name: 'admin-login',
component: () => import('@/views/LoginView.vue'),
meta: { public: true },
},
{
path: '/admin',
component: AdminLayout,
children: [
{ path: '', name: 'admin-dashboard', component: () => import('@/views/AdminDashboardView.vue') },
{ path: 'providers', name: 'admin-providers', component: () => import('@/views/AdminProvidersView.vue') },
{ path: 'history', name: 'admin-history', component: () => import('@/views/AdminHistoryView.vue') },
{ path: 'logs', redirect: '/admin/history' },
{ path: 'settings', name: 'admin-settings', component: () => import('@/views/SettingsView.vue') },
],
},
{ path: '/login', redirect: '/admin/login' },
],
})
router.beforeEach(async (to) => {
if (to.meta.public) return true
if (!to.path.startsWith('/admin')) return true
const auth = useAuthStore()
if (auth.isLoggedIn()) return true
try {
const res = await fetch('/api/v1/auth/status')
const data = await res.json()
if (!data.enabled) {
auth.token = 'disabled'
return true
}
} catch { /* ignore */ }
return '/admin/login'
})
export default router