0418 0222
更新2
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../model/song_model.dart';
|
||||
import '../model/user_model.dart';
|
||||
import '../tool/encryption_util.dart';
|
||||
|
||||
@@ -307,4 +308,33 @@ class UserService {
|
||||
throw _getErrorMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<ChartLogModel>> getChartLog(String token, List<int> musicIds) async {
|
||||
try {
|
||||
print("getChartLog");
|
||||
// 构建查询参数
|
||||
// 如果 API 期望的是逗号分隔的字符串 "11434,11435"
|
||||
final String idsParam = musicIds.map((e) => e.toString()).join(',');
|
||||
|
||||
final res = await _dio.get(
|
||||
'$baseUrl/api/union/chartlog',
|
||||
queryParameters: {
|
||||
"musicId": idsParam,
|
||||
},
|
||||
options: Options(headers: {"Authorization": token}),
|
||||
);
|
||||
|
||||
// 检查返回数据是否为 List
|
||||
if (res.data is List) {
|
||||
return (res.data as List)
|
||||
.map((item) => ChartLogModel.fromJson(item as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// 如果后端在某些错误情况下返回 Map 而不是 List,这里返回空列表或抛出异常
|
||||
return [];
|
||||
} on DioException catch (e) {
|
||||
throw _getErrorMessage(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user