From d4336ed447d1f24f1d32ec03436d07835f5f10ec 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: Sat, 30 Aug 2025 14:23:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(store):=20=E7=A7=BB=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84ckchat=E6=A8=A1=E5=9D=97=E5=8F=8A?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 清理不再使用的ckchat store模块及其相关导入,简化代码结构 --- Cunkebao/src/pages/mobile/test/db.tsx | 1 - Cunkebao/src/store/module/ckchat.ts | 205 -------------------------- 2 files changed, 206 deletions(-) delete mode 100644 Cunkebao/src/store/module/ckchat.ts diff --git a/Cunkebao/src/pages/mobile/test/db.tsx b/Cunkebao/src/pages/mobile/test/db.tsx index abb773c4..1c551148 100644 --- a/Cunkebao/src/pages/mobile/test/db.tsx +++ b/Cunkebao/src/pages/mobile/test/db.tsx @@ -30,7 +30,6 @@ import { DatabaseService, } from "@/utils/db"; import { testDatabaseUpgrade, resetDatabase } from "@/utils/db-test"; -import { KfUserListData, GroupData, ContractData } from "@/pages/pc/ckbox/data"; const { Title, Text } = Typography; diff --git a/Cunkebao/src/store/module/ckchat.ts b/Cunkebao/src/store/module/ckchat.ts deleted file mode 100644 index ed62f71a..00000000 --- a/Cunkebao/src/store/module/ckchat.ts +++ /dev/null @@ -1,205 +0,0 @@ -import { createPersistStore } from "@/store/createPersistStore"; -import { CkChatState, CkUserInfo, CkTenant } from "./ckchat/ckchat.data"; -import { - ContractData, - GroupData, - CkAccount, - KfUserListData, -} from "@/pages/pc/ckbox/data"; - -export const useCkChatStore = createPersistStore( - set => ({ - userInfo: null, - isLoggedIn: false, - contractList: [], //联系人列表 - chatSessions: [], //聊天会话 - kfUserList: [], //客服列表 - kfSelected: 0, - newContractList: [], //联系人分组 - kfSelectedUser: () => { - const state = useCkChatStore.getState(); - return state.kfUserList.find(item => item.id === state.kfSelected); - }, - asyncKfSelected: (data: number) => { - set({ kfSelected: data }); - }, - // 异步设置会话列表 - asyncNewContractList: data => { - set({ newContractList: data }); - }, - getNewContractList: () => { - const state = useCkChatStore.getState(); - return state.newContractList; - }, - // 异步设置会话列表 - asyncChatSessions: data => { - set({ chatSessions: data }); - }, - // 异步设置联系人列表 - asyncContractList: data => { - set({ contractList: data }); - }, - // 控制终端用户列表 - getkfUserList: () => { - const state = useCkChatStore.getState(); - return state.kfUserList; - }, - asyncKfUserList: data => { - set({ kfUserList: data }); - }, - // 删除控制终端用户 - deleteCtrlUser: (userId: number) => { - set(state => ({ - kfUserList: state.kfUserList.filter(item => item.id !== userId), - })); - }, - // 更新控制终端用户 - updateCtrlUser: (user: KfUserListData) => { - set(state => ({ - kfUserList: state.kfUserList.map(item => - item.id === user.id ? user : item, - ), - })); - }, - // 清空控制终端用户列表 - clearkfUserList: () => { - set({ kfUserList: [] }); - }, - // 获取聊天会话 - getChatSessions: () => { - const state = useCkChatStore.getState(); - return state.chatSessions; - }, - // 添加聊天会话 - addChatSession: (session: ContractData | GroupData) => { - set(state => { - // 检查是否已存在相同id的会话 - const exists = state.chatSessions.some(item => item.id === session.id); - // 如果已存在则不添加,否则添加到列表中 - return { - chatSessions: exists - ? state.chatSessions - : [...state.chatSessions, session as ContractData | GroupData], - }; - }); - }, - // 更新聊天会话 - updateChatSession: (session: ContractData | GroupData) => { - set(state => ({ - chatSessions: state.chatSessions.map(item => - item.id === session.id ? session : item, - ), - })); - }, - // 删除聊天会话 - deleteChatSession: (sessionId: string) => { - set(state => ({ - chatSessions: state.chatSessions.filter(item => item.id !== sessionId), - })); - }, - // 设置用户信息 - setUserInfo: (userInfo: CkUserInfo) => { - set({ userInfo, isLoggedIn: true }); - }, - - // 清除用户信息 - clearUserInfo: () => { - set({ userInfo: null, isLoggedIn: false }); - }, - - // 更新账户信息 - updateAccount: (account: Partial) => { - set(state => ({ - userInfo: state.userInfo - ? { - ...state.userInfo, - account: { ...state.userInfo.account, ...account }, - } - : null, - })); - }, - - // 更新租户信息 - updateTenant: (tenant: Partial) => { - set(state => ({ - userInfo: state.userInfo - ? { - ...state.userInfo, - tenant: { ...state.userInfo.tenant, ...tenant }, - } - : null, - })); - }, - - // 获取账户ID - getAccountId: () => { - const state = useCkChatStore.getState(); - return Number(state.userInfo?.account?.id) || null; - }, - - // 获取租户ID - getTenantId: () => { - const state = useCkChatStore.getState(); - return state.userInfo?.tenant?.id || null; - }, - - // 获取账户名称 - getAccountName: () => { - const state = useCkChatStore.getState(); - return ( - state.userInfo?.account?.realName || - state.userInfo?.account?.userName || - null - ); - }, - - // 获取租户名称 - getTenantName: () => { - const state = useCkChatStore.getState(); - return state.userInfo?.tenant?.name || null; - }, - }), - { - name: "ckchat-store", - partialize: state => ({ - userInfo: state.userInfo, - isLoggedIn: state.isLoggedIn, - }), - onRehydrateStorage: () => state => { - // console.log("CkChat store hydrated:", state); - }, - }, -); - -// 导出便捷的获取方法 -export const getCkAccountId = () => useCkChatStore.getState().getAccountId(); -export const getCkTenantId = () => useCkChatStore.getState().getTenantId(); -export const getCkAccountName = () => - useCkChatStore.getState().getAccountName(); -export const getCkTenantName = () => useCkChatStore.getState().getTenantName(); -export const getChatSessions = () => - useCkChatStore.getState().getChatSessions(); -export const addChatSession = (session: ContractData | GroupData) => - useCkChatStore.getState().addChatSession(session); -export const updateChatSession = (session: ContractData | GroupData) => - useCkChatStore.getState().updateChatSession(session); -export const deleteChatSession = (sessionId: string) => - useCkChatStore.getState().deleteChatSession(sessionId); -export const getkfUserList = () => useCkChatStore.getState().kfUserList; -export const addCtrlUser = (user: KfUserListData) => - useCkChatStore.getState().addCtrlUser(user); -export const deleteCtrlUser = (userId: number) => - useCkChatStore.getState().deleteCtrlUser(userId); -export const updateCtrlUser = (user: KfUserListData) => - useCkChatStore.getState().updateCtrlUser(user); -export const asyncKfUserList = (data: KfUserListData[]) => - useCkChatStore.getState().asyncKfUserList(data); -export const asyncContractList = (data: ContractData[]) => - useCkChatStore.getState().asyncContractList(data); -export const asyncChatSessions = (data: ContractData[]) => - useCkChatStore.getState().asyncChatSessions(data); -export const asyncNewContractList = ( - data: { groupName: string; contacts: any[] }[], -) => useCkChatStore.getState().asyncNewContractList(data); -export const asyncKfSelected = (data: number) => - useCkChatStore.getState().asyncKfSelected(data);