From 9ed298bf3eae362f44112b856daae274d628e863 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, 10 Sep 2025 18:08:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(weChat):=20=E6=B7=BB=E5=8A=A0=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E5=BD=93=E5=89=8D=E8=81=94=E7=B3=BB=E4=BA=BA=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在weChat模块中添加clearCurrentContact方法用于清空当前联系人和消息,并在ckchat模块中调用该方法确保删除会话时同步清空联系人 --- Cunkebao/src/store/module/ckchat/ckchat.ts | 7 ++++++- Cunkebao/src/store/module/weChat/weChat.data.ts | 3 ++- Cunkebao/src/store/module/weChat/weChat.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cunkebao/src/store/module/ckchat/ckchat.ts b/Cunkebao/src/store/module/ckchat/ckchat.ts index 5928866d..1b44fcbe 100644 --- a/Cunkebao/src/store/module/ckchat/ckchat.ts +++ b/Cunkebao/src/store/module/ckchat/ckchat.ts @@ -9,7 +9,10 @@ import { } from "@/pages/pc/ckbox/data"; import { weChatGroupService, contractService } from "@/utils/db"; import { createContractList } from "@/store/module/ckchat/api"; - +import { useWeChatStore } from "@/store/module/weChat/weChat"; +// 从weChat store获取clearCurrentContact方法 +const getClearCurrentContact = () => + useWeChatStore.getState().clearCurrentContact; export const useCkChatStore = createPersistStore( set => ({ userInfo: null, @@ -393,6 +396,8 @@ export const useCkChatStore = createPersistStore( set(state => ({ chatSessions: state.chatSessions.filter(item => item.id !== sessionId), })); + //当前选中的客户清空 + getClearCurrentContact(); }, // 设置用户信息 setUserInfo: (userInfo: CkUserInfo) => { diff --git a/Cunkebao/src/store/module/weChat/weChat.data.ts b/Cunkebao/src/store/module/weChat/weChat.data.ts index f7839ef0..7cdd4b73 100644 --- a/Cunkebao/src/store/module/weChat/weChat.data.ts +++ b/Cunkebao/src/store/module/weChat/weChat.data.ts @@ -6,7 +6,8 @@ export interface WeChatState { // 当前聊天用户的消息列表(只存储当前聊天用户的消息) currentMessages: ChatRecord[]; - + // 清空当前联系人 + clearCurrentContact: () => void; // 消息加载状态 messagesLoading: boolean; isLoadingData: boolean; diff --git a/Cunkebao/src/store/module/weChat/weChat.ts b/Cunkebao/src/store/module/weChat/weChat.ts index fa537c1d..f4f3cb0c 100644 --- a/Cunkebao/src/store/module/weChat/weChat.ts +++ b/Cunkebao/src/store/module/weChat/weChat.ts @@ -24,7 +24,10 @@ export const useWeChatStore = create()( messagesLoading: false, isLoadingData: false, currentGroupMembers: [], - + //清空当前联系人 + clearCurrentContact: () => { + set({ currentContract: null, currentMessages: [] }); + }, // Actions setCurrentContact: ( contract: ContractData | weChatGroup,