优化工作-1

This commit is contained in:
yml2213
2026-06-05 07:41:52 +08:00
parent b7ec5e2755
commit 0b9b0b5ea7
17 changed files with 1807 additions and 127 deletions
+22 -3
View File
@@ -12,6 +12,7 @@ export const useSessionStore = defineStore("session", {
nickname: localStorage.getItem("nickname") || "",
avatarUrl: localStorage.getItem("avatar_url") || "",
realnameStatus: localStorage.getItem("realname_status") || "unknown",
_loadingMe: false, // 防止重复调用
}),
getters: {
isLoggedIn: (state) => Boolean(state.token),
@@ -33,9 +34,27 @@ export const useSessionStore = defineStore("session", {
return result;
},
async loadMe() {
const user = await fetchMe();
this.applyUser(user);
return user;
if (this._loadingMe) {
// 如果正在加载,等待完成
await new Promise((resolve) => {
const checkInterval = setInterval(() => {
if (!this._loadingMe) {
clearInterval(checkInterval)
resolve(true)
}
}, 50)
})
return
}
this._loadingMe = true
try {
const user = await fetchMe();
this.applyUser(user);
return user;
} finally {
this._loadingMe = false
}
},
async updateProfile(payload: { nickname: string; avatar_url: string }) {
const user = await updateMe(payload);