新增文件: - data/local/collections/ 3 个 Isar Collection 定义 + 生成 Schema - data/repositories/isar_journal_repository.dart 完整 CRUD + 乐观锁 修改文件: - app.dart: IsarJournalRepository 注册为主 JournalRepository + SyncEngine 注入 - editor_page.dart: onSave 接入 JournalRepository,笔画/元素自动保存到 Isar - sync_engine.dart: 新增 persistPendingQueue/restorePendingQueue Isar 持久化 - isar_database.dart: 注册 3 个 Collection Schema - main.dart: 启动时初始化 Isar 架构: 离线优先 — Isar 为本地主仓库,Remote 供 SyncEngine 推送
37 lines
844 B
Dart
37 lines
844 B
Dart
// 待同步操作 Isar Collection — SyncEngine 队列持久化
|
||
//
|
||
// 应用退出时将内存队列写入 Isar,下次启动时恢复。
|
||
// 保证离线操作不会因进程终止而丢失。
|
||
|
||
import 'package:isar/isar.dart';
|
||
|
||
part 'pending_operation_collection.g.dart';
|
||
|
||
@collection
|
||
class PendingOperationCollection {
|
||
/// Isar 自增主键
|
||
Id isarId = Isar.autoIncrement;
|
||
|
||
/// 业务 UUID(索引)
|
||
@Index()
|
||
String id = '';
|
||
|
||
/// 操作类型:create / update / delete
|
||
String operationType = 'create';
|
||
|
||
/// API 端点(如 '/diary/journals')
|
||
String endpoint = '';
|
||
|
||
/// 请求负载(JSON String)
|
||
String dataJson = '{}';
|
||
|
||
/// 资源版本号(乐观锁)
|
||
int version = 1;
|
||
|
||
/// 创建时间(epoch milliseconds)
|
||
int createdAtEpoch = 0;
|
||
|
||
/// 重试次数(最大 5 次)
|
||
int retryCount = 0;
|
||
}
|