diff --git a/pages/chat/ChatMainList.vue b/pages/chat/ChatMainList.vue index 979c833..df480b2 100644 --- a/pages/chat/ChatMainList.vue +++ b/pages/chat/ChatMainList.vue @@ -490,6 +490,9 @@ // 停止请求函数 const stopRequest = () => { if (requestTaskRef.value && requestTaskRef.value.abort) { + // 标记请求已中止,用于过滤后续可能到达的数据 + requestTaskRef.value.isAborted = true; + // 中止请求 requestTaskRef.value.abort(); // 重置状态 isSessionActive.value = false; @@ -507,6 +510,8 @@ typeWriterTimer = null; } setTimeoutScrollToBottom() + // 清空请求引用 + requestTaskRef.value = null; } } diff --git a/request/api/AgentChatStream.js b/request/api/AgentChatStream.js index 0cba5cf..d972d8b 100644 --- a/request/api/AgentChatStream.js +++ b/request/api/AgentChatStream.js @@ -59,7 +59,8 @@ function agentChatStream(params, onChunk) { }); requestTask.onChunkReceived(res => { - if (hasError) return; + // 检查请求是否已被中止 + if (hasError || requestTask.isAborted) return; const base64 = uni.arrayBufferToBase64(res.data); let data = ''; try {