feat: 实现管理后台 W1-W3 假数据界面

This commit is contained in:
Nixevol
2026-09-30 07:02:33 +08:00
parent 8dde564517
commit 1cff321f2a
33 changed files with 4773 additions and 31 deletions
+36
View File
@@ -0,0 +1,36 @@
import { defineStore } from "pinia";
import { computed, ref } from "vue";
import { fetchMe, login as apiLogin, logout as apiLogout } from "@/api/admin";
export const useAuthStore = defineStore("auth", () => {
const username = ref<string | null>(null);
const ready = ref(false);
const isLoggedIn = computed(() => username.value != null);
async function hydrate() {
try {
const me = await fetchMe(true);
username.value = me.username;
} catch {
username.value = null;
} finally {
ready.value = true;
}
}
async function login(user: string, password: string) {
const res = await apiLogin(user, password);
username.value = res.username;
}
async function logout() {
try {
await apiLogout();
} finally {
username.value = null;
}
}
return { username, ready, isLoggedIn, hydrate, login, logout };
});