bug修复

This commit is contained in:
2025-10-26 23:26:30 +08:00
parent 85e910fac9
commit df818578e5
20 changed files with 2008 additions and 98 deletions
+8 -15
View File
@@ -251,6 +251,8 @@ const loadMessages = async () => {
loading.value = true
try {
console.log('📨 开始加载消息...')
// 调用最近消息API
const response = await messageApi.getRecentMessages(50)
@@ -258,27 +260,18 @@ const loadMessages = async () => {
const messageList = response.data || response || []
if (Array.isArray(messageList)) {
console.log('📨 收到消息列表,数量:', messageList.length)
// 转换消息格式
const chatMessages = MessageService.convertToChatMessages(messageList)
// 按时间排序(最早的在前面)
chatMessages.sort((a, b) => {
const parseTime = (timestamp: string | Date) => {
if (timestamp instanceof Date) return timestamp.getTime()
if (typeof timestamp === 'string') {
if (timestamp.includes(' ') && !timestamp.includes('T')) {
return new Date(timestamp.replace(' ', 'T')).getTime()
}
return new Date(timestamp).getTime()
}
return new Date().getTime()
}
// 使用优化的排序和去重方法
const sortedMessages = MessageService.sortAndDeduplicateMessages(chatMessages)
return parseTime(a.timestamp) - parseTime(b.timestamp)
})
console.log('✅ 消息排序完成,最终数量:', sortedMessages.length)
// 将消息添加到 chatStore
chatStore.messages.splice(0, chatStore.messages.length, ...chatMessages)
chatStore.messages.splice(0, chatStore.messages.length, ...sortedMessages)
// 强制滚动到底部
await nextTick()