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:
parent
f7913cd04e
commit
f5f0ff2822
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in New Issue