修复工作人员端令牌失效后的登录恢复

This commit is contained in:
czl231
2026-09-05 19:51:36 +08:00
parent 7ea39334eb
commit 1670d5880f
20 changed files with 849 additions and 46 deletions

View File

@@ -1,8 +1,11 @@
// 功能描述:展示工作人员作业准入检查,并安全处理刷新和会话失效。
// 版本1.1.0
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../../app/dependencies.dart';
import '../../../data/repositories/service_repository.dart';
import '../../../data/services/api_client.dart';
import '../../../domain/models/service_models.dart';
import '../../core/widgets.dart';
@@ -26,11 +29,21 @@ class _PreflightPageState extends State<PreflightPage> {
_future = widget.repository.preflight();
}
/// 创建新的加载任务,并在同步状态回调中替换页面 Future。
void _reload() {
final future = widget.repository.preflight();
setState(() {
_future = future;
});
}
Future<void> _attendance(String action) async {
setState(() => _busy = true);
try {
await widget.repository.attendance(action, widget.session.deviceIdentity);
setState(() => _future = widget.repository.preflight());
if (mounted) _reload();
} on SessionExpiredException {
return;
} catch (error) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(error.toString())));
@@ -48,10 +61,13 @@ class _PreflightPageState extends State<PreflightPage> {
builder: (context, snapshot) {
if (!snapshot.hasData) {
if (snapshot.hasError) {
if (snapshot.error is SessionExpiredException) {
return const Center(child: CircularProgressIndicator());
}
return MessageState(
title: '作业检查加载失败',
description: '请检查网络后重新加载',
onRetry: () => setState(() => _future = widget.repository.preflight()),
onRetry: _reload,
);
}
return const Center(child: CircularProgressIndicator());