From e72531cfb78746361f98267aa6d88fcb661474ce Mon Sep 17 00:00:00 2001 From: zoujing Date: Thu, 26 Mar 2026 00:10:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=95=BF=E6=96=87=E6=9C=AC=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages.json | 10 +++ .../components/chat/ChatMainList/index.vue | 84 ++++++++++++------- .../module/AnswerComponent/index.vue | 21 +++-- src/pages/long-answer/index.vue | 18 ++++ 4 files changed, 100 insertions(+), 33 deletions(-) create mode 100644 src/pages/long-answer/index.vue diff --git a/src/pages.json b/src/pages.json index f750c35..2927fe3 100644 --- a/src/pages.json +++ b/src/pages.json @@ -33,6 +33,16 @@ "navigationBarTextStyle": "black" } } + , + { + "path": "pages/long-answer/index", + "style": { + "navigationStyle": "custom", + "backgroundColor": "#FFFFFF", + "navigationBarBackgroundColor": "#FFFFFF", + "navigationBarTextStyle": "black" + } + } ], "subPackages": [ { diff --git a/src/pages/index/components/chat/ChatMainList/index.vue b/src/pages/index/components/chat/ChatMainList/index.vue index b0578b3..595c64f 100644 --- a/src/pages/index/components/chat/ChatMainList/index.vue +++ b/src/pages/index/components/chat/ChatMainList/index.vue @@ -19,31 +19,31 @@ @@ -473,25 +473,32 @@ const handleWebSocketMessage = (data) => { return; } - // 确保消息内容是字符串类型 - if (data.content && typeof data.content !== "string") { - try { - data.content = JSON.stringify(data.content); - } catch (e) { - data.content = String(data.content); - } - } - - // 优先使用 messageId 进行匹配 - const msgId = data.messageId || data.id || data.msgId || data.replyMessageId; let aiMsgIndex = -1; - if (msgId && pendingMap.has(msgId)) { - aiMsgIndex = pendingMap.get(msgId); - } else if (!msgId && currentSessionMessageId && pendingMap.has(currentSessionMessageId)) { - // 服务端未返回 messageId 的场景:优先使用当前会话的 messageId 映射 + if (currentSessionMessageId && pendingMap.has(currentSessionMessageId)) { aiMsgIndex = pendingMap.get(currentSessionMessageId); + if (aiMsgIndex >= 0 && aiMsgIndex < chatMsgList.value.length) { + const item = chatMsgList.value[aiMsgIndex]; + if (item && item.msgType === MessageRole.AI && + item.replyMessageId.length > 0 && data.replyMessageId && + item.replyMessageId !== data.replyMessageId) { + // 已经存在对应的AI消息项,继续使用 + const aiMsg = { + msgId: `msg_${chatMsgList.value.length}`, + msgType: MessageRole.AI, + msg: "", + isLoading: false, + messageId: currentSessionMessageId, + replyMessageId: '', + componentName: "", + title: "", + finish: false, + }; + chatMsgList.value.push(aiMsg); + aiMsgIndex = chatMsgList.value.length - 1; + } + } } else { - // 向后搜索最近的 AI 消息 + // 向后搜索最近的 AI 消息(回退逻辑) for (let i = chatMsgList.value.length - 1; i >= 0; i--) { if (chatMsgList.value[i] && chatMsgList.value[i].msgType === MessageRole.AI) { aiMsgIndex = i; @@ -504,6 +511,20 @@ const handleWebSocketMessage = (data) => { } } + // replyMessageId + if(data.replyMessageId) { + chatMsgList.value[aiMsgIndex].replyMessageId = data.replyMessageId; + } + + // 确保消息内容是字符串类型 + if (data.content && typeof data.content !== "string") { + try { + data.content = JSON.stringify(data.content); + } catch (e) { + data.content = String(data.content); + } + } + // 直接拼接内容到对应 AI 消息 if (data.content) { if (chatMsgList.value[aiMsgIndex].isLoading) { @@ -522,15 +543,18 @@ const handleWebSocketMessage = (data) => { chatMsgList.value[aiMsgIndex].finish = true; const msg = chatMsgList.value[aiMsgIndex].msg; if (!msg || chatMsgList.value[aiMsgIndex].isLoading) { - chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试"; - chatMsgList.value[aiMsgIndex].isLoading = false; - if (data.toolCall) { + // 如果服务器返回了 componentName 或 toolCall,应保留空消息以供组件渲染;否则显示错误占位 + if (data.toolCall || data.componentName) { chatMsgList.value[aiMsgIndex].msg = ""; + } else { + chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试"; } + chatMsgList.value[aiMsgIndex].isLoading = false; } // 处理组件调用 if (data.componentName) { + chatMsgList.value[aiMsgIndex].title = data.content; chatMsgList.value[aiMsgIndex].componentName = data.componentName; } @@ -558,6 +582,8 @@ const handleWebSocketMessage = (data) => { isSessionActive.value = false; // 清理当前会话的 messageId,避免保留陈旧 id resetMessageState(); + + nextTick(() => scrollToBottom()); } }; @@ -763,7 +789,9 @@ const sendChat = async (message, isInstruct = false) => { msg: "加载中", isLoading: true, messageId: currentSessionMessageId, + replyMessageId: '', componentName: "", + title: "", finish: false, }; chatMsgList.value.push(aiMsg); diff --git a/src/pages/index/components/module/AnswerComponent/index.vue b/src/pages/index/components/module/AnswerComponent/index.vue index f1c234a..dc84818 100644 --- a/src/pages/index/components/module/AnswerComponent/index.vue +++ b/src/pages/index/components/module/AnswerComponent/index.vue @@ -5,15 +5,15 @@ - 游玩划重点 + {{ title }} - {{ answerText }} + - - 查看完整攻略 + + 查看详情 @@ -22,12 +22,17 @@