From 66241f32afe0f21acbbc0eac94e0a8c2b8f89509 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 11:47:40 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat(=E5=BE=AE=E4=BF=A1):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0wechatChatroomId=E5=AD=97=E6=AE=B5=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=B6=88=E6=81=AF=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在weChatGroup接口中添加wechatChatroomId字段 - 移除调试用的console.log语句 - 重构消息处理逻辑,简化条件判断并新增会话初始化处理 --- .../components/MessageRecord/index.tsx | 1 - Cunkebao/src/pages/pc/ckbox/data.ts | 1 + Cunkebao/src/store/module/weChat/weChat.ts | 20 +++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx index 3c059ad9..229f0cb2 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx @@ -18,7 +18,6 @@ const MessageRecord: React.FC = ({ contract }) => { ); useEffect(() => { - console.log(currentMessages); scrollToBottom(); }, [currentMessages]); diff --git a/Cunkebao/src/pages/pc/ckbox/data.ts b/Cunkebao/src/pages/pc/ckbox/data.ts index 089d8935..1a5f14e6 100644 --- a/Cunkebao/src/pages/pc/ckbox/data.ts +++ b/Cunkebao/src/pages/pc/ckbox/data.ts @@ -119,6 +119,7 @@ export interface weChatGroup { unreadCount: number; notice: string; selfDisplyName: string; + wechatChatroomId: number; [key: string]: any; } diff --git a/Cunkebao/src/store/module/weChat/weChat.ts b/Cunkebao/src/store/module/weChat/weChat.ts index 4ab64187..fb25a99e 100644 --- a/Cunkebao/src/store/module/weChat/weChat.ts +++ b/Cunkebao/src/store/module/weChat/weChat.ts @@ -91,18 +91,10 @@ export const useWeChatStore = create()( const currentContract = useWeChatStore.getState().currentContract; //判断群还是好友 const getMessageId = - currentContract?.chatroomId || message.wechatFriendId; - const isGroup = currentContract?.chatroomId; + message?.wechatChatroomId || message.wechatFriendId; - if ( - currentContract && - currentContract.wechatAccountId == message.wechatAccountId && - currentContract.id == getMessageId - ) { - console.log("进入"); - if (isGroup) { - message.unreadCount = 1; - } + //当前选中聊天的群或好友 + if (currentContract && currentContract.id == getMessageId) { set(state => ({ currentMessages: [...state.currentMessages, message], })); @@ -113,6 +105,12 @@ export const useWeChatStore = create()( if (session) { session.unreadCount = Number(session.unreadCount) + 1; updateChatSession(session); + } else { + // 新增会话 + addChatSession({ + ...session, + unreadCount: 1, + }); } } }, 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 2/6] =?UTF-8?q?refactor(wechat):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A5=E6=94=B6=E5=A4=84=E7=90=86=E5=92=8C?= =?UTF-8?q?=E6=95=B0=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", From 70256b252c55333fe665d6391140ed041501ff64 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:55:24 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix(chat):=20=E4=BF=AE=E5=A4=8D=E6=96=B0?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E6=9C=AA=E8=AF=BB=E8=AE=A1=E6=95=B0=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除ckchat.ts中自动设置unreadCount为0的逻辑,改为在weChat.ts中添加会话时显式设置unreadCount为1,确保新消息有正确未读标记 --- .../ckbox/components/SidebarMenu/MessageList/index.tsx | 6 ++---- Cunkebao/src/store/module/ckchat/ckchat.ts | 1 - Cunkebao/src/store/module/weChat/weChat.ts | 10 ++++++++-- 3 files changed, 10 insertions(+), 7 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 5320c040..f0ea752c 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, { useEffect } from "react"; +import React from "react"; import { List, Avatar, Badge } from "antd"; import { UserOutlined, TeamOutlined } from "@ant-design/icons"; import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data"; @@ -15,9 +15,7 @@ const MessageList: React.FC = () => { const onContactClick = (session: ContractData | weChatGroup) => { setCurrentContact(session, true); }; - // useEffect(() => { - // console.log(chatSessions); - // }, [chatSessions]); + return (
( })(), // 添加聊天会话 addChatSession: (session: ContractData | weChatGroup) => { - session.unreadCount = 0; set(state => { // 检查是否已存在相同id的会话 const exists = state.chatSessions.some(item => item.id === session.id); diff --git a/Cunkebao/src/store/module/weChat/weChat.ts b/Cunkebao/src/store/module/weChat/weChat.ts index a438bfd8..1a90497e 100644 --- a/Cunkebao/src/store/module/weChat/weChat.ts +++ b/Cunkebao/src/store/module/weChat/weChat.ts @@ -110,11 +110,17 @@ export const useWeChatStore = create()( if (isWechatGroup) { const [group] = await weChatGroupService.findByIds(getMessageId); if (group) { - addChatSession(group); + addChatSession({ + ...group, + unreadCount: 1, + }); } } else { const [user] = await contractService.findByIds(getMessageId); - addChatSession(user); + addChatSession({ + ...user, + unreadCount: 1, + }); } } } From 25da77a3b18a24745ca39e10434a28d561ac339e 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 15:08:52 +0800 Subject: [PATCH 4/6] =?UTF-8?q?refactor(ChatWindow):=20=E4=BD=BF=E7=94=A8A?= =?UTF-8?q?ntd=20Divider=E6=9B=BF=E6=8D=A2=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=88=86=E9=9A=94=E7=BA=BF=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除MessageRecord.module.scss中自定义的时间分隔线样式,改为使用Antd的Divider组件 --- .../MessageRecord/MessageRecord.module.scss | 21 +------------------ .../components/MessageRecord/index.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/MessageRecord.module.scss b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/MessageRecord.module.scss index cfd65086..96fe8a3e 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/MessageRecord.module.scss +++ b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/MessageRecord.module.scss @@ -33,25 +33,6 @@ font-size: 12px; margin: 8px 0; position: relative; - - &::before { - content: ''; - position: absolute; - top: 50%; - left: 0; - right: 0; - height: 1px; - background: #e8e8e8; - z-index: 0; - } - - &::after { - content: attr(data-time); - background: #f5f5f5; - padding: 0 12px; - position: relative; - z-index: 1; - } } // 消息项 @@ -235,4 +216,4 @@ max-width: 150px; max-height: 150px; } -} \ No newline at end of file +} diff --git a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx index 229f0cb2..e2ea13bb 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/ChatWindow/components/MessageRecord/index.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useRef } from "react"; -import { Avatar } from "antd"; +import { Avatar, Divider } from "antd"; import { UserOutlined } from "@ant-design/icons"; import { ChatRecord, ContractData, weChatGroup } from "@/pages/pc/ckbox/data"; import { formatWechatTime } from "@/utils/common"; @@ -194,7 +194,9 @@ const MessageRecord: React.FC = ({ contract }) => {
{groupMessagesByTime(currentMessages).map((group, groupIndex) => ( -
{group.time}
+ +
{group.time}
+
{group.messages.map(renderMessage)}
))} From f76029c2d9b2810735b6ffe6f8eefb6a6bf90747 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 15:14:36 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E7=BE=A4=E7=BB=84?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=88=B0=E5=BE=AE=E4=BF=A1=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?ID=E5=8E=BB=E9=87=8D=E9=80=BB=E8=BE=91=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cunkebao/src/pages/pc/ckbox/main.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Cunkebao/src/pages/pc/ckbox/main.ts b/Cunkebao/src/pages/pc/ckbox/main.ts index 3a75ec00..19f6cf62 100644 --- a/Cunkebao/src/pages/pc/ckbox/main.ts +++ b/Cunkebao/src/pages/pc/ckbox/main.ts @@ -233,6 +233,13 @@ export const getUniqueWechatAccountIds = ( } }); + // 遍历联系人列表,将每个wechatAccountId添加到Set中 + groupList.forEach(group => { + if (group && group.wechatAccountId) { + uniqueAccountIdsSet.add(group.wechatAccountId); + } + }); + // 将Set转换为数组并返回 return Array.from(uniqueAccountIdsSet); }; From afa58712cffd82506cb46fd08b7d0be7a8d7b221 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 15:22:26 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix(MessageList):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BB=8Estore=E8=8E=B7=E5=8F=96chatSessions=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用getChatSessions方法替代直接访问chatSessions状态,确保获取的是最新数据 --- .../pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f0ea752c..14c68a3d 100644 --- a/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx +++ b/Cunkebao/src/pages/pc/ckbox/components/SidebarMenu/MessageList/index.tsx @@ -11,7 +11,7 @@ interface MessageListProps {} const MessageList: React.FC = () => { const { setCurrentContact, currentContract } = useWeChatStore(); - const chatSessions = useCkChatStore(state => state.chatSessions); + const chatSessions = useCkChatStore(state => state.getChatSessions()); const onContactClick = (session: ContractData | weChatGroup) => { setCurrentContact(session, true); };