diff --git a/src/pages/index/components/chat/ChatMainList/index.vue b/src/pages/index/components/chat/ChatMainList/index.vue index 653c8fd..bc51ac3 100644 --- a/src/pages/index/components/chat/ChatMainList/index.vue +++ b/src/pages/index/components/chat/ChatMainList/index.vue @@ -581,18 +581,19 @@ const sendChat = (message, isInstruct = false) => { initWebSocket(); // 短暂延迟后再次检查连接状态 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); } else { 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); return;