2026-04-28 11:33:17 +08:00
|
|
|
import { createRouter, createWebHistory } from "vue-router";
|
|
|
|
|
|
|
|
|
|
import { pinia } from "@/stores/pinia";
|
|
|
|
|
import { useAuthStore } from "@/stores/auth";
|
|
|
|
|
|
|
|
|
|
export const router = createRouter({
|
|
|
|
|
history: createWebHistory(),
|
|
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: "/login",
|
|
|
|
|
name: "login",
|
|
|
|
|
component: () => import("@/views/LoginView.vue"),
|
|
|
|
|
meta: { title: "登录" },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/",
|
|
|
|
|
component: () => import("@/layouts/AppShell.vue"),
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
children: [
|
2026-04-29 00:02:46 +08:00
|
|
|
{ path: "", redirect: "/admin-users" },
|
|
|
|
|
{
|
|
|
|
|
path: "admin-users",
|
|
|
|
|
name: "admin-users",
|
|
|
|
|
component: () => import("@/views/AdminUsersView.vue"),
|
|
|
|
|
meta: { title: "用户管理" },
|
|
|
|
|
},
|
2026-04-28 11:33:17 +08:00
|
|
|
{
|
|
|
|
|
path: "accounts",
|
|
|
|
|
name: "accounts",
|
|
|
|
|
component: () => import("@/views/AccountsView.vue"),
|
2026-04-29 00:02:46 +08:00
|
|
|
meta: { title: "操作员管理" },
|
2026-04-28 11:33:17 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "audits",
|
|
|
|
|
name: "audits",
|
|
|
|
|
component: () => import("@/views/AuditLogsView.vue"),
|
|
|
|
|
meta: { title: "审计日志" },
|
|
|
|
|
},
|
2026-04-29 17:10:17 +08:00
|
|
|
{
|
|
|
|
|
path: "site-domain-mappings",
|
|
|
|
|
name: "site-domain-mappings",
|
|
|
|
|
component: () => import("@/views/SiteDomainMappingsView.vue"),
|
|
|
|
|
meta: { title: "站点映射" },
|
|
|
|
|
},
|
2026-04-28 11:33:17 +08:00
|
|
|
{
|
|
|
|
|
path: "profile",
|
|
|
|
|
name: "profile",
|
|
|
|
|
component: () => import("@/views/ProfileView.vue"),
|
|
|
|
|
meta: { title: "个人资料" },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/:pathMatch(.*)*",
|
|
|
|
|
redirect: "/",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.beforeEach((to) => {
|
|
|
|
|
const auth = useAuthStore(pinia);
|
|
|
|
|
if (!auth.initialized) {
|
|
|
|
|
auth.hydrate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (to.meta.requiresAuth && !auth.isAuthenticated) {
|
|
|
|
|
return {
|
|
|
|
|
name: "login",
|
|
|
|
|
query: to.fullPath !== "/" ? { redirect: to.fullPath } : undefined,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (to.name === "login" && auth.isAuthenticated) {
|
2026-04-29 00:02:46 +08:00
|
|
|
return { name: "admin-users" };
|
2026-04-28 11:33:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.afterEach((to) => {
|
|
|
|
|
if (typeof document !== "undefined") {
|
|
|
|
|
const t = (to.meta.title as string | undefined) ?? "运营后台";
|
|
|
|
|
document.title = `${t} · 省心推`;
|
|
|
|
|
}
|
|
|
|
|
});
|