|
|
@ -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 += `<span class="result-content">${result}</span>`; |
|
|
|
|
|
|
|
// 使用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; |
|
|
|