Files
nj/app/lib/data/local/collections/journal_element_collection.dart
iven 2481c8fce6 feat(app): Isar 本地数据库集成 — Collection + Repository + 编辑器持久化 + SyncEngine 队列
新增文件:
- 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 推送
2026-06-01 14:41:40 +08:00

64 lines
1.4 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 日记元素 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;
}