From fa2f283da4e41f273e52a972e6e5e894ad849094 Mon Sep 17 00:00:00 2001 From: geyun <1556375442@qq.com> Date: Mon, 10 Nov 2025 16:33:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E6=97=B6=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=9A=84bug=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 24 +++++++++++++++++++++--- modal.html | 3 +-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 713fc13..4da2d74 100755 --- a/index.html +++ b/index.html @@ -1312,6 +1312,11 @@ } chatInput.value = ""; + if (controller) { + controller.abort(); + controller = null; + + } if (!sendBtnImg.classList.contains('none')) { sendBtnImg.classList.add('none'); stopBtn.classList.remove('none') @@ -1362,7 +1367,14 @@ while (true) { const { done, value } = await reader.read(); - if (done) break; + console.log(done, value, 'done') + if (done) { + const sendBtnImg = document.querySelector('#sendBtn img'); + const stopBtn = document.querySelector('#stopBtn'); + sendBtnImg.classList.add('none'); + stopBtn.classList.remove('none'); + break; + }; buffer += decoder.decode(value, { stream: true }); let lines = buffer.split("\n"); @@ -1373,8 +1385,14 @@ if (!line.startsWith("data:")) continue; const data = line.slice(5).trim(); - if (data === "[DONE]") { + console.log("完成回答", data) + if (data == "[DONE]") { + console.log("完成回答") // 更新聊天滚动条 + const sendBtnImg = document.querySelector('#sendBtn img'); + const stopBtn = document.querySelector('#stopBtn'); + sendBtnImg.classList.remove('none'); + stopBtn.classList.add('none'); setTimeout(scrollToBottom, 0); // chatMessages.scrollTop = chatMessages.scrollHeight; return; @@ -1391,7 +1409,7 @@ // } if (obj.content && obj.type !== "title") { for (const char of obj.content) { - await new Promise(r => setTimeout(r, 20)); // 控制字速 + await new Promise(r => setTimeout(r, 5)); // 控制字速 aiMsg.content += char; msgDiv.innerHTML = marked.parse(aiMsg.content); diff --git a/modal.html b/modal.html index e5a5d63..15e89e6 100644 --- a/modal.html +++ b/modal.html @@ -281,7 +281,6 @@ background-size: cover; background-repeat: no-repeat; padding: 10px 0 20px 0; - ; } /* 先给表格四列添加细微分色(可按需移除) */ @@ -333,7 +332,7 @@