From e7c109eab1536168bc4fedd97e54c4dd4d748812 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: Fri, 5 Sep 2025 14:53:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(wechat):=20=E4=BC=98=E5=8C=96=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E6=94=B6=E5=A4=84=E7=90=86=E5=92=8C=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除未使用的kfUserService导入 - 为weChatGroup和ContractData接口添加serverId字段 - 重构receivedMsg方法,根据消息类型从数据库获取会话信息 - 简化数据库表结构,移除冗余的WithServerId接口 --- .../SidebarMenu/MessageList/index.tsx | 5 ++++- Cunkebao/src/pages/pc/ckbox/data.ts | 4 +++- Cunkebao/src/store/module/ckchat/ckchat.ts | 2 +- Cunkebao/src/store/module/weChat/weChat.ts | 19 ++++++++++++------- Cunkebao/src/utils/db.ts | 16 +++------------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx index dfaab7e4..5320c040 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import { List, Avatar, Badge } from "antd"; import { UserOutlined, TeamOutlined } from "@ant-design/icons"; import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data"; @@ -15,6 +15,9 @@ const MessageList: React.FC = () => { const onContactClick = (session: ContractData | weChatGroup) => { setCurrentContact(session, true); }; + // useEffect(() => { + // console.log(chatSessions); + // }, [chatSessions]); return (
( diff --git a/Cunkebao/src/store/module/weChat/weChat.ts b/Cunkebao/src/store/module/weChat/weChat.ts index fb25a99e..a438bfd8 100644 --- a/Cunkebao/src/store/module/weChat/weChat.ts +++ b/Cunkebao/src/store/module/weChat/weChat.ts @@ -8,6 +8,7 @@ import { import { WeChatState } from "./weChat.data"; import { clearUnreadCount, updateConfig } from "@/pages/pc/ckbox/api"; import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data"; +import { weChatGroupService, contractService } from "@/utils/db"; import { addChatSession, updateChatSession, @@ -87,12 +88,12 @@ export const useWeChatStore = create()( })); }, - receivedMsg: message => { + receivedMsg: async message => { const currentContract = useWeChatStore.getState().currentContract; //判断群还是好友 const getMessageId = message?.wechatChatroomId || message.wechatFriendId; - + const isWechatGroup = message?.wechatChatroomId; //当前选中聊天的群或好友 if (currentContract && currentContract.id == getMessageId) { set(state => ({ @@ -106,11 +107,15 @@ export const useWeChatStore = create()( session.unreadCount = Number(session.unreadCount) + 1; updateChatSession(session); } else { - // 新增会话 - addChatSession({ - ...session, - unreadCount: 1, - }); + if (isWechatGroup) { + const [group] = await weChatGroupService.findByIds(getMessageId); + if (group) { + addChatSession(group); + } + } else { + const [user] = await contractService.findByIds(getMessageId); + addChatSession(user); + } } } }, diff --git a/Cunkebao/src/utils/db.ts b/Cunkebao/src/utils/db.ts index 5724fd53..cebcff29 100644 --- a/Cunkebao/src/utils/db.ts +++ b/Cunkebao/src/utils/db.ts @@ -39,16 +39,6 @@ export interface KfUserWithServerId extends Omit { id?: number; // 接口数据的原始ID字段 } -export interface weChatGroupServerId extends Omit { - serverId: number | string; // 服务器ID作为主键 - id?: number; // 接口数据的原始ID字段 -} - -export interface ContractWithServerId extends Omit { - serverId: number | string; // 服务器ID作为主键 - id?: number; // 接口数据的原始ID字段 -} - // 新联系人列表数据接口 export interface NewContactListData { serverId: number | string; // 服务器ID作为主键 @@ -61,8 +51,8 @@ export interface NewContactListData { // 数据库类 class CunkebaoDatabase extends Dexie { kfUsers!: Table; - weChatGroup!: Table; - contracts!: Table; + weChatGroup!: Table; + contracts!: Table; newContractList!: Table; messageList!: Table; @@ -74,7 +64,7 @@ class CunkebaoDatabase extends Dexie { kfUsers: "serverId, id, tenantId, wechatId, nickname, alias, avatar, gender, region, signature, bindQQ, bindEmail, bindMobile, createTime, currentDeviceId, isDeleted, deleteTime, groupId, memo, wechatVersion, lastUpdateTime, isOnline", weChatGroup: - "serverId, id, wechatAccountId, tenantId, accountId, chatroomId, chatroomOwner, conRemark, nickname, chatroomAvatar, groupId, config, unreadCount, notice, selfDisplyName", + "serverId, id, wechatAccountId, tenantId, accountId, chatroomId, chatroomOwner, conRemark, nickname, chatroomAvatar,wechatChatroomId, groupId, config, unreadCount, notice, selfDisplyName", contracts: "serverId, id, wechatAccountId, wechatId, alias, conRemark, nickname, quanPin, avatar, gender, region, addFrom, phone, signature, accountId, extendFields, city, lastUpdateTime, isPassed, tenantId, groupId, thirdParty, additionalPicture, desc, config, lastMessageTime, unreadCount, duplicate", newContractList: "serverId, id, groupName, contacts",