From d110c9742445cdfe414758afd9dd288c6188f166 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: Thu, 18 Sep 2025 15:04:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=95=B0=E6=8D=AE=E5=BA=93):=20=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=AC=A6=E5=B9=B6=E4=BC=98=E5=8C=96=E8=81=94=E7=B3=BB?= =?UTF-8?q?=E4=BA=BA=E5=88=86=E7=BB=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 DatabaseService 中添加新的查询操作符(notEqual, aboveOrEqual, belowOrEqual, contains, anyOf, notIn, between) - 修改 createContractList 方法以支持未分组联系人的查询 - 添加调试日志用于跟踪缓存结果和真实分组 --- Touchkebao/src/store/module/ckchat/api.ts | 30 ++++++++++++++++---- Touchkebao/src/store/module/ckchat/ckchat.ts | 2 ++ Touchkebao/src/utils/db.ts | 30 ++++++++++++++++++-- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/Touchkebao/src/store/module/ckchat/api.ts b/Touchkebao/src/store/module/ckchat/api.ts index 5c91f734..c10f10d5 100644 --- a/Touchkebao/src/store/module/ckchat/api.ts +++ b/Touchkebao/src/store/module/ckchat/api.ts @@ -12,16 +12,36 @@ export const createContractList = async ( countLables: ContactGroupByLabel[], ) => { // 根据 groupType 决定查询不同的服务 + const realGroup = countLables + .filter(item => item.id !== 0) + .map(item => item.id); + console.log(realGroup); + const dataByLabels = []; for (const label of countLables) { let data; if (label.groupType === 1) { - // groupType: 1, 查询 contractService - data = await contractService.findWhere("groupId", label.id); - // 过滤出 kfSelected 对应的联系人 - if (kfSelected && kfSelected != 0) { - data = data.filter(contact => contact.wechatAccountId === kfSelected); + console.log(label.groupName); + if (label.id == 0) { + data = await contractService.findWhereMultiple([ + { + field: "groupId", + operator: "notIn", + value: realGroup, + }, + ]); + // 过滤出 kfSelected 对应的联系人 + if (kfSelected && kfSelected != 0) { + data = data.filter(contact => contact.wechatAccountId === kfSelected); + } + } else { + data = await contractService.findWhere("groupId", label.id); + // 过滤出 kfSelected 对应的联系人 + if (kfSelected && kfSelected != 0) { + data = data.filter(contact => contact.wechatAccountId === kfSelected); + } } + // console.log(`标签 ${label.groupName} 对应的联系人数据:`, data); } else if (label.groupType === 2) { // groupType: 2, 查询 weChatGroupService diff --git a/Touchkebao/src/store/module/ckchat/ckchat.ts b/Touchkebao/src/store/module/ckchat/ckchat.ts index 1b44fcbe..57fefccf 100644 --- a/Touchkebao/src/store/module/ckchat/ckchat.ts +++ b/Touchkebao/src/store/module/ckchat/ckchat.ts @@ -131,6 +131,8 @@ export const useCkChatStore = createPersistStore( lastSearchKeyword = state.searchKeyword; } + console.log("cachedResult", cachedResult); + return cachedResult; }; })(), diff --git a/Touchkebao/src/utils/db.ts b/Touchkebao/src/utils/db.ts index e225a564..fb1a179f 100644 --- a/Touchkebao/src/utils/db.ts +++ b/Touchkebao/src/utils/db.ts @@ -238,27 +238,53 @@ export class DatabaseService { async findWhereMultiple( conditions: { field: keyof T; - operator: "equals" | "above" | "below" | "startsWith"; + operator: + | "equals" + | "notEqual" + | "above" + | "below" + | "aboveOrEqual" + | "belowOrEqual" + | "startsWith" + | "anyOf" + | "notIn" + | "between" + | "contains"; value: any; + value2?: any; // 用于 between 操作符 }[], ): Promise { let collection = this.table.toCollection(); for (const condition of conditions) { - const { field, operator, value } = condition; + const { field, operator, value, value2 } = condition; collection = collection.and(item => { const fieldValue = (item as any)[field]; switch (operator) { case "equals": return fieldValue === value; + case "notEqual": + return fieldValue !== value; case "above": return fieldValue > value; case "below": return fieldValue < value; + case "aboveOrEqual": + return fieldValue >= value; + case "belowOrEqual": + return fieldValue <= value; case "startsWith": return ( typeof fieldValue === "string" && fieldValue.startsWith(value) ); + case "contains": + return typeof fieldValue === "string" && fieldValue.includes(value); + case "anyOf": + return Array.isArray(value) && value.includes(fieldValue); + case "notIn": + return Array.isArray(value) && !value.includes(fieldValue); + case "between": + return fieldValue >= value && fieldValue <= (value2 ?? value); default: return true; }