feat: select school before connecting timetable

This commit is contained in:
Codex
2026-10-14 20:58:47 +08:00
parent ce21cdc10c
commit d83481d965
12 changed files with 297 additions and 20 deletions
+2 -2
View File
@@ -1,2 +1,2 @@
const appVersion = '0.6.1';
const appBuildNumber = 16;
const appVersion = '0.6.2';
const appBuildNumber = 17;
+50 -4
View File
@@ -14,6 +14,7 @@ import '../features/exams/exams_page.dart';
import '../features/timetable/timetable_page.dart';
import '../features/profile/profile_page.dart';
import '../features/school/school_session.dart';
import '../features/school/school_selection_page.dart';
class HepanApp extends StatelessWidget {
const HepanApp({
@@ -66,6 +67,16 @@ class _Shell extends StatefulWidget {
class _ShellState extends State<_Shell> with WidgetsBindingObserver {
int _tab = 0;
bool _openingSchool = false;
SupportedSchool? _selectedSchool;
// Earlier imports all belong to UESTC graduate; reuse their existing term
// and session without requiring students to choose again on every refresh.
SupportedSchool? get _knownSchool =>
_selectedSchool ??
(widget.controller.snapshot.schoolTerm != null ||
widget.school?.canLogout == true
? SupportedSchool.uestcGraduate
: null);
void _selectTab(int index) {
if (index == _tab) return;
setState(() => _tab = index);
@@ -121,7 +132,41 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
}
}
void _school({bool exams = false, bool chooseTerm = false}) {
Future<void> _school({
bool exams = false,
bool chooseTerm = false,
bool selectSchool = false,
}) async {
if (_openingSchool) return;
_openingSchool = true;
try {
var selected = _knownSchool;
if (selectSchool || selected == null) {
selected = await Navigator.push<SupportedSchool>(
context,
MaterialPageRoute<SupportedSchool>(
builder: (_) => SchoolSelectionPage(selected: _knownSchool),
),
);
if (!mounted || selected == null) return;
setState(() => _selectedSchool = selected);
}
if (!mounted) return;
// The only current connector is the existing UESTC graduate workflow.
// A new catalog option must provide its own connector here.
switch (selected) {
case SupportedSchool.uestcGraduate:
await _openSchool(exams: exams, chooseTerm: chooseTerm);
}
} finally {
_openingSchool = false;
}
}
Future<void> _openSchool({
bool exams = false,
bool chooseTerm = false,
}) async {
if (widget.schoolBuilder != null) {
final term = widget.controller.snapshot.schoolTerm;
if (exams) {
@@ -135,12 +180,12 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
chooseTerm: chooseTerm || term == null,
);
}
Navigator.push(
await Navigator.push(
context,
MaterialPageRoute<void>(builder: (_) => widget.schoolBuilder!()),
);
} else {
showDialog<void>(
await showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: const Text('学校认证'),
@@ -275,7 +320,8 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
ProfilePage(
controller: widget.controller,
feedbackSender: widget.feedbackSender,
onLogin: _school,
onLogin: () => _school(selectSchool: true),
schoolName: _knownSchool?.label,
onUpdateTerm: () => _school(chooseTerm: true),
authStatus: widget.school?.statusLabel ?? '未登录',
logoutLabel: widget.school?.logoutFailed == true
+1 -1
View File
@@ -118,7 +118,7 @@ class ExamsPage extends StatelessWidget {
),
const SizedBox(height: 12),
const Text(
'连接研究生系统,或导入学校考试页面的 HTML。',
'选择学校连接教务系统,或导入学校考试页面的 HTML。',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 13, height: 1.8),
),
@@ -18,6 +18,7 @@ class ProfilePage extends StatelessWidget {
super.key,
required this.controller,
required this.onLogin,
this.schoolName,
this.authStatus = '未登录',
this.onLogout,
this.logoutLabel = '退出学校登录',
@@ -26,6 +27,7 @@ class ProfilePage extends StatelessWidget {
});
final AppController controller;
final VoidCallback onLogin;
final String? schoolName;
final VoidCallback? onLogout;
final VoidCallback? onUpdateTerm;
final String authStatus, logoutLabel;
@@ -98,12 +100,12 @@ class ProfilePage extends StatelessWidget {
),
const SizedBox(height: 16),
const Text(
'连接学校课表',
'学校课表',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700),
),
const SizedBox(height: 7),
Text(
'电子科技大学 · 研究生\n$authStatus',
'${schoolName ?? '选择学校后连接教务系统'}\n$authStatus',
style: TextStyle(
fontSize: 12,
height: 1.8,
@@ -115,7 +117,7 @@ class ProfilePage extends StatelessWidget {
width: double.infinity,
child: FilledButton(
onPressed: onLogin,
child: Text(onLogout == null ? '登录学校账户' : '打开学校课表'),
child: const Text('选择学校'),
),
),
if (onLogout != null)
@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
import '../../app/app_theme.dart';
/// Only list schools whose login and import workflow is available.
enum SupportedSchool {
uestcGraduate('电子科技大学(研究生)', '研究生课表与考试安排');
const SupportedSchool(this.label, this.description);
final String label, description;
}
class SchoolSelectionPage extends StatelessWidget {
const SchoolSelectionPage({super.key, this.selected});
final SupportedSchool? selected;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('选择学校')),
body: SafeArea(
top: false,
child: ListView(
padding: const EdgeInsets.fromLTRB(22, 16, 22, 24),
children: [
Text(
'选择你的学校,登录后导入课表和考试。',
style: TextStyle(fontSize: 13, color: ink.withValues(alpha: 0.6)),
),
const SizedBox(height: 20),
for (final school in SupportedSchool.values) ...[
SurfaceCard(
padding: EdgeInsets.zero,
child: ListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
leading: const Icon(Icons.school_rounded, color: river),
title: Text(
school.label,
style: const TextStyle(fontWeight: FontWeight.w600),
),
subtitle: Text(school.description),
trailing: Icon(
school == selected
? Icons.check_circle_rounded
: Icons.chevron_right_rounded,
color: river,
),
onTap: () => Navigator.pop(context, school),
),
),
const SizedBox(height: 12),
],
],
),
),
);
}