feat: 优化发送消息的中断重连问题

This commit is contained in:
2026-01-08 14:46:44 +08:00
parent 5d98b76fd1
commit 7239313f0f

View File

@@ -581,18 +581,19 @@ const sendChat = (message, isInstruct = false) => {
initWebSocket(); initWebSocket();
// 短暂延迟后再次检查连接状态 // 短暂延迟后再次检查连接状态
setTimeout(() => { setTimeout(() => {
if (webSocketManager && webSocketManager.isConnected()) { const connected = webSocketManager && webSocketManager.isConnected();
isSessionActive.value = connected;
// 更新AI消息状态
const aiMsgIndex = chatMsgList.value.length - 1;
if (aiMsgIndex >= 0 && chatMsgList.value[aiMsgIndex].msgType === MessageRole.AI) {
chatMsgList.value[aiMsgIndex].msg = connected ? "" : "发送消息失败,请重试";
chatMsgList.value[aiMsgIndex].isLoading = connected;
}
if (connected) {
// 连接成功后重新发送消息 // 连接成功后重新发送消息
sendChat(message, isInstruct); sendChat(message, isInstruct);
} else { } else {
console.error("WebSocket重新初始化失败"); console.error("WebSocket重新初始化失败");
isSessionActive.value = false;
// 更新AI消息状态为失败
const aiMsgIndex = chatMsgList.value.length - 1;
if (aiMsgIndex >= 0 && chatMsgList.value[aiMsgIndex].msgType === MessageRole.AI) {
chatMsgList.value[aiMsgIndex].msg = "发送消息失败,请重试";
chatMsgList.value[aiMsgIndex].isLoading = false;
}
} }
}, 1000); }, 1000);
return; return;