fix(mobile-app): correctly parse nested API response for pending actions

The API returns a nested structure {success, data: {code, data: [...]}}
but the service was only checking for {actions: [...]} format.

Now correctly extracts the actions list from data.data.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-02 20:57:17 -08:00
parent f7913cd04e
commit f5f0ff2822
1 changed files with 22 additions and 1 deletions

View File

@ -158,8 +158,28 @@ class PendingActionService {
final data = response.data;
debugPrint('[PendingActionService] 响应: $data');
// : {success: true, data: {code: "OK", data: [...]}}
if (data is Map<String, dynamic>) {
return PendingActionsResponse.fromJson(data);
// data
final innerData = data['data'];
if (innerData is Map<String, dynamic>) {
// data ()
final actionsList = innerData['data'];
if (actionsList is List) {
debugPrint('[PendingActionService] 解析到 ${actionsList.length} 个待办操作');
return PendingActionsResponse(
actions: actionsList
.map((e) => PendingAction.fromJson(e as Map<String, dynamic>))
.toList(),
count: actionsList.length,
);
}
}
// : {actions: [...]}
if (data.containsKey('actions')) {
return PendingActionsResponse.fromJson(data);
}
}
//
@ -172,6 +192,7 @@ class PendingActionService {
);
}
debugPrint('[PendingActionService] 无法解析响应数据,返回空列表');
return PendingActionsResponse(actions: [], count: 0);
} catch (e) {
debugPrint('[PendingActionService] 获取待办操作失败: $e');