feat: select school terms and smooth refractive Dock motion

This commit is contained in:
Codex
2026-10-13 19:08:36 +08:00
parent 3e2d8864af
commit 50fcc70e8e
33 changed files with 1245 additions and 94 deletions
+20
View File
@@ -1,4 +1,5 @@
import '../domain/course.dart';
import '../domain/school_term.dart';
import 'dart:convert';
@@ -9,12 +10,14 @@ class ImportDraft {
required this.source,
required this.parserVersion,
this.semesterLabel,
this.schoolTerm,
});
final List<Course> courses;
final bool explicitlyEmpty;
final CourseSource source;
final String parserVersion;
final String? semesterLabel;
final SchoolTerm? schoolTerm;
}
class JsonScheduleImport {
@@ -46,11 +49,28 @@ class JsonScheduleImport {
if (courses.map((c) => c.id).toSet().length != courses.length) {
throw const FormatException('课程标识重复');
}
final termIds = courses
.map((c) => RegExp(r'^uestc-(\d+)-').firstMatch(c.id)?.group(1))
.whereType<String>()
.toSet();
final term = json['schoolTerm'] != null
? SchoolTerm.fromJson(
Map<String, dynamic>.from(json['schoolTerm'] as Map),
)
: termIds.length == 1
? SchoolTerm(int.parse(termIds.single))
: null;
if (termIds.length > 1 ||
(term != null && termIds.any((id) => id != term.id.toString()))) {
throw const FormatException('文件中包含不同学期的课程');
}
return ImportDraft(
courses: List.unmodifiable(courses),
explicitlyEmpty: json['explicitlyEmpty'] == true,
source: source,
parserVersion: 'json-v1',
schoolTerm: source == CourseSource.demo ? null : term,
semesterLabel: term?.label,
);
} on FormatException {
rethrow;