import 'dart:convert'; import 'dart:io'; import 'package:dio/dio.dart'; import 'package:get_it/get_it.dart'; import 'package:sport/bean/friend_list.dart'; import 'package:sport/services/api/resp.dart'; Future mergeAny(List options) async { var dio = GetIt.I(); Map params = {}; for (var i = 0; i < options.length; i++) { var o = options[i]; params["groups[$i][url]"] = o.uri.toString(); params["groups[$i][method]"] = o.method; } Response response = await dio.post("/merge/any", data: params, options: Options(contentType: "application/x-www-form-urlencoded")); if (response.statusCode == HttpStatus.ok) { return response.data; } return null; } Future> mergeMessageCount() async { List result = [0, 0, 0]; var dio = GetIt.I(); var options = dio.options.copyWith(baseUrl: ""); String? jsonStr = await mergeAny([ Options( method: "GET", ).compose(options, "/notice/count", queryParameters: {"type": "like", "read": 0, "isMsg": 1}), Options( method: "GET", ).compose(options, "/notice/count", queryParameters: {"type": "comment", "read": 0, "isMsg": 1}), Options( method: "GET", ).compose(options, "/forum/fansList", queryParameters: {"limit": 1}) ]); if (jsonStr?.isNotEmpty == true) { List jsonResult = json.decode(jsonStr!); result[0] = RespData.fromJson(jsonResult[0]).data ?? 0; result[1] = RespData.fromJson(jsonResult[1]).data ?? 0; result[2] = RespData.fromJson(jsonResult[2]).data?.noIgnoreCount ?? 0; } return result; }