refactor(chat): 重命名Person组件为ProfileCard并优化代码

修复微信聊天消息可能为undefined的问题
添加调试日志检查消息状态
确保wechatTime字段安全访问
This commit is contained in:
超级老白兔
2025-09-04 10:47:57 +08:00
parent df0bbddbd5
commit 1f0ef3c64d
4 changed files with 7 additions and 5 deletions

View File

@@ -111,7 +111,7 @@ const Person: React.FC<PersonProps> = ({
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 || "-",

View File

@@ -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<ChatWindowProps> = ({
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<ChatWindowProps> = ({
// 用于分组消息并添加时间戳的辅助函数
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<ChatWindowProps> = ({
</Layout>
{/* 右侧个人资料卡片 */}
<Person
<ProfileCard
contract={contract}
showProfile={showProfile}
onToggleProfile={onToggleProfile}

View File

@@ -60,7 +60,7 @@ export const useWeChatStore = create<WeChatState>()(
}
const messages = await getChatMessages(params);
set({ currentMessages: messages });
set({ currentMessages: messages || [] });
} catch (error) {
console.error("获取聊天消息失败:", error);
} finally {