修复工作人员端令牌失效后的登录恢复
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// 功能描述:展示工作人员任务详情,并安全处理业务操作、刷新和会话失效。
|
||||
// 版本:1.1.0
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
@@ -6,6 +8,7 @@ import 'package:uuid/uuid.dart';
|
||||
import '../../../app/dependencies.dart';
|
||||
import '../../../data/offline/encrypted_draft_store.dart';
|
||||
import '../../../data/repositories/service_repository.dart';
|
||||
import '../../../data/services/api_client.dart';
|
||||
import '../../../domain/models/service_models.dart';
|
||||
import '../../core/widgets.dart';
|
||||
|
||||
@@ -41,6 +44,14 @@ class _WorkDetailPageState extends State<WorkDetailPage> {
|
||||
? widget.repository.deliveryDetail(widget.identity)
|
||||
: widget.repository.ticketDetail(widget.identity);
|
||||
|
||||
/// 创建新的加载任务,并在同步状态回调中替换页面 Future。
|
||||
void _reload() {
|
||||
final future = _load();
|
||||
setState(() {
|
||||
_future = future;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _run(
|
||||
Future<void> Function(WorkItem) action,
|
||||
WorkItem item,
|
||||
@@ -48,7 +59,9 @@ class _WorkDetailPageState extends State<WorkDetailPage> {
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
await action(item);
|
||||
setState(() => _future = _load());
|
||||
if (mounted) _reload();
|
||||
} on SessionExpiredException {
|
||||
return;
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
@@ -152,7 +165,9 @@ class _WorkDetailPageState extends State<WorkDetailPage> {
|
||||
proofFile: temporaryFile,
|
||||
);
|
||||
await widget.drafts.deleteDraft(widget.session.identity, item.identity);
|
||||
if (mounted) setState(() => _future = _load());
|
||||
if (mounted) _reload();
|
||||
} on SessionExpiredException {
|
||||
return;
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
@@ -175,10 +190,13 @@ class _WorkDetailPageState extends State<WorkDetailPage> {
|
||||
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 = _load()),
|
||||
onRetry: _reload,
|
||||
);
|
||||
}
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
@@ -292,7 +310,7 @@ class _WorkDetailPageState extends State<WorkDetailPage> {
|
||||
final changed = await context.push<bool>(
|
||||
'/tasks/${item.identity}/evidence',
|
||||
);
|
||||
if (changed == true) setState(() => _future = _load());
|
||||
if (changed == true && mounted) _reload();
|
||||
},
|
||||
icon: const Icon(Icons.fact_check_outlined),
|
||||
label: const Text('现场取证与提交'),
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// 功能描述:管理工作人员任务列表数据,并将会话失效交给统一路由处理。
|
||||
// 版本:1.1.0
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../../data/repositories/service_repository.dart';
|
||||
import '../../../data/services/api_client.dart';
|
||||
import '../../../domain/models/service_models.dart';
|
||||
|
||||
class WorkListViewModel extends ChangeNotifier {
|
||||
@@ -27,7 +30,8 @@ class WorkListViewModel extends ChangeNotifier {
|
||||
.where((item) => completed ? item.status == 23 : item.status != 23 && item.status != 22)
|
||||
.toList();
|
||||
} catch (error) {
|
||||
_error = error;
|
||||
// 会话失效由统一路由接管,不在任务列表重复展示网络错误。
|
||||
if (error is! SessionExpiredException) _error = error;
|
||||
} finally {
|
||||
_loading = false;
|
||||
notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user