主要修改:
1. AssetService.dart - 修复资金账户数据解析
- 处理后端返回的嵌套结构 {"fund": {...}}
- 正确提取 fund 字段中的数据
2. AssetPage.dart - 移除portfolio value卡片
- 移除最上面的总资产卡片显示
- 只保留资金账户和交易账户的Tab切换
修复后:
- ✅ 资金账户余额正确显示 (15500 USDT)
- ✅ 页面布局更简洁,符合用户需求
- ✅ 数据解析正确,不再显示0
92 lines
2.5 KiB
Dart
92 lines
2.5 KiB
Dart
import '../../core/constants/api_endpoints.dart';
|
|
import '../../core/network/api_response.dart';
|
|
import '../../core/network/dio_client.dart';
|
|
import '../models/account_models.dart';
|
|
|
|
/// 资产服务
|
|
class AssetService {
|
|
final DioClient _client;
|
|
|
|
AssetService(this._client);
|
|
|
|
/// 获取资产总览
|
|
Future<ApiResponse<AssetOverview>> getOverview() async {
|
|
final response = await _client.get<Map<String, dynamic>>(
|
|
ApiEndpoints.assetOverview,
|
|
);
|
|
|
|
if (response.success && response.data != null) {
|
|
return ApiResponse.success(
|
|
AssetOverview.fromJson(response.data!),
|
|
response.message,
|
|
);
|
|
}
|
|
return ApiResponse.fail(response.message ?? '获取资产总览失败');
|
|
}
|
|
|
|
/// 获取资金账户
|
|
Future<ApiResponse<AccountFund>> getFundAccount() async {
|
|
final response = await _client.get<Map<String, dynamic>>(
|
|
ApiEndpoints.fundAccount,
|
|
);
|
|
|
|
if (response.success && response.data != null) {
|
|
// 后端返回格式: {"fund": {...}}
|
|
final fundData = response.data!['fund'] as Map<String, dynamic>?;
|
|
if (fundData != null) {
|
|
return ApiResponse.success(
|
|
AccountFund.fromJson(fundData),
|
|
response.message,
|
|
);
|
|
}
|
|
}
|
|
return ApiResponse.fail(response.message ?? '获取资金账户失败');
|
|
}
|
|
|
|
/// 获取交易账户
|
|
Future<ApiResponse<List<AccountTrade>>> getTradeAccount() async {
|
|
final response = await _client.get<Map<String, dynamic>>(
|
|
ApiEndpoints.tradeAccount,
|
|
);
|
|
|
|
if (response.success && response.data != null) {
|
|
final list = response.data!['list'] as List?;
|
|
final accounts = list?.map((e) => AccountTrade.fromJson(e as Map<String, dynamic>)).toList() ?? [];
|
|
return ApiResponse.success(accounts, response.message);
|
|
}
|
|
return ApiResponse.fail(response.message ?? '获取交易账户失败');
|
|
}
|
|
|
|
/// 资金划转
|
|
Future<ApiResponse<void>> transfer({
|
|
required int direction,
|
|
required String amount,
|
|
}) async {
|
|
return _client.post<void>(
|
|
ApiEndpoints.transfer,
|
|
data: {
|
|
'direction': direction,
|
|
'amount': amount,
|
|
},
|
|
);
|
|
}
|
|
|
|
/// 获取资金流水
|
|
Future<ApiResponse<Map<String, dynamic>>> getFlow({
|
|
int? flowType,
|
|
int pageNum = 1,
|
|
int pageSize = 20,
|
|
}) async {
|
|
final params = <String, dynamic>{
|
|
'pageNum': pageNum,
|
|
'pageSize': pageSize,
|
|
};
|
|
if (flowType != null) params['flowType'] = flowType;
|
|
|
|
return _client.get<Map<String, dynamic>>(
|
|
ApiEndpoints.assetFlow,
|
|
queryParameters: params,
|
|
);
|
|
}
|
|
}
|