From 70fbdce641159683bb43f9e50e2b9aecad56cddf Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Tue, 19 May 2026 09:28:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(ai-chat):=20=E4=BC=98=E5=8C=96=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E6=B6=88=E6=81=AF=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=8E=E6=90=9C=E7=B4=A2=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 时间显示人性化:昨天/前天/跨年日期 - 搜索上下导航修复 scroll-into-view 触发逻辑 --- lang/en-us/ai-chat/index.js | 5 ++ lang/zh-cn/ai-chat/index.js | 5 ++ pages_tool/ai-chat/ai-chat-message.vue | 64 +++++++++++++++----------- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/lang/en-us/ai-chat/index.js b/lang/en-us/ai-chat/index.js index b3ca06d..2a41b70 100644 --- a/lang/en-us/ai-chat/index.js +++ b/lang/en-us/ai-chat/index.js @@ -8,6 +8,11 @@ export const lang = { send: 'Send', retry: 'Retry', + // ====== Time Format ====== + timeFormatToday: 'Today', + timeFormatYesterday: 'Yesterday', + timeFormatBeforeYesterday: 'Day before yesterday', + // ====== ai-chat-message ====== aiNickname: 'AI Assistant', defaultNickname: 'Me', diff --git a/lang/zh-cn/ai-chat/index.js b/lang/zh-cn/ai-chat/index.js index 496ebe1..98d721c 100644 --- a/lang/zh-cn/ai-chat/index.js +++ b/lang/zh-cn/ai-chat/index.js @@ -8,6 +8,11 @@ export const lang = { send: '发送', retry: '重试', + // ====== 时间格式化 ====== + timeFormatToday: '今天', + timeFormatYesterday: '昨天', + timeFormatBeforeYesterday: '前天', + // ====== ai-chat-message ====== aiNickname: '智能助手', defaultNickname: '我', diff --git a/pages_tool/ai-chat/ai-chat-message.vue b/pages_tool/ai-chat/ai-chat-message.vue index e8c28c7..6e15411 100644 --- a/pages_tool/ai-chat/ai-chat-message.vue +++ b/pages_tool/ai-chat/ai-chat-message.vue @@ -1291,52 +1291,62 @@ _handleStreamError(msg) { return html }, - // 格式化时间 + // 格式化时间(人性化显示) formatTime(timestamp) { - // 如果没有时间戳,就不显示时间 - if (!timestamp) { - return ''; - } - + if (!timestamp) return ''; + let date; - - // 如果是字符串格式,例如 "2026-04-16 03:56:20" + if (typeof timestamp === 'string') { - // 手动解析格式 "YYYY-MM-DD HH:mm:ss" const parts = timestamp.match(/(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})/); if (parts) { const [, year, month, day, hour, minute, second] = parts; - // 先解析成本地时间,然后加上8小时时区差 date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day), parseInt(hour), parseInt(minute), parseInt(second)); - // 加上8小时 date.setHours(date.getHours() + 8); } else { - // 其他字符串格式直接解析 date = new Date(timestamp); } - } - // 如果是数字格式 - else { + } else { let timeValue = timestamp; - - // 如果时间戳小于10000000000,说明是秒,需要乘以1000转成毫秒 if (typeof timeValue === 'number' && timeValue < 10000000000) { timeValue = timeValue * 1000; } - date = new Date(timeValue); } - - - // 如果时间无效,就不显示时间 - if (isNaN(date.getTime())) { - return ''; - } - + + if (isNaN(date.getTime())) return ''; + + const now = new Date(); + const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); + const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000); + const beforeYesterday = new Date(today.getTime() - 2 * 24 * 60 * 60 * 1000); + + const msgDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()); + const hours = date.getHours().toString().padStart(2, '0'); const minutes = date.getMinutes().toString().padStart(2, '0'); - const result = hours + ':' + minutes; - return result; + const timeStr = `${hours}:${minutes}`; + + if (msgDate.getTime() === today.getTime()) { + return timeStr; + } + if (msgDate.getTime() === yesterday.getTime()) { + return `${this.$lang('timeFormatYesterday')} ${timeStr}`; + } + if (msgDate.getTime() === beforeYesterday.getTime()) { + return `${this.$lang('timeFormatBeforeYesterday')} ${timeStr}`; + } + + const isCurrentYear = date.getFullYear() === now.getFullYear(); + const monthStr = (date.getMonth() + 1).toString(); + const dayStr = date.getDate().toString(); + + if (isCurrentYear) { + return `${monthStr}/${dayStr} ${timeStr}`; + } + + const yearStr = date.getFullYear().toString(); + return `${yearStr}/${monthStr}/${dayStr} ${timeStr}`; }, // 格式化文件大小