feat(weChat): 添加清空当前联系人的功能

在weChat模块中添加clearCurrentContact方法用于清空当前联系人和消息,并在ckchat模块中调用该方法确保删除会话时同步清空联系人
This commit is contained in:
超级老白兔
2025-09-10 18:08:09 +08:00
parent 8507b640b2
commit 9ed298bf3e
3 changed files with 12 additions and 3 deletions

View File

@@ -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<CkChatState>(
set => ({
userInfo: null,
@@ -393,6 +396,8 @@ export const useCkChatStore = createPersistStore<CkChatState>(
set(state => ({
chatSessions: state.chatSessions.filter(item => item.id !== sessionId),
}));
//当前选中的客户清空
getClearCurrentContact();
},
// 设置用户信息
setUserInfo: (userInfo: CkUserInfo) => {

View File

@@ -6,7 +6,8 @@ export interface WeChatState {
// 当前聊天用户的消息列表(只存储当前聊天用户的消息)
currentMessages: ChatRecord[];
// 清空当前联系人
clearCurrentContact: () => void;
// 消息加载状态
messagesLoading: boolean;
isLoadingData: boolean;

View File

@@ -24,7 +24,10 @@ export const useWeChatStore = create<WeChatState>()(
messagesLoading: false,
isLoadingData: false,
currentGroupMembers: [],
//清空当前联系人
clearCurrentContact: () => {
set({ currentContract: null, currentMessages: [] });
},
// Actions
setCurrentContact: (
contract: ContractData | weChatGroup,