From ead29615003846a8bab4ec693bbd04594408d478 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sun, 13 Apr 2025 15:51:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9B=E8=A1=8C=E5=9B=BE?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E5=AF=BC=E8=87=B4=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E6=BC=8F=E8=BF=87=E5=A4=9A=E5=AF=BC=E8=87=B4=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=AF=B9=E5=8E=86=E5=8F=B2=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E4=B8=8D=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/system/gen-chat.vue | 22 +++++++++++++++++++--- src/views/system/kbase-chat.vue | 26 ++++++++++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/views/system/gen-chat.vue b/src/views/system/gen-chat.vue index a93e304..97e514b 100644 --- a/src/views/system/gen-chat.vue +++ b/src/views/system/gen-chat.vue @@ -60,7 +60,7 @@ 🧑‍🎓
-
+
([]); // 用于存储过滤后的文件列表 const uploadFileVisible = ref(false); // 控制上传文件对话框的显示与隐藏 +const historyMsgHtml= ref([]); // 用于存储历史消息的HTML内容 -const renderMarkdown = (content: string) => { - return md.render(content); +const renderMarkdown = (message: Message, index:number) => { + if(message.finished == false){ + //console.log("not finished"); + return message.content; + } + if(historyMsgHtml.value[index]){ + //console.log("historyMsgHtml:", historyMsgHtml.value[index]); + //console.log("historyMsgHtml:", index); + //已经渲染过的消息,直接返回 + return historyMsgHtml.value[index]; + } + //console.log("new finish:"); + const html = md.render(message.content); + historyMsgHtml.value.push(html); + return html; }; const scrollToBottom = () => { @@ -626,6 +640,7 @@ const loadSession = async (session_id: number) => { const clearCurrent = () => { sessionID.value = 0; messages.length = 0; // 清空消息 + historyMsgHtml.value.length = 0; // 清空历史消息 sessionName.value = "新会话"; ElMessage.success("新会话已创建!可以开始聊天了"); }; @@ -649,6 +664,7 @@ const getShortenedName = (name: string) => { }; const getMessage = async (session_id: number) => { + historyMsgHtml.value.length = 0; // 清空历史消息 let result = {}; try { let req = { diff --git a/src/views/system/kbase-chat.vue b/src/views/system/kbase-chat.vue index 7af3c55..6a46131 100644 --- a/src/views/system/kbase-chat.vue +++ b/src/views/system/kbase-chat.vue @@ -60,7 +60,7 @@ 🧑‍🎓
-
+
([]); // 用于存储过滤后的文件列表 const uploadFileVisible = ref(false); // 控制上传文件对话框的显示与隐藏 - - const renderMarkdown = (content: string) => { - return md.render(content); - }; - + const historyMsgHtml= ref([]); // 用于存储历史消息的HTML内容 + +const renderMarkdown = (message: Message, index:number) => { + if(message.finished == false){ + //console.log("not finished"); + return message.content; + } + if(historyMsgHtml.value[index]){ + //console.log("historyMsgHtml:", historyMsgHtml.value[index]); + //console.log("historyMsgHtml:", index); + //已经渲染过的消息,直接返回 + return historyMsgHtml.value[index]; + } + //console.log("new finish:"); + const html = md.render(message.content); + historyMsgHtml.value.push(html); + return html; +}; const scrollToBottom = () => { let x = document.getElementsByClassName("chat-messages")[0]; if (!x) return; @@ -665,6 +678,7 @@ }; const getMessage = async (session_id: number) => { + historyMsgHtml.value.length = 0; // 清空历史消息 let result = {}; try { let req = {