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; }