登录接口调试

This commit is contained in:
GYJ
2024-11-25 17:26:41 +08:00
parent 2f1eb7abc4
commit d12e3dea84
14 changed files with 1054 additions and 61 deletions

View File

@@ -1,4 +1,5 @@
import 'package:cashier_reserve/common/manager/app_manager.dart';
import 'package:cashier_reserve/common/manager/hive_manager.dart';
import 'package:cashier_reserve/common/print/print.dart';
import 'package:dio/dio.dart';
@@ -20,6 +21,11 @@ class RequestManager {
/// GET
static Future<dynamic> get(String url, {bool catchError = true}) {
if (url.contains("?")) {
url += "&shopId=${HiveManager.getShopId()}";
} else {
url += "?shopId=${HiveManager.getShopId()}";
}
return _doRequest("GET", url, catchError: catchError);
}
@@ -31,12 +37,22 @@ class RequestManager {
/// POST
static Future<dynamic> post(String url, Map<String, dynamic>? body,
{bool catchError = true}) {
if (body != null) {
body["shopId"] = HiveManager.getShopId();
} else {
body = {"shopId": HiveManager.getShopId()};
}
return _doRequest("POST", url, body: body, catchError: catchError);
}
/// PUT
static Future<dynamic> put(String url, Map<String, dynamic>? body,
{bool catchError = true}) {
if (body != null) {
body["shopId"] = HiveManager.getShopId();
} else {
body = {"shopId": HiveManager.getShopId()};
}
return _doRequest("PUT", url, body: body, catchError: catchError);
}
@@ -49,7 +65,8 @@ class RequestManager {
data: body,
options: Options(
method: method,
headers: {"authorization": "Bearer ${AppManager.getUserToken()}"}));
headers: {"authorization": "Bearer ${AppManager.getUserToken()}"}
));
yjPrint("[RequestManager resp]: $method$url】body === $resp");
if (catchError) {
if (resp.statusCode == kNeedLoginCode) {
@@ -65,6 +82,17 @@ class RequestManager {
} catch (e) {
yjPrint("[RequestManager error]: $method$url】error === $e");
// _alertError("网络错误", "请检查您的网络连接!");
if (e is DioException) {
DioException de = e;
if (de.response?.statusCode == kNeedLoginCode) {
AppManager.gotoLogin();
return null;
}
if (de.response?.data is Map) {
final data = de.response!.data as Map;
Utils.toast(data["message"], AppManager.globalContext!);
}
}
return null;
}
}