fix: Phase 1.3 完善修复 — 管理端对接 + HMS清理 + 编辑器加载
- feat(web): ClassList.tsx 对接 update/deactivate/reset-code API - 编辑班级: PUT /diary/classes/:id - 停用班级: PATCH /diary/classes/:id/deactivate (Popconfirm 确认) - 重置班级码: POST /diary/classes/:id/reset-code (Popconfirm 确认) - 数据源改用 listAll() 获取所有班级 - fix(web): JournalList.tsx 班级筛选改用 classApi.listAll() - fix(app): EditorPage 加载已有日记数据 (journalId 非空时) - 从 Isar 恢复笔画/元素/标签/心情/标题 - _EditorView 改为 StatefulWidget + initState 加载 - chore(web): HMS 遗留代码清理 - 删除 api/copilot.ts, healthFixtures.ts, healthHandlers.ts - AuditLogViewer 资源类型替换为日记模块类型 - auth.test.ts / renderWithProviders 权限码 health.* → diary.* - docs: 确认 M6 NotificationService 为误报 (已在 3 处调用)
This commit is contained in:
@@ -254,7 +254,7 @@ class EditorPage extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _EditorView extends StatelessWidget {
|
||||
class _EditorView extends StatefulWidget {
|
||||
final String? journalId;
|
||||
final String? templateId;
|
||||
final String? savedJournalId;
|
||||
@@ -269,6 +269,67 @@ class _EditorView extends StatelessWidget {
|
||||
required this.onSaveComplete,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_EditorView> createState() => _EditorViewState();
|
||||
}
|
||||
|
||||
class _EditorViewState extends State<_EditorView> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 当 journalId 非空时,从 Isar 加载已有日记数据
|
||||
if (widget.journalId != null) {
|
||||
_loadExistingJournal(widget.journalId!);
|
||||
}
|
||||
}
|
||||
|
||||
/// 从 Isar 加载已有日记的笔画、元素、标签、心情、标题
|
||||
Future<void> _loadExistingJournal(String id) async {
|
||||
try {
|
||||
// 加载日记元数据
|
||||
final entry = await widget.repo.getJournal(id);
|
||||
if (entry == null || !mounted) return;
|
||||
|
||||
final bloc = context.read<EditorBloc>();
|
||||
|
||||
// 加载标题和心情
|
||||
bloc.add(TitleChanged(entry.title));
|
||||
bloc.add(MoodChanged(entry.mood));
|
||||
|
||||
// 加载标签
|
||||
if (entry.tags.isNotEmpty) {
|
||||
bloc.add(TagsLoaded(entry.tags));
|
||||
}
|
||||
|
||||
// 加载元素(含笔画)
|
||||
final elements = await widget.repo.getElements(id);
|
||||
if (!mounted) return;
|
||||
|
||||
for (final element in elements) {
|
||||
if (element.elementType == ElementType.handwritingRef) {
|
||||
// 从 handwriting_ref 元素中恢复笔画
|
||||
final strokesData = element.content['strokes'];
|
||||
if (strokesData is List) {
|
||||
final strokes = strokesData
|
||||
.map((s) => Stroke.fromJson(s as Map<String, dynamic>))
|
||||
.toList();
|
||||
bloc.add(StrokesLoaded(strokes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 加载非笔画元素(贴纸/文字/图片)
|
||||
final nonStrokeElements = elements
|
||||
.where((e) => e.elementType != ElementType.handwritingRef)
|
||||
.toList();
|
||||
if (nonStrokeElements.isNotEmpty) {
|
||||
bloc.add(ElementsLoaded(nonStrokeElements));
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('加载日记数据失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
@@ -288,7 +349,7 @@ class _EditorView extends StatelessWidget {
|
||||
Expanded(
|
||||
child: BlocBuilder<EditorBloc, EditorState>(
|
||||
builder: (context, state) {
|
||||
return _EditorStack(state: state, journalId: journalId);
|
||||
return _EditorStack(state: state, journalId: widget.journalId);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -404,7 +465,7 @@ class _EditorView extends StatelessWidget {
|
||||
|
||||
/// 保存处理
|
||||
void _handleSave(BuildContext context, EditorState state) {
|
||||
onSaveComplete();
|
||||
widget.onSaveComplete();
|
||||
}
|
||||
|
||||
/// 格式化日期显示
|
||||
|
||||
Reference in New Issue
Block a user