From 69c56d49e6ea4fd3103b8e3ef687303eead87f93 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Fri, 19 Sep 2025 00:58:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(chat):=20=E4=BF=AE=E5=A4=8D=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E5=88=97=E8=A1=A8=E6=97=B6=E9=97=B4=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=B8=BA=E5=8C=97=E4=BA=AC=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/ChatSidebarComponent.vue | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/web/src/components/ChatSidebarComponent.vue b/web/src/components/ChatSidebarComponent.vue index 8b01c809..e961fe0a 100644 --- a/web/src/components/ChatSidebarComponent.vue +++ b/web/src/components/ChatSidebarComponent.vue @@ -71,8 +71,12 @@ import { PanelLeftClose, MessageSquarePlus } from 'lucide-vue-next'; import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; import relativeTime from 'dayjs/plugin/relativeTime'; +import utc from 'dayjs/plugin/utc'; +import timezone from 'dayjs/plugin/timezone'; dayjs.extend(relativeTime); +dayjs.extend(utc); +dayjs.extend(timezone); dayjs.locale('zh-cn'); const props = defineProps({ @@ -128,16 +132,23 @@ const groupedChats = computed(() => { '三十天内': [], }; - const now = dayjs(); + // 确保使用北京时间进行比较 + const now = dayjs().tz('Asia/Shanghai'); const today = now.startOf('day'); const sevenDaysAgo = now.subtract(7, 'day').startOf('day'); const thirtyDaysAgo = now.subtract(30, 'day').startOf('day'); // Sort chats by creation date, newest first - const sortedChats = [...props.chatsList].sort((a, b) => dayjs(b.create_at).diff(dayjs(a.create_at))); + const sortedChats = [...props.chatsList].sort((a, b) => { + // 将后端时间当作UTC时间处理,然后转换为北京时间进行比较 + const dateA = dayjs.utc(b.create_at).tz('Asia/Shanghai'); + const dateB = dayjs.utc(a.create_at).tz('Asia/Shanghai'); + return dateA.diff(dateB); + }); sortedChats.forEach(chat => { - const chatDate = dayjs(chat.create_at); + // 将后端时间当作UTC时间处理,然后转换为北京时间 + const chatDate = dayjs.utc(chat.create_at).tz('Asia/Shanghai'); if (chatDate.isAfter(today)) { groups['今天'].push(chat); } else if (chatDate.isAfter(sevenDaysAgo)) {