From 66241f32afe0f21acbbc0eac94e0a8c2b8f89509 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: Fri, 5 Sep 2025 11:47:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BE=AE=E4=BF=A1):=20=E6=B7=BB=E5=8A=A0w?= =?UTF-8?q?echatChatroomId=E5=AD=97=E6=AE=B5=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在weChatGroup接口中添加wechatChatroomId字段 - 移除调试用的console.log语句 - 重构消息处理逻辑,简化条件判断并新增会话初始化处理 --- .../components/MessageRecord/index.tsx | 1 - Cunkebao/src/pages/pc/ckbox/data.ts | 1 + Cunkebao/src/store/module/weChat/weChat.ts | 20 +++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) 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 3c059ad9..229f0cb2 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 @@ -18,7 +18,6 @@ const MessageRecord: React.FC = ({ contract }) => { ); useEffect(() => { - console.log(currentMessages); scrollToBottom(); }, [currentMessages]); diff --git a/Cunkebao/src/pages/pc/ckbox/data.ts b/Cunkebao/src/pages/pc/ckbox/data.ts index 089d8935..1a5f14e6 100644 --- a/Cunkebao/src/pages/pc/ckbox/data.ts +++ b/Cunkebao/src/pages/pc/ckbox/data.ts @@ -119,6 +119,7 @@ export interface weChatGroup { unreadCount: number; notice: string; selfDisplyName: string; + wechatChatroomId: number; [key: string]: any; } diff --git a/Cunkebao/src/store/module/weChat/weChat.ts b/Cunkebao/src/store/module/weChat/weChat.ts index 4ab64187..fb25a99e 100644 --- a/Cunkebao/src/store/module/weChat/weChat.ts +++ b/Cunkebao/src/store/module/weChat/weChat.ts @@ -91,18 +91,10 @@ export const useWeChatStore = create()( const currentContract = useWeChatStore.getState().currentContract; //判断群还是好友 const getMessageId = - currentContract?.chatroomId || message.wechatFriendId; - const isGroup = currentContract?.chatroomId; + message?.wechatChatroomId || message.wechatFriendId; - if ( - currentContract && - currentContract.wechatAccountId == message.wechatAccountId && - currentContract.id == getMessageId - ) { - console.log("进入"); - if (isGroup) { - message.unreadCount = 1; - } + //当前选中聊天的群或好友 + if (currentContract && currentContract.id == getMessageId) { set(state => ({ currentMessages: [...state.currentMessages, message], })); @@ -113,6 +105,12 @@ export const useWeChatStore = create()( if (session) { session.unreadCount = Number(session.unreadCount) + 1; updateChatSession(session); + } else { + // 新增会话 + addChatSession({ + ...session, + unreadCount: 1, + }); } } },