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,