feat: 实现后台管理前端全部页面与登录布局

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 16:52:41 +08:00
co-authored by Cursor
parent fa61840cfb
commit 5fa84f346b
40 changed files with 4481 additions and 1 deletions
+61
View File
@@ -0,0 +1,61 @@
import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router';
import { useAuthStore } from '@/stores/auth';
import { loadingBar } from '@/utils/feedback';
import MainLayout from '@/layouts/MainLayout.vue';
export const routes: RouteRecordRaw[] = [
{
path: '/login',
name: 'login',
component: () => import('@/views/Login.vue'),
meta: { public: true },
},
{
path: '/',
component: MainLayout,
redirect: '/dashboard',
children: [
{ path: 'dashboard', name: 'dashboard', component: () => import('@/views/Dashboard.vue') },
{ path: 'templates', name: 'templates', component: () => import('@/views/Templates.vue') },
{ path: 'artworks', name: 'artworks', component: () => import('@/views/Artworks.vue') },
{ path: 'artworks/:id', name: 'artwork-detail', component: () => import('@/views/ArtworkEdit.vue') },
{ path: 'trace-codes', name: 'traceCodes', component: () => import('@/views/TraceCodes.vue') },
{ path: 'outbound', name: 'outbound', component: () => import('@/views/Outbound.vue') },
{ path: 'query-logs', name: 'queryLogs', component: () => import('@/views/QueryLogs.vue') },
{ path: 'users', name: 'users', component: () => import('@/views/Users.vue') },
{ path: 'settings', name: 'settings', component: () => import('@/views/Settings.vue') },
{ path: 'profile', name: 'profile', component: () => import('@/views/Profile.vue') },
],
},
{ path: '/:pathMatch(.*)*', redirect: '/dashboard' },
];
const router = createRouter({
history: createWebHashHistory(),
routes,
});
router.beforeEach(async (to) => {
loadingBar.start();
const auth = useAuthStore();
if (to.meta.public) {
if (auth.isLoggedIn && to.name === 'login') return { name: 'dashboard' };
return true;
}
if (!auth.isLoggedIn) {
return { name: 'login' };
}
if (!auth.user) {
try {
await auth.fetchProfile();
} catch {
auth.logout();
return { name: 'login' };
}
}
return true;
});
router.afterEach(() => loadingBar.finish());
export default router;