重构PushTaskModal和PushTask组件以实现好友和消息发送的默认间隔。增强间隔状态管理,并在联系步骤中集成流量池选择。更新样式以改进布局和用户体验。

This commit is contained in:
2025-11-12 12:21:04 +08:00
parent 87d1e1c44f
commit f28f9049d5
9 changed files with 574 additions and 99 deletions

View File

@@ -7,6 +7,7 @@
* 4. 提供回调机制通知组件更新
*/
import Dexie from "dexie";
import { db, chatSessionService, ChatSession } from "../db";
import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
@@ -243,7 +244,9 @@ export class MessageManager {
"userId",
userId,
)) as ChatSession[];
const localSessionMap = new Map(localSessions.map(s => [s.id, s]));
const localSessionMap = new Map(
localSessions.map(session => [session.serverId, session]),
);
// 2. 转换服务器数据为统一格式
const serverSessions: ChatSession[] = [];
@@ -264,16 +267,18 @@ export class MessageManager {
serverSessions.push(...groups);
}
const serverSessionMap = new Map(serverSessions.map(s => [s.id, s]));
const serverSessionMap = new Map(
serverSessions.map(session => [session.serverId, session]),
);
// 3. 计算差异
const toAdd: ChatSession[] = [];
const toUpdate: ChatSession[] = [];
const toDelete: number[] = [];
const toDelete: string[] = [];
// 检查新增和更新
for (const serverSession of serverSessions) {
const localSession = localSessionMap.get(serverSession.id);
const localSession = localSessionMap.get(serverSession.serverId);
if (!localSession) {
toAdd.push(serverSession);
@@ -286,8 +291,8 @@ export class MessageManager {
// 检查删除
for (const localSession of localSessions) {
if (!serverSessionMap.has(localSession.id)) {
toDelete.push(localSession.id);
if (!serverSessionMap.has(localSession.serverId)) {
toDelete.push(localSession.serverId);
}
}
@@ -334,7 +339,19 @@ export class MessageManager {
serverId: `${session.type}_${session.id}`,
}));
await db.chatSessions.bulkAdd(dataToInsert);
try {
await db.chatSessions.bulkAdd(dataToInsert);
} catch (error) {
if (error instanceof Dexie.BulkError) {
console.warn(
`批量新增会话时检测到重复主键,切换为 bulkPut 以覆盖更新。错误详情:`,
error,
);
await db.chatSessions.bulkPut(dataToInsert);
} else {
throw error;
}
}
}
/**
@@ -357,14 +374,16 @@ export class MessageManager {
*/
private static async batchDeleteSessions(
userId: number,
sessionIds: number[],
serverIds: string[],
) {
if (sessionIds.length === 0) return;
if (serverIds.length === 0) return;
const serverIdSet = new Set(serverIds);
await db.chatSessions
.where("userId")
.equals(userId)
.and(session => sessionIds.includes(session.id))
.and(session => serverIdSet.has(session.serverId))
.delete();
}