优化工作-1
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user