diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx index bf97e639..4521f4a7 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx @@ -48,6 +48,9 @@ const ChatWindow: React.FC = ({ if (!prevMsg || prevMsg.id !== msg.id) return false; try { + // 检查msg.content和prevMsg.content是否为null或undefined + if (!msg.content || !prevMsg.content) return false; + const currentContent = typeof msg.content === "string" ? JSON.parse(msg.content) @@ -107,7 +110,14 @@ const ChatWindow: React.FC = ({ }; // 解析消息内容,判断消息类型并返回对应的渲染内容 - const parseMessageContent = (content: string, msg: ChatRecord) => { + const parseMessageContent = ( + content: string | null | undefined, + msg: ChatRecord, + ) => { + // 处理null或undefined的内容 + if (content === null || content === undefined) { + return
消息内容不可用
; + } // 检查是否为表情包 if ( typeof content === "string" && @@ -530,7 +540,7 @@ const ChatWindow: React.FC = ({ }; const renderMessage = (msg: ChatRecord) => { - const isOwn = msg.isSend; + const isOwn = msg?.isSend; return (
= ({ )}
{!isOwn && ( -
{msg.senderName}
+
{msg?.senderName}
)} {parseMessageContent(msg.content, msg)}