fix: 统一管理后台 401 与加载失败处理

This commit is contained in:
Nixevol
2026-09-30 16:22:48 +08:00
parent 1cb562fb71
commit ed788fbb74
17 changed files with 473 additions and 47 deletions
+15 -1
View File
@@ -2,8 +2,22 @@ import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
import { router } from "./router";
import { setUnauthorizedHandler } from "./api/http";
import { useAuthStore } from "./stores/auth";
const app = createApp(App);
app.use(createPinia());
const pinia = createPinia();
app.use(pinia);
app.use(router);
setUnauthorizedHandler((redirect) => {
const auth = useAuthStore();
auth.clearSession();
if (router.currentRoute.value.meta.public) {
return;
}
const target = redirect.startsWith("/login") ? "/overview" : redirect || "/overview";
void router.replace({ name: "login", query: { redirect: target } });
});
app.mount("#app");