From df0bbddbd5c6f9d071e64db9d6f97fb97f4e6106 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: Wed, 3 Sep 2025 18:33:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(weChat):=20=E6=B7=BB=E5=8A=A0=E8=81=94?= =?UTF-8?q?=E7=B3=BB=E4=BA=BA=E5=AD=98=E5=9C=A8=E6=A3=80=E6=9F=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=B9=B6=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在setCurrentContact方法中添加isExist参数,用于区分新增联系人和已存在联系人的处理逻辑 优化消息处理流程,确保未读消息计数正确更新 --- .../SidebarMenu/MessageList/index.tsx | 2 +- .../src/store/module/weChat/weChat.data.ts | 5 ++++- Cunkebao/src/store/module/weChat/weChat.ts | 21 +++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx index 6fc7d049..dfaab7e4 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx @@ -13,7 +13,7 @@ const MessageList: React.FC = () => { const { setCurrentContact, currentContract } = useWeChatStore(); const chatSessions = useCkChatStore(state => state.chatSessions); const onContactClick = (session: ContractData | weChatGroup) => { - setCurrentContact(session); + setCurrentContact(session, true); }; return (
diff --git a/Cunkebao/src/store/module/weChat/weChat.data.ts b/Cunkebao/src/store/module/weChat/weChat.data.ts index 78dc6508..a63ff292 100644 --- a/Cunkebao/src/store/module/weChat/weChat.data.ts +++ b/Cunkebao/src/store/module/weChat/weChat.data.ts @@ -11,7 +11,10 @@ export interface WeChatState { messagesLoading: boolean; // Actions - setCurrentContact: (contract: ContractData | weChatGroup) => void; + setCurrentContact: ( + contract: ContractData | weChatGroup, + isExist?: boolean, + ) => void; loadChatMessages: (contact: ContractData | weChatGroup) => Promise; // 视频消息处理方法 diff --git a/Cunkebao/src/store/module/weChat/weChat.ts b/Cunkebao/src/store/module/weChat/weChat.ts index 30d65ead..914f5e71 100644 --- a/Cunkebao/src/store/module/weChat/weChat.ts +++ b/Cunkebao/src/store/module/weChat/weChat.ts @@ -6,8 +6,8 @@ import { clearUnreadCount, updateConfig } from "@/pages/pc/ckbox/api"; import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data"; import { addChatSession, - getChatSessions, updateChatSession, + useCkChatStore, } from "@/store/module/ckchat/ckchat"; export const useWeChatStore = create()( @@ -19,12 +19,19 @@ export const useWeChatStore = create()( messagesLoading: false, // Actions - setCurrentContact: (contract: ContractData | weChatGroup) => { + setCurrentContact: ( + contract: ContractData | weChatGroup, + isExist?: boolean, + ) => { const state = useWeChatStore.getState(); // 切换联系人时清空当前消息,等待重新加载 set({ currentMessages: [] }); clearUnreadCount([contract.id]).then(() => { - addChatSession(contract); + if (isExist) { + updateChatSession({ ...contract, unreadCount: 0 }); + } else { + addChatSession(contract); + } set({ currentContract: contract }); updateConfig({ id: contract.id, @@ -83,12 +90,14 @@ export const useWeChatStore = create()( })); } else { //更新消息列表unread数值,根据接收的++1 这样 - const chatSessions = getChatSessions(); + const chatSessions = useCkChatStore.getState().chatSessions; const session = chatSessions.find( item => item.id == message.wechatFriendId, ); - session.unreadCount = Number(session.unreadCount) + 1; - updateChatSession(session); + if (session) { + session.unreadCount = Number(session.unreadCount) + 1; + updateChatSession(session); + } } },