import { createRouter, createWebHistory } from 'vue-router' import { useAuthStore } from '@/stores/auth' const router = createRouter({ history: createWebHistory(), routes: [ { path: '/login', name: 'login', component: () => import('@/views/LoginView.vue'), meta: { public: true }, }, { // 网页 VNC 独立页:从实例详情新标签页打开,无侧栏布局 path: '/console/vnc/:cfgId/:instanceId', name: 'vnc-console', component: () => import('@/views/VncConsoleView.vue'), }, { path: '/', component: () => import('@/layouts/AppLayout.vue'), children: [ { path: '', name: 'overview', component: () => import('@/views/OverviewView.vue') }, { path: 'tenants', name: 'tenants', component: () => import('@/views/TenantListView.vue') }, { path: 'tenants/:id', name: 'tenant-detail', component: () => import('@/views/TenantDetailView.vue'), }, { path: 'instances', name: 'instances', component: () => import('@/views/InstanceListView.vue'), }, { path: 'instances/:cfgId/:instanceId', name: 'instance-detail', component: () => import('@/views/InstanceDetailView.vue'), }, { path: 'network', name: 'network', component: () => import('@/views/NetworkListView.vue') }, { path: 'network/:cfgId/vcns/:vcnId', name: 'vcn-detail', component: () => import('@/views/VcnDetailView.vue'), }, { path: 'storage/boot-volumes', name: 'boot-volumes', component: () => import('@/views/BootVolumeListView.vue'), }, { path: 'storage/objects', name: 'object-storage', component: () => import('@/views/ObjectStorageView.vue'), }, { path: 'tasks', name: 'tasks', component: () => import('@/views/TaskListView.vue') }, { path: 'ai-gateway', name: 'ai-gateway', component: () => import('@/views/AiGatewayView.vue'), }, { path: 'tasks/:taskId', name: 'task-detail', component: () => import('@/views/TaskDetailView.vue'), }, { path: 'proxies', name: 'proxies', component: () => import('@/views/ProxyListView.vue'), }, { path: 'logs', name: 'logs', component: () => import('@/views/LogsView.vue'), }, { path: 'settings', name: 'settings', component: () => import('@/views/SettingsView.vue'), }, ], }, { // 全局限速拦截页:request 层收到非登录接口的 429 时跳转 path: '/blocked', name: 'blocked', component: () => import('@/views/errors/BlockedView.vue'), meta: { public: true }, }, { path: '/:pathMatch(.*)*', name: 'not-found', component: () => import('@/views/errors/NotFoundView.vue'), meta: { public: true }, }, ], }) router.beforeEach((to) => { const auth = useAuthStore() if (!to.meta.public && !auth.isAuthed()) return { name: 'login', query: { redirect: to.fullPath } } if (to.name === 'login' && auth.isAuthed()) return { name: 'overview' } return true }) export default router