From a101fc182b89401b61602f84ecff995016961ca9 Mon Sep 17 00:00:00 2001 From: Lexcubia Date: Sun, 27 Apr 2025 16:59:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(chat):=20=E4=BC=98=E5=8C=96=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=88=B3=E6=98=BE=E7=A4=BA=E5=92=8C=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了对 createdAtTimestamp 的引用,改为使用 createdAt - 添加了对时间戳的格式化处理,支持字符串和数字类型的时间戳 - 增加了时间戳的有效性检查 - 调整了时间戳的显示位置和样式 --- src/views/chat/ChatInterface.vue | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/views/chat/ChatInterface.vue b/src/views/chat/ChatInterface.vue index b27bcc9..6bdc6be 100644 --- a/src/views/chat/ChatInterface.vue +++ b/src/views/chat/ChatInterface.vue @@ -21,9 +21,9 @@
- +
+ {{ formatTimestamp(message.createdAt) }} +
{{ message.question }}
@@ -55,9 +55,9 @@
- +
+ {{ formatTimestamp(message.createdAt) }} +
@@ -310,9 +310,20 @@ const toggleSummary = () => { // 格式化时间戳 const formatTimestamp = (timestamp) => { - console.log('%c timestamp:', 'color: #2196F3; font-weight: bold', timestamp) if (!timestamp) return '' - const date = new Date(timestamp) + + // 检查时间戳是否为字符串,如果是则转换为数字 + const timestampNum = typeof timestamp === 'string' ? parseInt(timestamp) : timestamp + + // 检查时间戳是否为毫秒级,如果不是则转换为毫秒 + const date = new Date(timestampNum.toString().length === 10 ? timestampNum * 1000 : timestampNum) + + // 检查日期是否有效 + if (isNaN(date.getTime())) { + console.error('Invalid timestamp:', timestamp) + return '' + } + return date.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', @@ -561,6 +572,9 @@ html.dark .background-section .background-content { flex-direction: column; align-items: flex-end; } + .message-timestamp { + right: 0; + } } &.assistant { @@ -865,6 +879,7 @@ html.dark .background-section .background-content { top: -20px; opacity: 0; transition: opacity 0.2s ease; + width: max-content; } .message-text-wrapper {