diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx index 20c1f580..662aa53c 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef } from "react"; import { Avatar, Divider } from "antd"; -import { UserOutlined } from "@ant-design/icons"; +import { UserOutlined, LoadingOutlined } from "@ant-design/icons"; import { ChatRecord, ContractData, weChatGroup } from "@/pages/pc/ckbox/data"; import { formatWechatTime } from "@/utils/common"; import styles from "./MessageRecord.module.scss"; @@ -194,11 +194,40 @@ const MessageRecord: React.FC = ({ contract }) => { ); }; + const loadMoreMessages = () => { + // 兼容性处理:检查消息数组和时间戳 + if (!currentMessages || currentMessages.length === 0) { + console.warn("No messages available for loading more"); + return; + } + + const firstMessage = currentMessages[0]; + if (!firstMessage || !firstMessage.createTime) { + console.warn("Invalid message or createTime"); + return; + } + + // 兼容性处理:确保时间戳格式正确 + let timestamp; + try { + const date = new Date(firstMessage.createTime); + if (isNaN(date.getTime())) { + console.warn("Invalid createTime format:", firstMessage.createTime); + return; + } + timestamp = date.getTime() - 20000; + } catch (error) { + console.error("Error parsing createTime:", error); + return; + } + + loadChatMessages(false, timestamp); + }; return (
-
loadChatMessages(false)}> - 点击加载更早的信息{messagesLoading ? "中" : "1"} +
loadMoreMessages()}> + 点击加载更早的信息 {messagesLoading ? : ""}
{groupMessagesByTime(currentMessages).map((group, groupIndex) => ( diff --git a/Cunkebao/src/store/module/weChat/weChat.ts b/Cunkebao/src/store/module/weChat/weChat.ts index 612aa37b..2941c710 100644 --- a/Cunkebao/src/store/module/weChat/weChat.ts +++ b/Cunkebao/src/store/module/weChat/weChat.ts @@ -72,8 +72,8 @@ export const useWeChatStore = create()( } else { set({ currentMessages: [ - ...state.currentMessages, ...(messages || []), + ...state.currentMessages, ], }); } @@ -85,8 +85,8 @@ export const useWeChatStore = create()( } else { set({ currentMessages: [ - ...state.currentMessages, ...(messages || []), + ...state.currentMessages, ], }); } @@ -94,7 +94,9 @@ export const useWeChatStore = create()( } catch (error) { console.error("获取聊天消息失败:", error); } finally { - set({ messagesLoading: false }); + setTimeout(() => { + set({ messagesLoading: false }); + }, 1500); } },