fix(chat): 修复聊天列表时间处理为北京时间

This commit is contained in:
Wenjie Zhang 2025-09-19 00:58:19 +08:00
parent 782eb4ae31
commit 69c56d49e6

View File

@ -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)) {