1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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<String?> mergeAny(List<RequestOptions> options) async {
- var dio = GetIt.I<Dio>();
- Map<String, String> 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<String>("/merge/any", data: params, options: Options(contentType: "application/x-www-form-urlencoded"));
- if (response.statusCode == HttpStatus.ok) {
- return response.data;
- }
- return null;
- }
- Future<List<int>> mergeMessageCount() async {
- List<int> result = [0, 0, 0];
- var dio = GetIt.I<Dio>();
- 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<dynamic> jsonResult = json.decode(jsonStr!);
- result[0] = RespData<int>.fromJson(jsonResult[0]).data ?? 0;
- result[1] = RespData<int>.fromJson(jsonResult[1]).data ?? 0;
- result[2] = RespData<FriendList>.fromJson(jsonResult[2]).data?.noIgnoreCount ?? 0;
- }
- return result;
- }
|