diff --git a/index.html b/index.html index 93cd323..713fc13 100755 --- a/index.html +++ b/index.html @@ -739,6 +739,15 @@ cursor: pointer; } + + .stopBtn { + width: 36px; + height: 36px; + } + + .none { + display: none; + } @@ -883,6 +892,15 @@
+
+ + + +
+
@@ -910,6 +928,7 @@ const chatInput = document.getElementById("chatInput"); const fileInput = document.getElementById("fileInput"); const chatList = document.getElementById("chatList"); + let controller = null; let sessIdList = []; let isUpload = {}; let hasImage = false; @@ -1253,11 +1272,14 @@ function sendMessage(isPre) { - console.log("发送消息"); + console.log("发送消息1122"); + const sendBtnImg = document.querySelector('#sendBtn img'); + const stopBtn = document.querySelector('#stopBtn'); + + // 2. 先判断 stopBtn 的状态,再控制 sendBtn img(逻辑更清晰) + if (!activeChatId) { - newChat(); - } // if (sessIdList.length == 0) { // return; @@ -1290,6 +1312,10 @@ } chatInput.value = ""; + if (!sendBtnImg.classList.contains('none')) { + sendBtnImg.classList.add('none'); + stopBtn.classList.remove('none') + } getAiResponse(imgUrl); } @@ -1312,11 +1338,19 @@ sendParam.imageBase64 = img; // sendParam.userId= encodedUserId; sendParam.userId = decodeURIComponent(Number(escape(atob(encodedUserId)))); + // ✅ 创建 AbortController + controller = new AbortController(); const res = await fetch("http://1.95.137.212:30009/analyze", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(sendParam), + signal: controller.signal, // ✅ 加上 signal + }).catch(err => { + console.log("✅ 流被中断:", err.name); + return null; }); + if (!res) return; // 流已中断则直接退出 + sendParam.imageBase64 = ''; @@ -1492,8 +1526,10 @@ sendMessage(); // 调用发送函数 } }); - document.getElementById("sendBtn").addEventListener("click", function () { + document.querySelector("#sendBtn img").addEventListener("click", function () { + console.log("发送信息11") sendMessage(); + }); document.getElementById("sendFileBtn").addEventListener("click", function () { handleSendFile() @@ -1590,6 +1626,18 @@ toggleBtn.style.left = "190px"; // 展开后 } } + document.getElementById("stopBtn").addEventListener("click", () => { + const sendBtnImg = document.querySelector('#sendBtn img'); + const stopBtn = document.querySelector('#stopBtn'); + if (controller) { + controller.abort(); + controller = null; + if (sendBtnImg.classList.contains('none')) { + sendBtnImg.classList.remove('none'); + stopBtn.classList.add('none') + } + } + });