|
@@ -20,9 +20,10 @@
|
|
|
<button class="action-btn" @click="copyContent(message.content)">
|
|
|
<img src="@/assets/icon-copy.png" alt="复制">
|
|
|
</button>
|
|
|
- <!-- <button class="action-btn" @click="toggleFavorite(message.id)">
|
|
|
- <img src="@/assets/icon-star.png" alt="收藏">
|
|
|
- </button> -->
|
|
|
+ <button class="action-btn" @click="toggleFavorite(message)">
|
|
|
+ <img src="@/assets/icon-star.png" v-if="!message.isCollect" alt="收藏">
|
|
|
+ <img src="@/assets/icon-star-fill.svg" style="width: 20px;height: 20px;" v-else alt="已收藏">
|
|
|
+ </button>
|
|
|
<button class="action-btn reanswer" @click="reAnswer(message.id)">
|
|
|
<img src="@/assets/icon-reanswer.png" alt="重新回答">
|
|
|
<span>重新回答</span>
|
|
@@ -102,7 +103,7 @@ import { ref, onMounted, nextTick, watch } from 'vue'
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
import userAvatar from '@/assets/user-avatar.png'
|
|
|
import assistantAvatar from '@/assets/assistant-avatar.png'
|
|
|
-import { post,get } from '@/utils/request'
|
|
|
+import { post,get,del } from '@/utils/request'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import MarkdownIt from 'markdown-it'
|
|
|
import hljs from 'highlight.js'
|
|
@@ -253,7 +254,8 @@ const simulateStreamResponse = async (question) => {
|
|
|
id: Date.now(),
|
|
|
role: 'assistant',
|
|
|
content: '',
|
|
|
- time: new Date()
|
|
|
+ time: new Date(),
|
|
|
+ chunksID: ''
|
|
|
});
|
|
|
|
|
|
// 立即滚动到底部确保"正在输入"可见
|
|
@@ -279,6 +281,7 @@ const simulateStreamResponse = async (question) => {
|
|
|
if (data.data && data.data.answer) {
|
|
|
accumulatedText += data.data.answer;
|
|
|
messages.value[messageIndex].content = accumulatedText;
|
|
|
+ messages.value[messageIndex].chunksID = data.data.id;
|
|
|
await scrollToBottom();
|
|
|
}
|
|
|
|
|
@@ -371,8 +374,40 @@ const copyContent = (content) => {
|
|
|
ElMessage.success('复制成功')
|
|
|
}
|
|
|
|
|
|
-const toggleFavorite = (messageId) => {
|
|
|
- // TODO: 实现收藏功能
|
|
|
+const toggleFavorite = async (message) => {
|
|
|
+ const answerId = message.chunksID || message.answerId;
|
|
|
+ //如果没有answerId,则不进行收藏
|
|
|
+ if(!answerId){
|
|
|
+ ElMessage.error('没有answerId')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ let response;
|
|
|
+ if (!message.isCollect) {
|
|
|
+ // 添加收藏
|
|
|
+ response = await post('/admin/userCollect/save', {
|
|
|
+ relatedType: 'ai.answer',
|
|
|
+ answerId: answerId
|
|
|
+ });
|
|
|
+ if (response.data) {
|
|
|
+ message.isCollect = true;
|
|
|
+ ElMessage.success('收藏成功');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 取消收藏
|
|
|
+ response = await del('/admin/userCollect/deleteById', {
|
|
|
+ // relatedType: 'ai.answer',
|
|
|
+ id: answerId
|
|
|
+ });
|
|
|
+ if (response.data) {
|
|
|
+ message.isCollect = false;
|
|
|
+ ElMessage.success('已取消收藏');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('收藏操作失败:', error);
|
|
|
+ ElMessage.error(message.isCollect ? '取消收藏失败' : '收藏失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const reAnswer = (messageId) => {
|
|
@@ -418,11 +453,13 @@ const getHistoryChat = async (historyId) => {
|
|
|
|
|
|
// 添加所有对话记录
|
|
|
for (const message of sortedMessages) {
|
|
|
+ // console.log('message',message);
|
|
|
+
|
|
|
// 添加用户问题
|
|
|
messages.value.push({
|
|
|
role: 'user',
|
|
|
content: message.askContent,
|
|
|
- time: new Date(message.createTime)
|
|
|
+ time: new Date(message.createTime),
|
|
|
})
|
|
|
|
|
|
// 处理AI回答
|
|
@@ -506,7 +543,9 @@ const getHistoryChat = async (historyId) => {
|
|
|
id: message.id,
|
|
|
role: 'assistant',
|
|
|
content: finalContent,
|
|
|
- time: new Date(message.createTime)
|
|
|
+ time: new Date(message.createTime),
|
|
|
+ chunksID: message.answerId,
|
|
|
+ isCollect: message.isCollect
|
|
|
})
|
|
|
} catch (error) {
|
|
|
console.error('处理回答内容失败:', error)
|