新增文件: - 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 推送
64 lines
1.4 KiB
Dart
64 lines
1.4 KiB
Dart
// 日记元素 Isar Collection — 本地持久化存储
|
||
//
|
||
// 与纯 Dart 模型 JournalElement 分离,通过转换函数桥接。
|
||
// journalId 索引支持按日记查询所有元素。
|
||
|
||
import 'package:isar/isar.dart';
|
||
|
||
part 'journal_element_collection.g.dart';
|
||
|
||
@collection
|
||
class JournalElementCollection {
|
||
/// Isar 自增主键
|
||
Id isarId = Isar.autoIncrement;
|
||
|
||
/// 业务 UUID(索引)
|
||
@Index()
|
||
String id = '';
|
||
|
||
/// 所属日记 ID(索引,用于外键查询)
|
||
@Index()
|
||
String journalId = '';
|
||
|
||
/// 元素类型(enum → string: text/image/sticker/handwriting_ref/tape)
|
||
String elementType = 'text';
|
||
|
||
/// X 坐标
|
||
double positionX = 0;
|
||
|
||
/// Y 坐标
|
||
double positionY = 0;
|
||
|
||
/// 宽度
|
||
double width = 100;
|
||
|
||
/// 高度
|
||
double height = 100;
|
||
|
||
/// 旋转角度
|
||
double rotation = 0;
|
||
|
||
/// 层级
|
||
int zIndex = 0;
|
||
|
||
/// 结构化内容(JSON String)
|
||
/// text: {'text':'...','fontSize':16.0}
|
||
/// image: {'filePath':'...'}
|
||
/// sticker: {'stickerPackId':'...','stickerId':'...'}
|
||
/// handwriting_ref: {'strokesJson':'...','strokeCount':42}
|
||
/// tape: {'tapeStyle':'washi_dots'}
|
||
String contentJson = '{}';
|
||
|
||
/// 版本号(乐观锁)
|
||
int version = 1;
|
||
|
||
/// 创建时间(epoch milliseconds)
|
||
int createdAtEpoch = 0;
|
||
|
||
/// 更新时间(epoch milliseconds)
|
||
int updatedAtEpoch = 0;
|
||
|
||
/// 软删除标记
|
||
bool isDeleted = false;
|
||
}
|