fix(app): 修复 RemoteJournalRepository API 响应解析 — 分页信封嵌套
根因: 后端列表接口返回 { success, data: { data: [...], total, ... }, message }
但前端直接 body['data'] as List,类型不匹配导致 TypeError 被静默吞掉。
修复: getJournals 和 getJournalCount 正确解析分页信封
body['data']['data'] 获取列表, body['data']['total'] 获取总数。
This commit is contained in:
@@ -39,7 +39,9 @@ class RemoteJournalRepository implements JournalRepository {
|
||||
|
||||
final response = await _api.get('/diary/journals', queryParams: queryParams);
|
||||
final body = response.data as Map<String, dynamic>;
|
||||
final items = body['data'] as List? ?? [];
|
||||
// 后端信封格式: { success, data: { data: [...], total, page, ... }, message }
|
||||
final envelope = body['data'] as Map<String, dynamic>? ?? {};
|
||||
final items = envelope['data'] as List? ?? [];
|
||||
return items
|
||||
.map((json) => JournalEntry.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
@@ -52,7 +54,9 @@ class RemoteJournalRepository implements JournalRepository {
|
||||
'page_size': 1,
|
||||
});
|
||||
final body = response.data as Map<String, dynamic>;
|
||||
return (body['total'] as int?) ?? 0;
|
||||
// 后端信封格式: { success, data: { data: [...], total, ... }, message }
|
||||
final envelope = body['data'] as Map<String, dynamic>? ?? {};
|
||||
return (envelope['total'] as int?) ?? 0;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user