diff --git a/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/WechatFriends/extend.ts b/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/WechatFriends/extend.ts index f9a3b3c8..220c4d56 100644 --- a/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/WechatFriends/extend.ts +++ b/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/WechatFriends/extend.ts @@ -206,8 +206,13 @@ export const getGroupStatistics = async ( labels: ContactGroupByLabel[], customerId?: number, ): Promise => { - const realGroupIds = labels - .filter(item => item.id !== 0) + // 分别提取好友标签和群标签的ID + const friendGroupIds = labels + .filter(item => item.id !== 0 && Number(item.groupType) === 1) + .map(item => item.id); + + const chatGroupIds = labels + .filter(item => item.id !== 0 && Number(item.groupType) === 2) .map(item => item.id); const groupedData: ContactGroupByLabel[] = []; @@ -218,12 +223,12 @@ export const getGroupStatistics = async ( if (Number(label.groupType) === 1) { // 好友分组 if (label.id === 0) { - // 未分组:不属于任何标签的好友 + // 未分组:不属于任何好友标签的好友 count = await ContactManager.getContactCount( userId, "friend", customerId, - realGroupIds, + friendGroupIds, // 只排除好友标签 true, // 排除已分组的 ); } else { @@ -239,12 +244,12 @@ export const getGroupStatistics = async ( } else if (Number(label.groupType) === 2) { // 群组分组 if (label.id === 0) { - // 默认群分组:不属于任何标签的群 + // 默认群分组:不属于任何群标签的群 count = await ContactManager.getContactCount( userId, "group", customerId, - realGroupIds, + chatGroupIds, // 只排除群标签 true, // 排除已分组的 ); } else { diff --git a/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/WechatFriends/index.tsx b/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/WechatFriends/index.tsx index 22b4c34b..deed4a02 100644 --- a/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/WechatFriends/index.tsx +++ b/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/WechatFriends/index.tsx @@ -174,8 +174,13 @@ const ContactListSimple: React.FC = ({ })); try { + // 根据当前标签的 groupType 计算正确的 realGroupIds const realGroupIds = labels - .filter(item => item.id !== 0) + .filter( + item => + item.id !== 0 && + Number(item.groupType) === Number(label.groupType), + ) .map(item => item.id); const contacts = await getContactsByGroup( @@ -231,8 +236,13 @@ const ContactListSimple: React.FC = ({ const currentPage = groupData.pages[groupKey] || 1; const nextPage = currentPage + 1; + // 根据当前标签的 groupType 计算正确的 realGroupIds const realGroupIds = labels - .filter(item => item.id !== 0) + .filter( + item => + item.id !== 0 && + Number(item.groupType) === Number(label.groupType), + ) .map(item => item.id); const newContacts = await getContactsByGroup( diff --git a/Touchkebao/src/utils/dbAction/contact.ts b/Touchkebao/src/utils/dbAction/contact.ts index 501c6289..1f0ced1a 100644 --- a/Touchkebao/src/utils/dbAction/contact.ts +++ b/Touchkebao/src/utils/dbAction/contact.ts @@ -326,6 +326,14 @@ export class ContactManager { exclude: boolean = false, ): Promise { try { + console.log("getContactCount 调用参数:", { + userId, + type, + customerId, + groupIds, + exclude, + }); + const conditions: any[] = [ { field: "userId", operator: "equals", value: userId }, { field: "type", operator: "equals", value: type }, @@ -353,14 +361,21 @@ export class ContactManager { // 包含指定分组 conditions.push({ field: "groupId", - operator: "in", + operator: "anyOf", value: groupIds, }); } } + console.log("查询条件:", conditions); + const contacts = await contactUnifiedService.findWhereMultiple(conditions); + + console.log( + `查询结果数量: ${contacts.length}, type: ${type}, groupIds: ${groupIds}`, + ); + return contacts.length; } catch (error) { console.error("获取联系人数量失败:", error); @@ -408,7 +423,7 @@ export class ContactManager { // 包含指定分组 conditions.push({ field: "groupId", - operator: "in", + operator: "anyOf", value: groupIds, }); }