app-starlock/star_lock/lib/network/api_provider_base.dart
Daisy b83a5c4c01 1,授权管理员详情
2,删除授权管理员
3,更新授权管理员及相应逻辑处理
2023-09-22 11:45:24 +08:00

86 lines
2.5 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../../tools/toast.dart';
import 'package:get/get.dart';
import '../appRouters.dart';
import 'api.dart';
import 'request_interceptor.dart';
import 'request_interceptor_log.dart';
import 'response_interceptor.dart';
import 'response_interceptor_log.dart';
class BaseProvider extends GetConnect with Api {
@override
void onInit() {
httpClient.baseUrl = baseUrl;
httpClient.addRequestModifier(requestInterceptor);
httpClient.addResponseModifier(responseInterceptor);
httpClient.addRequestModifier(requestLogInterceptor);
httpClient.addResponseModifier(responseLogInterceptor);
httpClient.timeout = 15.seconds;
super.onInit();
}
@override
Future<Response<T>> post<T>(String? url, body,
{String? contentType,
Map<String, String>? headers,
Map<String, dynamic>? query,
Decoder<T>? decoder,
Progress? uploadProgress,
bool? isUnShowLoading = false}) async {
// print("post: url:${url} body:${body} contentType:${contentType} headers:${headers} query:${query}");
if(isUnShowLoading == false) EasyLoading.show();
print('哈喽请求body体为${body}');
var res = await super.post(url, body,
contentType: contentType,
headers: headers,
query: query,
decoder: decoder,
uploadProgress: uploadProgress);
if (res.body == null) {
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
var rs = {
"errorMsg": "Network Error!",
"errorCode": -1,
"data": null,
"description": "表示成功或是。"
};
return Response(
request: res.request,
statusCode: -1,
bodyString: res.bodyString,
bodyBytes: res.bodyBytes,
body: rs as T,
statusText: res.statusText,
);
}
// print('得到的数据======>bodyString:${res.bodyString} body:${res.body} bodyBytes:${res.bodyBytes} status:${res.status} statusText:${res.statusText} statusCode:${res.statusCode}');
getDataResult(res.body);
return res;
}
getDataResult(T) {
switch (T["errorCode"]) {
case 403:
Get.offNamedUntil(Routers.starLockLoginPage, (route) => false);
break;
case 500:
Toast.show(msg: "服务器错误");
break;
case 421:
case 422:
case 430:
Toast.show(msg: T["errorMsg"]);
break;
case 425:
Toast.show(msg: "用户不存在");
break;
case 10001:
Toast.show(msg: "数据不存在");
break;
}
}
}