From 1f0ef3c64d0c39ff30d612af2a995ff205a6feb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E7=BA=A7=E8=80=81=E7=99=BD=E5=85=94?= Date: Thu, 4 Sep 2025 10:47:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor(chat):=20=E9=87=8D=E5=91=BD=E5=90=8DPe?= =?UTF-8?q?rson=E7=BB=84=E4=BB=B6=E4=B8=BAProfileCard=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复微信聊天消息可能为undefined的问题 添加调试日志检查消息状态 确保wechatTime字段安全访问 --- .../components/{Person => ProfileCard}/Person.module.scss | 0 .../components/{Person => ProfileCard}/index.tsx | 2 +- .../src/pages/pc/ckbox/components/ChatWindow/index.tsx | 8 +++++--- Cunkebao/src/store/module/weChat/weChat.ts | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) rename Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/{Person => ProfileCard}/Person.module.scss (100%) rename Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/{Person => ProfileCard}/index.tsx (99%) diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/Person/Person.module.scss b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/ProfileCard/Person.module.scss similarity index 100% rename from Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/Person/Person.module.scss rename to Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/ProfileCard/Person.module.scss diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/Person/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/ProfileCard/index.tsx similarity index 99% rename from Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/Person/index.tsx rename to Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/ProfileCard/index.tsx index c96eea65..ed60e655 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/Person/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/ProfileCard/index.tsx @@ -111,7 +111,7 @@ const Person: React.FC = ({ conRemark: remarkValue, // 使用当前编辑的备注值 alias: contract.alias, wechatId: contract.wechatId, - avatar: contract.avatar, + avatar: contract.avatar || contract.chatroomAvatar, phone: contract.phone || "-", email: contract.email || "-", department: contract.department || "-", diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx index edff2cd2..5470c535 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/index.tsx @@ -20,7 +20,7 @@ import { ChatRecord, ContractData, weChatGroup } from "@/pages/pc/ckbox/data"; import styles from "./ChatWindow.module.scss"; import { useWebSocketStore } from "@/store/module/websocket/websocket"; import { formatWechatTime } from "@/utils/common"; -import Person from "./components/Person"; +import ProfileCard from "./components/ProfileCard"; import MessageEnter from "./components/MessageEnter"; import { useWeChatStore } from "@/store/module/weChat/weChat"; const { Header, Content } = Layout; @@ -44,6 +44,8 @@ const ChatWindow: React.FC = ({ const prevMessages = prevMessagesRef.current; // 检查是否有视频状态变化(从加载中变为已完成或开始加载) + console.log("currentMessages", currentMessages); + const hasVideoStateChange = currentMessages.some((msg, index) => { const prevMsg = prevMessages[index]; if (!prevMsg || prevMsg.id !== msg.id) return false; @@ -525,7 +527,7 @@ const ChatWindow: React.FC = ({ // 用于分组消息并添加时间戳的辅助函数 const groupMessagesByTime = (messages: ChatRecord[]) => { return messages.map(msg => ({ - time: formatWechatTime(msg.wechatTime), + time: formatWechatTime(msg?.wechatTime), messages: [msg], })); }; @@ -643,7 +645,7 @@ const ChatWindow: React.FC = ({ {/* 右侧个人资料卡片 */} - ()( } const messages = await getChatMessages(params); - set({ currentMessages: messages }); + set({ currentMessages: messages || [] }); } catch (error) { console.error("获取聊天消息失败:", error); } finally {