feat(微信功能加載優化): 在微信功能中新增isLoadWeChat狀態管理,優化聯絡人及群列表的加載邏輯,根據狀態決定數據來源,提升性能與用戶體驗。
This commit is contained in:
@@ -5,9 +5,12 @@ import {
|
||||
asyncWeChatGroup,
|
||||
asyncCountLables,
|
||||
useCkChatStore,
|
||||
updateIsLoadWeChat,
|
||||
} from "@/store/module/ckchat/ckchat";
|
||||
import { useWebSocketStore } from "@/store/module/websocket/websocket";
|
||||
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
import { weChatGroupService, contractService } from "@/utils/db";
|
||||
const isLoadWeChat = useCkChatStore.getState().isLoadWeChat;
|
||||
import {
|
||||
loginWithToken,
|
||||
getControlTerminalList,
|
||||
@@ -17,36 +20,37 @@ import {
|
||||
getLabelsListByGroup,
|
||||
} from "./api";
|
||||
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
|
||||
import {
|
||||
KfUserListData,
|
||||
ContractData,
|
||||
weChatGroup,
|
||||
} from "@/pages/pc/ckbox/data";
|
||||
|
||||
import { WechatGroup } from "./api";
|
||||
const { login2 } = useUserStore.getState();
|
||||
//获取触客宝基础信息
|
||||
export const chatInitAPIdata = async () => {
|
||||
try {
|
||||
//获取联系人列表
|
||||
const contractList = await getAllContactList();
|
||||
let contractList = [];
|
||||
let groupList = [];
|
||||
if (isLoadWeChat) {
|
||||
//获取联系人列表
|
||||
contractList = await contractService.findAll();
|
||||
//获取群列表
|
||||
groupList = await weChatGroupService.findAll();
|
||||
} else {
|
||||
//获取联系人列表
|
||||
contractList = await getAllContactList();
|
||||
|
||||
//获取联系人列表
|
||||
asyncContractList(contractList);
|
||||
//获取群列表
|
||||
groupList = await getAllGroupList();
|
||||
|
||||
//获取群列表
|
||||
const groupList = await getAllGroupList();
|
||||
updateIsLoadWeChat(true);
|
||||
}
|
||||
//获取联系人列表
|
||||
await asyncContractList(contractList);
|
||||
|
||||
await asyncWeChatGroup(groupList);
|
||||
|
||||
// 提取不重复的wechatAccountId组
|
||||
// const uniqueWechatAccountIds: number[] = getUniqueWechatAccountIds(
|
||||
// contractList,
|
||||
// groupList,
|
||||
// );
|
||||
|
||||
//获取控制终端列表
|
||||
const kfUserList: KfUserListData[] = await getAgentList();
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ export interface CkChatState {
|
||||
userInfo: CkUserInfo | null;
|
||||
isLoggedIn: boolean;
|
||||
searchKeyword: string;
|
||||
isLoadWeChat: boolean;
|
||||
updateIsLoadWeChat: (isLoadWeChat: boolean) => void;
|
||||
contractList: ContractData[];
|
||||
chatSessions: any[];
|
||||
kfUserList: KfUserListData[];
|
||||
|
||||
@@ -24,16 +24,18 @@ export const useCkChatStore = createPersistStore<CkChatState>(
|
||||
newContractList: [], //联系人分组
|
||||
kfSelected: 0, //选中的客服
|
||||
searchKeyword: "", //搜索关键词
|
||||
isLoadWeChat: false, //是否加载微信
|
||||
updateIsLoadWeChat: (isLoadWeChat: boolean) => {
|
||||
set({ isLoadWeChat });
|
||||
},
|
||||
//客服列表
|
||||
asyncKfUserList: async data => {
|
||||
set({ kfUserList: data });
|
||||
// await kfUserService.createManyWithServerId(data);
|
||||
},
|
||||
// 获取客服列表
|
||||
getkfUserList: async () => {
|
||||
const state = useCkChatStore.getState();
|
||||
return state.kfUserList;
|
||||
// return await kfUserService.findAll();
|
||||
},
|
||||
// 异步设置标签列表
|
||||
asyncCountLables: async (data: ContactGroupByLabel[]) => {
|
||||
@@ -545,3 +547,5 @@ export const searchContactsAndGroups = () =>
|
||||
export const pinChatSessionToTop = (sessionId: number) =>
|
||||
useCkChatStore.getState().pinChatSessionToTop(sessionId);
|
||||
useCkChatStore.getState().getKfSelectedUser();
|
||||
export const updateIsLoadWeChat = (isLoadWeChat: boolean) =>
|
||||
useCkChatStore.getState().updateIsLoadWeChat(isLoadWeChat);
|
||||
|
||||
Reference in New Issue
Block a user