From cd5849897150fef966398b5511f81368a8bff698 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 20 Jul 2025 08:32:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=B6=88=E6=81=AF=E6=97=B6?= =?UTF-8?q?=E6=8C=89=E6=97=B6=E9=97=B4=E6=8E=92=E5=BA=8F=E4=BB=A5=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E6=9C=80=E6=96=B0=E6=B6=88=E6=81=AF=E5=9C=A8=E6=9C=80?= =?UTF-8?q?=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/system/MessageView.vue | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/views/system/MessageView.vue b/src/views/system/MessageView.vue index a7132b52..c72f2f87 100644 --- a/src/views/system/MessageView.vue +++ b/src/views/system/MessageView.vue @@ -43,16 +43,11 @@ function handleSSEMessage(event: MessageEvent) { } // 使用优化的SSE连接 -const sseConnection = useSSE( - `${import.meta.env.VITE_API_BASE_URL}system/message?role=user`, - handleSSEMessage, - 'message-view', - { - backgroundCloseDelay: 5000, - reconnectDelay: 3000, - maxReconnectAttempts: 3 - } -) +useSSE(`${import.meta.env.VITE_API_BASE_URL}system/message?role=user`, handleSSEMessage, 'message-view', { + backgroundCloseDelay: 5000, + reconnectDelay: 3000, + maxReconnectAttempts: 3, +}) // 调用API加载存量消息 async function loadMessages({ done }: { done: any }) { @@ -73,10 +68,17 @@ async function loadMessages({ done }: { done: any }) { // 已加载过 isLoaded.value = true if (currData.value.length > 0) { + // 按时间排序,确保最新的消息在最后 + currData.value.sort((a, b) => { + const timeA = a.reg_time || a.date || '' + const timeB = b.reg_time || b.date || '' + return compareTime(timeA, timeB) + }) + // 取最后一条时间为存量消息最新时间 - lastTime.value = currData.value[currData.value.length - 1].reg_time ?? '' - // 倒序 - currData.value.reverse() + lastTime.value = + currData.value[currData.value.length - 1].reg_time ?? currData.value[currData.value.length - 1].date ?? '' + // 合并数据 messages.value = [...currData.value, ...messages.value] if (page.value === 1) {