diff --git a/src/services/conversationApi.ts b/src/services/conversationApi.ts index 9ac3aca..ec9e6e6 100644 --- a/src/services/conversationApi.ts +++ b/src/services/conversationApi.ts @@ -115,6 +115,23 @@ export const conversationApi = { */ async fetchConversations(): Promise { const authStore = useAuthStore(); + // 等待 authStore 初始化完成 + if (!authStore.isInitialized) { + await new Promise((resolve) => { + const unwatch = authStore.$subscribe(() => { + if (authStore.isInitialized) { + unwatch(); + resolve(); + } + }); + // 如果已经初始化了,立即 resolve + if (authStore.isInitialized) { + unwatch(); + resolve(); + } + }); + } + const userId = authStore.userId; // 构建 URL,添加 user_id 查询参数