增加停止输出逻辑
This commit is contained in:
56
index.html
56
index.html
@@ -739,6 +739,15 @@
|
||||
cursor: pointer;
|
||||
|
||||
}
|
||||
|
||||
.stopBtn {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
}
|
||||
|
||||
.none {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -883,6 +892,15 @@
|
||||
</div>
|
||||
<div id="sendBtn">
|
||||
<img src="./img/upload.png" alt="" style="width:36px;height:36px">
|
||||
<div class="stopBtn none" id="stopBtn">
|
||||
<svg t="1762735469119" class="icon" viewBox="0 0 1024 1024" version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg" p-id="4603" width="36" height="36">
|
||||
<path
|
||||
d="M512 947.456A435.456 435.456 0 1 1 947.456 512 435.456 435.456 0 0 1 512 947.456z m0.4096-81.3056A353.8432 353.8432 0 1 0 158.72 512.3072a353.8944 353.8944 0 0 0 353.6896 353.8432zM407.7568 386.8672h208.4864a20.8384 20.8384 0 0 1 20.8384 20.7872v208.5888a20.8384 20.8384 0 0 1-20.8384 20.7872H407.7568a20.8384 20.8384 0 0 1-20.8384-20.7872V407.7568a20.8896 20.8896 0 0 1 20.8384-20.8896z"
|
||||
p-id="4604"></path>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user