From 96a84cc28152c6e67cab424b59e3f3ca574a4ae0 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 9 Jan 2026 02:43:23 -0800 Subject: [PATCH] =?UTF-8?q?fix(mobile-app):=20=E4=BF=AE=E5=A4=8D=E8=AE=A4?= =?UTF-8?q?=E7=A7=8D=E5=90=91=E5=AF=BC=E5=AE=8C=E6=88=90=E5=90=8E=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=BF=94=E5=9B=9E=E5=BE=85=E5=8A=9E=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:认种向导完成后使用 context.go() 跳转到合同签署页面, 替换了整个导航栈,导致合同签署完成后无法返回待办页面继续处理其他待办。 修复:改用 context.push() 跳转到合同签署页面,保留导航栈, 合同签署完成后可以正确返回待办页面。 同时添加了详细的调试日志,便于排查问题。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../pages/pending_actions_page.dart | 24 +++++++++++++++++-- .../pages/planting_location_page.dart | 14 +++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/frontend/mobile-app/lib/features/pending_actions/presentation/pages/pending_actions_page.dart b/frontend/mobile-app/lib/features/pending_actions/presentation/pages/pending_actions_page.dart index 295468d3..170e1718 100644 --- a/frontend/mobile-app/lib/features/pending_actions/presentation/pages/pending_actions_page.dart +++ b/frontend/mobile-app/lib/features/pending_actions/presentation/pages/pending_actions_page.dart @@ -62,38 +62,50 @@ class _PendingActionsPageState extends ConsumerState { /// 执行当前待办操作 Future _executeCurrentAction() async { + debugPrint('[PendingActionsPage] _executeCurrentAction: 开始执行, currentIndex=$_currentIndex, total=${_pendingActions.length}'); if (_currentIndex >= _pendingActions.length) { + debugPrint('[PendingActionsPage] _executeCurrentAction: 已完成所有操作,跳转'); _completeAllActions(); return; } final action = _pendingActions[_currentIndex]; + debugPrint('[PendingActionsPage] _executeCurrentAction: 执行操作 ${action.actionCode} (id=${action.id})'); setState(() => _isExecuting = true); try { // 根据不同的操作类型执行不同的逻辑 final result = await _executeAction(action); + debugPrint('[PendingActionsPage] _executeCurrentAction: _executeAction 返回 $result'); if (result) { // 操作执行成功,标记为完成 + debugPrint('[PendingActionsPage] _executeCurrentAction: 调用后端 completeAction'); final service = ref.read(pendingActionServiceProvider); await service.completeAction(action.id); + debugPrint('[PendingActionsPage] _executeCurrentAction: completeAction 成功'); // 移动到下一个操作 setState(() { _currentIndex++; _isExecuting = false; }); + debugPrint('[PendingActionsPage] _executeCurrentAction: 移动到下一个操作, currentIndex=$_currentIndex'); // 检查是否所有操作都完成 if (_currentIndex >= _pendingActions.length) { + debugPrint('[PendingActionsPage] _executeCurrentAction: 所有操作完成,跳转'); _completeAllActions(); + } else { + debugPrint('[PendingActionsPage] _executeCurrentAction: 还有 ${_pendingActions.length - _currentIndex} 个待办操作'); } } else { // 用户取消或操作失败,保持在当前操作 + debugPrint('[PendingActionsPage] _executeCurrentAction: 操作未完成(result=false),保持当前操作'); setState(() => _isExecuting = false); } } catch (e) { + debugPrint('[PendingActionsPage] _executeCurrentAction: 发生异常: $e'); setState(() { _isExecuting = false; _errorMessage = '操作失败: $e'; @@ -114,11 +126,19 @@ class _PendingActionsPageState extends ConsumerState { switch (action.actionCode) { case 'ADOPTION_WIZARD': // 跳转到认种向导 + debugPrint('[PendingActionsPage] ADOPTION_WIZARD: push 到认种向导页面'); final result = await context.push(RoutePaths.plantingQuantity); - if (result == true) return true; + debugPrint('[PendingActionsPage] ADOPTION_WIZARD: 认种向导返回,result=$result'); + if (result == true) { + debugPrint('[PendingActionsPage] ADOPTION_WIZARD: 返回 true,标记完成'); + return true; + } // 认种向导完成后会跳转到合同签署页面,不会返回 true // 通过检查是否有待签合同来判断是否完成认种 - return await _checkIfAlreadyCompleted(action); + debugPrint('[PendingActionsPage] ADOPTION_WIZARD: 返回不是 true,检查是否已完成'); + final alreadyDone = await _checkIfAlreadyCompleted(action); + debugPrint('[PendingActionsPage] ADOPTION_WIZARD: _checkIfAlreadyCompleted 返回 $alreadyDone'); + return alreadyDone; case 'SETTLE_REWARDS': // 直接调用结算 API 将可结算收益转入钱包余额 diff --git a/frontend/mobile-app/lib/features/planting/presentation/pages/planting_location_page.dart b/frontend/mobile-app/lib/features/planting/presentation/pages/planting_location_page.dart index bb7693f0..ea61dc4f 100644 --- a/frontend/mobile-app/lib/features/planting/presentation/pages/planting_location_page.dart +++ b/frontend/mobile-app/lib/features/planting/presentation/pages/planting_location_page.dart @@ -293,6 +293,7 @@ class _PlantingLocationPageState extends ConsumerState { } } else if (mounted) { // 已完成实名认证 - 直接跳转到合同签署页面 + debugPrint('[PlantingLocation] 已完成实名认证,准备跳转到合同签署页面'); ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('认种成功!请在24小时内完成合同签署'), @@ -300,8 +301,17 @@ class _PlantingLocationPageState extends ConsumerState { ), ); - // 跳转到合同签署页面 - context.go('${RoutePaths.contractSigning}/${widget.orderNo}'); + // 跳转到合同签署页面(使用 push 保留导航栈,以便返回待办页面) + debugPrint('[PlantingLocation] push 到合同签署页面: ${RoutePaths.contractSigning}/${widget.orderNo}'); + final signResult = await context.push('${RoutePaths.contractSigning}/${widget.orderNo}'); + debugPrint('[PlantingLocation] 合同签署页面返回,signResult=$signResult, mounted=$mounted, canPop=${context.canPop()}'); + // 签署完成后,返回 true 给调用方(待办页面) + if (mounted && context.canPop()) { + debugPrint('[PlantingLocation] pop 返回上一页,返回值: ${signResult == true}'); + context.pop(signResult == true); + } else { + debugPrint('[PlantingLocation] 无法 pop,mounted=$mounted, canPop=${mounted ? context.canPop() : "N/A"}'); + } return; } } else {