|
@@ -1,8 +1,8 @@
|
1
|
1
|
<!--
|
2
|
2
|
* @Author: wrh
|
3
|
3
|
* @Date: 2025-01-01 00:00:00
|
4
|
|
- * @LastEditors: wrh
|
5
|
|
- * @LastEditTime: 2025-07-29 17:45:58
|
|
4
|
+ * @LastEditors: Please set LastEditors
|
|
5
|
+ * @LastEditTime: 2025-07-30 14:54:24
|
6
|
6
|
-->
|
7
|
7
|
<template>
|
8
|
8
|
<div class="agent-detail-container" v-loading="loading">
|
|
@@ -248,14 +248,10 @@ const loadTopic = async () => {
|
248
|
248
|
}
|
249
|
249
|
}
|
250
|
250
|
|
251
|
|
-// 选择话题
|
252
|
|
-const selectTopic = async (topic) => {
|
253
|
|
- console.log('选择话题:', topic)
|
254
|
|
- currentTopicId.value = topic.topicId
|
255
|
|
- chatTitle.value = topic.topic
|
|
251
|
+// 加载指定话题的聊天记录(公共函数)
|
|
252
|
+const loadChatMessages = async (topicId) => {
|
256
|
253
|
try {
|
257
|
|
- // 加载该话题下的聊天记录
|
258
|
|
- const res = await listChat({ topicId: topic.topicId });
|
|
254
|
+ const res = await listChat({ topicId: topicId });
|
259
|
255
|
if (res.rows.length > 0) {
|
260
|
256
|
// 处理聊天消息格式
|
261
|
257
|
const messages = []
|
|
@@ -265,12 +261,11 @@ const selectTopic = async (topic) => {
|
265
|
261
|
try {
|
266
|
262
|
const fileResponse = await listDocument({ chatId: chat.chatId });
|
267
|
263
|
if (fileResponse.rows && fileResponse.rows.length > 0) {
|
268
|
|
- const fileNames = fileResponse.rows.map(doc => doc.path).join(', ')
|
|
264
|
+ const fileNames = fileResponse.rows.map(doc => doc.path.split("/")[doc.path.split("/").length - 1]).join(', ');
|
269
|
265
|
// 先添加文件信息消息
|
270
|
266
|
messages.push({
|
271
|
267
|
role: 'assistant',
|
272
|
268
|
content: `📎 相关文件: ${fileNames}`,
|
273
|
|
- timestamp: chat.inputTime || new Date(chat.createTime).toLocaleTimeString(),
|
274
|
269
|
isHtml: false,
|
275
|
270
|
isFileInfo: true // 标记为文件信息消息
|
276
|
271
|
})
|
|
@@ -292,7 +287,7 @@ const selectTopic = async (topic) => {
|
292
|
287
|
if (chat.output) {
|
293
|
288
|
messages.push({
|
294
|
289
|
role: 'assistant',
|
295
|
|
- content: formatContentLinks(chat.output),
|
|
290
|
+ content: chat.output,
|
296
|
291
|
timestamp: chat.outputTime || new Date(chat.createTime).toLocaleTimeString(),
|
297
|
292
|
isHtml: true // 历史消息可能包含HTML内容
|
298
|
293
|
})
|
|
@@ -300,17 +295,38 @@ const selectTopic = async (topic) => {
|
300
|
295
|
}
|
301
|
296
|
// 更新聊天消息
|
302
|
297
|
chatMessages.value = messages
|
303
|
|
- // 滚动到底部
|
304
|
|
- nextTick(() => {
|
305
|
|
- scrollToBottom()
|
306
|
|
- })
|
307
|
|
- ElMessage.success(`已加载话题"${topic.topic}"的对话记录`)
|
|
298
|
+ return messages.length > 0
|
308
|
299
|
} else {
|
309
|
300
|
chatMessages.value = []
|
310
|
|
- ElMessage.info('该话题暂无对话记录')
|
|
301
|
+ return false
|
311
|
302
|
}
|
312
|
303
|
} catch (error) {
|
313
|
304
|
console.error('加载话题对话记录失败:', error)
|
|
305
|
+ chatMessages.value = []
|
|
306
|
+ throw error
|
|
307
|
+ }
|
|
308
|
+}
|
|
309
|
+
|
|
310
|
+// 选择话题
|
|
311
|
+const selectTopic = async (topic) => {
|
|
312
|
+ console.log('选择话题:', topic)
|
|
313
|
+ currentTopicId.value = topic.topicId
|
|
314
|
+ chatTitle.value = topic.topic
|
|
315
|
+
|
|
316
|
+ try {
|
|
317
|
+ const hasMessages = await loadChatMessages(topic.topicId)
|
|
318
|
+
|
|
319
|
+ // 滚动到底部
|
|
320
|
+ nextTick(() => {
|
|
321
|
+ scrollToBottom()
|
|
322
|
+ })
|
|
323
|
+
|
|
324
|
+ if (hasMessages) {
|
|
325
|
+ ElMessage.success(`已加载话题"${topic.topic}"的对话记录`)
|
|
326
|
+ } else {
|
|
327
|
+ ElMessage.info('该话题暂无对话记录')
|
|
328
|
+ }
|
|
329
|
+ } catch (error) {
|
314
|
330
|
ElMessage.error('加载对话记录失败')
|
315
|
331
|
}
|
316
|
332
|
}
|
|
@@ -338,8 +354,8 @@ const sendMessage = async () => {
|
338
|
354
|
try {
|
339
|
355
|
// 调用智能体回答API
|
340
|
356
|
const response = await answer({
|
341
|
|
- query: message,
|
342
|
|
- agentName: agentInfo.value.agentName
|
|
357
|
+ topicId: currentTopicId.value,
|
|
358
|
+ question: message
|
343
|
359
|
})
|
344
|
360
|
|
345
|
361
|
// 添加助手回复
|
|
@@ -426,7 +442,24 @@ const submitChatUpload = async () => {
|
426
|
442
|
ElMessage.success('文件上传成功');
|
427
|
443
|
let topicRes = await addTopic({ agentId: props.agentId, topic: fileName });
|
428
|
444
|
const topicId = topicRes.msg;
|
429
|
|
- await addChat({ userId: userStore.id, chatId, topicId, output: assistantContent, outputTime: proxy.parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}') });
|
|
445
|
+ await updateChat({ userId: userStore.id, chatId, topicId, output: assistantContent, outputTime: proxy.parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}') });
|
|
446
|
+
|
|
447
|
+ // 刷新话题列表
|
|
448
|
+ await loadTopic();
|
|
449
|
+
|
|
450
|
+ // 激活当前话题并加载聊天记录
|
|
451
|
+ currentTopicId.value = topicId;
|
|
452
|
+ chatTitle.value = fileName;
|
|
453
|
+
|
|
454
|
+ // 重新加载该话题的聊天记录以显示文件相关内容
|
|
455
|
+ try {
|
|
456
|
+ await loadChatMessages(topicId)
|
|
457
|
+ } catch (error) {
|
|
458
|
+ console.error('加载话题聊天记录失败:', error)
|
|
459
|
+ }
|
|
460
|
+
|
|
461
|
+ // 清空文件上传列表
|
|
462
|
+ chatFileList.value = [];
|
430
|
463
|
|
431
|
464
|
nextTick(() => {
|
432
|
465
|
scrollToBottom()
|