debug: 修复时序问题导致的获取会话列表为空的问题

This commit is contained in:
肖应宇 2026-03-09 16:45:01 +08:00
parent b2bbba8db6
commit 9ca89209af
1 changed files with 17 additions and 0 deletions

View File

@ -115,6 +115,23 @@ export const conversationApi = {
*/
async fetchConversations(): Promise<Conversation[]> {
const authStore = useAuthStore();
// 等待 authStore 初始化完成
if (!authStore.isInitialized) {
await new Promise<void>((resolve) => {
const unwatch = authStore.$subscribe(() => {
if (authStore.isInitialized) {
unwatch();
resolve();
}
});
// 如果已经初始化了,立即 resolve
if (authStore.isInitialized) {
unwatch();
resolve();
}
});
}
const userId = authStore.userId;
// 构建 URL添加 user_id 查询参数