From d6ab956951e7da903d3cb40808fff11ee0f12a81 Mon Sep 17 00:00:00 2001 From: donghaolin <17667510818@163.com> Date: Tue, 25 Feb 2025 11:44:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99=E6=98=AF=E5=8A=A0=E4=BA=86=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/chat.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/views/chat.vue b/src/views/chat.vue index 944943a..ca68658 100644 --- a/src/views/chat.vue +++ b/src/views/chat.vue @@ -4,6 +4,7 @@ import { useUserInfo } from '../store/userPermissionCode' import axios from 'axios' import { ElMessage } from 'element-plus'; import { Loading, Position } from '@element-plus/icons-vue'; // 引入图标组件 +import { marked } from 'marked'; // 引入marked库 const { getQueryVariable } = useUserInfo() // 假设 getSessionId 已经正确定义 @@ -17,7 +18,7 @@ const fnGetToken = () => { setTimeout(() => { fnGetToken() }, 800) -const token = localStorage.getItem('localToken') + // 验证 token const validateToken = async () => { const token = localStorage.getItem('localToken') @@ -34,7 +35,7 @@ const sessionId = ref(localStorage.getItem('sessionId') || {}); const add = async () => { try { const result = await axios.post( - "http://2zhyw2.natappfree.cc/api/v1/chats/8b37cd9cf0c811efa4210242ac120003/completions", + "http://td7idg.natappfree.cc/api/v1/chats/8b37cd9cf0c811efa4210242ac120003/completions", {}, { headers: { @@ -132,7 +133,7 @@ const sendMessage = async () => { try { // 调用API获取回复 - const response = await fetch("http://2zhyw2.natappfree.cc/api/v1/chats/8b37cd9cf0c811efa4210242ac120003/completions", { + const response = await fetch("http://td7idg.natappfree.cc/api/v1/chats/8b37cd9cf0c811efa4210242ac120003/completions", { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ragflow-hkNjEwYjcwZjBlMDExZWZiYjYzMDI0Mm' }, body: JSON.stringify({ question: content, stream: false, session_id: sessionId.value }) @@ -160,6 +161,9 @@ const sendMessage = async () => { // } combinedContent += `${result}`; + // 使用marked库将Markdown转换为HTML + const markdownContent = marked(combinedContent); + // 添加初始空消息 const botMessageIndex = messages.value.length; messages.value.push({ @@ -171,8 +175,8 @@ const sendMessage = async () => { // 使用定时器逐个字符更新消息内容 let currentIndex = 0; const intervalId = setInterval(() => { - if (currentIndex < combinedContent.length) { - messages.value[botMessageIndex].content += combinedContent[currentIndex]; + if (currentIndex < markdownContent.length) { + messages.value[botMessageIndex].content += markdownContent[currentIndex]; scrollToBottom(); currentIndex++; } else { @@ -288,6 +292,7 @@ onMounted(async () => { /* 其他样式保持不变 */ .message-item.bot { justify-content: flex-start; /* 让机器人消息靠左对齐 */ + text-align: left; /* 新增:设置文本左对齐 */ } .chat-container { display: flex;