fix(app): Phase 1.1 紧急修复 — SyncEngine 接入 + authorId + catch 异常处理
Some checks failed
Main Merge / backend (push) Has been cancelled
Main Merge / frontend (push) Has been cancelled

- feat(sync): SyncEngine 接入 EditorPage, 保存时 enqueue + 网络恢复自动 trySync
- fix(editor): authorId 从 AuthBloc 获取, 替代硬编码 'local'
- fix(bloc): class_bloc/calendar/profile/parent catch(_).全部改为 debugPrint
- feat(editor): 编辑器工具栏拆分 (brush_panel/tag_panel/text_format_bar/dot_grid_painter)
- feat(editor): EditorBloc 扩展 + EditorPage 增强
- feat(search): SearchBloc 扩展搜索功能
- feat(home): HomeBloc/HomePage 增强
- feat(auth): LoginPage 增强
- feat(templates): TemplateGalleryPage 重构
- fix(web): 管理端班级/日记页面修复
- fix(server): comment_service + theme_handler 修复
- docs: 添加全链路审计报告和验证截图
This commit is contained in:
iven
2026-06-02 21:21:43 +08:00
parent 7e928ae1e1
commit 49d4aa36a7
55 changed files with 2738 additions and 677 deletions

View File

@@ -1,5 +1,6 @@
// 班级 BLoC — 通过 ClassRepository 管理班级数据
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:nuanji_app/data/models/journal_entry.dart';
import 'package:nuanji_app/data/models/school_class.dart';
@@ -117,9 +118,14 @@ final class ClassLoading extends ClassState {
final class ClassListLoaded extends ClassState {
final List<SchoolClass> classes;
final bool isLoading;
const ClassListLoaded({this.classes = const [], this.isLoading = false});
ClassListLoaded copyWith({List<SchoolClass>? classes, bool? isLoading}) =>
ClassListLoaded(classes: classes ?? this.classes, isLoading: isLoading ?? this.isLoading);
final String? error;
const ClassListLoaded({this.classes = const [], this.isLoading = false, this.error});
ClassListLoaded copyWith({List<SchoolClass>? classes, bool? isLoading, String? error, bool clearError = false}) =>
ClassListLoaded(
classes: classes ?? this.classes,
isLoading: isLoading ?? this.isLoading,
error: clearError ? null : (error ?? this.error),
);
}
final class ClassDetailLoaded extends ClassState {
@@ -209,7 +215,8 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
final classes = await _classRepo.getMyClasses();
emit(ClassListLoaded(classes: classes));
} catch (e) {
emit(ClassListLoaded(classes: const []));
debugPrint('ClassBloc._onLoadMyClasses 失败: $e');
emit(const ClassListLoaded());
}
}
@@ -224,7 +231,8 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
add(ClassLoadMembers(event.classId));
add(ClassLoadTopics(event.classId));
} catch (e) {
emit(ClassError('加载班级失败: $e'));
debugPrint('ClassBloc._onClassSelected 失败: $e');
emit(const ClassError('加载班级失败,请重试'));
}
}
@@ -247,7 +255,8 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
))
.toList();
emit(current.copyWith(members: members, isLoadingMembers: false));
} catch (_) {
} catch (e) {
debugPrint('ClassBloc._onLoadMembers 失败: $e');
emit(current.copyWith(isLoadingMembers: false));
}
}
@@ -266,7 +275,8 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
final classJournals = journals.where((j) => j.sharedToClass).toList();
emit(current.copyWith(diaryWall: classJournals, isLoadingWall: false));
} catch (_) {
} catch (e) {
debugPrint('ClassBloc._onLoadDiaryWall 失败: $e');
emit(current.copyWith(isLoadingWall: false));
}
}
@@ -292,8 +302,9 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
))
.toList();
emit(current.copyWith(topics: topics));
} catch (_) {
// 静默失败,保留空列表
} catch (e) {
debugPrint('ClassBloc._onLoadTopics 失败: $e');
// 保留空列表
}
}
@@ -316,7 +327,8 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
))
.toList();
emit(current.copyWith(comments: comments, selectedJournalId: event.journalId));
} catch (_) {
} catch (e) {
debugPrint('ClassBloc._onLoadComments 失败: $e');
emit(current.copyWith(selectedJournalId: event.journalId));
}
}
@@ -335,7 +347,11 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
emit(current.copyWith(classes: [...current.classes, newClass]));
}
} catch (e) {
// 创建失败不改变状态
debugPrint('ClassBloc._onCreateClass 失败: $e');
// 创建失败不改变状态,但通知 UI
if (state is ClassListLoaded) {
emit((state as ClassListLoaded).copyWith(error: '创建班级失败,请重试'));
}
}
}
@@ -364,8 +380,12 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
);
emit(current.copyWith(topics: [newTopic, ...current.topics]));
}
} catch (_) {
// 静默失败
} catch (e) {
debugPrint('ClassBloc._onTopicAssign 失败: $e');
// 通知 UI 布置失败
if (state is ClassDetailLoaded) {
emit((state as ClassDetailLoaded).copyWith(error: '话题布置失败,请重试'));
}
}
}
@@ -378,7 +398,8 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
// 加入成功后刷新列表
add(const ClassLoadMyClasses());
} catch (e) {
emit(ClassError('加入班级失败: $e'));
debugPrint('ClassBloc._onJoinClass 失败: $e');
emit(const ClassError('加入班级失败,请检查班级码'));
}
}
@@ -397,6 +418,7 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
// 创建成功后重新加载评语列表
add(ClassLoadComments(event.journalId));
} catch (e) {
debugPrint('ClassBloc._onCommentCreate 失败: $e');
emit(currentState.copyWith(error: '评语发布失败'));
}
}