修复工作人员端令牌失效后的登录恢复
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// 功能描述:提供工作人员端手机号密码登录界面及本地输入校验。
|
||||
// 版本:1.2.0
|
||||
// 版本:1.3.0
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../app/dependencies.dart';
|
||||
@@ -7,9 +7,14 @@ import '../../../data/services/api_client.dart';
|
||||
|
||||
/// 工作人员端手机号密码登录页面。
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({required this.session, super.key});
|
||||
const LoginPage({
|
||||
required this.session,
|
||||
this.showSessionExpiredMessage = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final StaffSession session;
|
||||
final bool showSessionExpiredMessage;
|
||||
|
||||
@override
|
||||
State<LoginPage> createState() => _LoginPageState();
|
||||
@@ -29,6 +34,14 @@ class _LoginPageState extends State<LoginPage> {
|
||||
String? _passwordError;
|
||||
bool _obscurePassword = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.showSessionExpiredMessage) {
|
||||
_error = '登录状态已失效,请重新登录';
|
||||
}
|
||||
}
|
||||
|
||||
/// 校验手机号和密码,通过后再提交登录请求。
|
||||
Future<void> _login() async {
|
||||
final phone = _phone.text.trim();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// 功能描述:管理工作人员现场取证、加密草稿和安全提交。
|
||||
// 版本:1.1.0
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@@ -5,6 +7,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 '../../core/widgets.dart';
|
||||
|
||||
class EvidencePage extends StatefulWidget {
|
||||
@@ -138,6 +141,8 @@ class _EvidencePageState extends State<EvidencePage> {
|
||||
widget.taskIdentity,
|
||||
);
|
||||
if (mounted) Navigator.pop(context, true);
|
||||
} on SessionExpiredException {
|
||||
return;
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// 功能描述:展示工作人员资料、钱包和草稿状态,并安全处理刷新与退出。
|
||||
// 版本:1.1.0
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.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';
|
||||
|
||||
@@ -38,6 +41,14 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||
await widget.drafts.count(widget.session.identity),
|
||||
);
|
||||
|
||||
/// 创建新的加载任务,并在同步状态回调中替换页面 Future。
|
||||
void _reload() {
|
||||
final future = _load();
|
||||
setState(() {
|
||||
_future = future;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _logout(int draftCount) async {
|
||||
if (draftCount > 0) {
|
||||
final discard = await showDialog<bool>(
|
||||
@@ -66,10 +77,13 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||
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());
|
||||
|
||||
@@ -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