Merge branch 'master' into mcy
This commit is contained in:
commit
a7df4d9fe8
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* @Author: wangyang 1147192855@qq.com
|
||||||
|
* @Date: 2022-07-13 11:28:23
|
||||||
|
* @LastEditors: wangyang 1147192855@qq.com
|
||||||
|
* @LastEditTime: 2022-09-14 11:17:20
|
||||||
|
* @FilePath: \marking_app\lib\config\RequestConfig.dart
|
||||||
|
* @Description: 请求工具类
|
||||||
|
*/
|
||||||
|
import 'package:school_asignment_app/common/job/common/base_page.dart';
|
||||||
|
|
||||||
|
class RequestConfig {
|
||||||
|
static const _devBaseUrl = "https://dpc-teacher-api.23544.com"; // 开发
|
||||||
|
static const _proBaseUrl = "https://dpc-teacher-api.23544.com"; // 生产
|
||||||
|
|
||||||
|
static RequestConfig? _instance;
|
||||||
|
String baseUrl;
|
||||||
|
|
||||||
|
static const connectTimeout = 8000; // 连接超时
|
||||||
|
static const receiveTimeout = 8000; // 接收超时
|
||||||
|
static const bool requestDataPrinting = true; // 打印返回数据
|
||||||
|
static const bool printSwitch = true; // 打印返回数据
|
||||||
|
static const successCode = [204, 200]; // 返回成功code
|
||||||
|
static final BasePage basePage = BasePage(1, 10); // 分页参数
|
||||||
|
|
||||||
|
// 私有化构造函数,防止外部直接实例化
|
||||||
|
// 私有化构造函数,防止外部直接实例化
|
||||||
|
RequestConfig._({required this.baseUrl});
|
||||||
|
|
||||||
|
factory RequestConfig() {
|
||||||
|
if (_instance == null) {
|
||||||
|
String newBaseUrl;
|
||||||
|
if (const bool.fromEnvironment('dart.vm.product')) {
|
||||||
|
newBaseUrl = _proBaseUrl; // 生产环境
|
||||||
|
} else {
|
||||||
|
newBaseUrl = _devBaseUrl; // 开发环境
|
||||||
|
}
|
||||||
|
_instance = RequestConfig._(baseUrl: newBaseUrl);
|
||||||
|
}
|
||||||
|
return _instance!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||||
*/
|
*/
|
||||||
import 'package:json_annotation/json_annotation.dart';
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
import 'package:school_asignment_app/common/request/request_config.dart';
|
import 'package:school_asignment_app/common/config/request_config.dart';
|
||||||
|
|
||||||
part 'base_structure_result.g.dart';
|
part 'base_structure_result.g.dart';
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ class BaseStructureResult<T> extends Object {
|
||||||
this.data, {
|
this.data, {
|
||||||
this.success = false,
|
this.success = false,
|
||||||
}) {
|
}) {
|
||||||
success = (code == RequestConfig.successCode);
|
success = RequestConfig.successCode.contains(code);
|
||||||
}
|
}
|
||||||
factory BaseStructureResult.fromJson(Map<String, dynamic> json, T Function(dynamic json) fromJsonT) =>
|
factory BaseStructureResult.fromJson(Map<String, dynamic> json, T Function(dynamic json) fromJsonT) =>
|
||||||
_$BaseStructureResultFromJson(json, fromJsonT);
|
_$BaseStructureResultFromJson(json, fromJsonT);
|
||||||
|
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* @Author: wangyang 1147192855@qq.com
|
|
||||||
* @Date: 2022-07-13 11:28:23
|
|
||||||
* @LastEditors: wangyang 1147192855@qq.com
|
|
||||||
* @LastEditTime: 2022-09-14 11:17:20
|
|
||||||
* @FilePath: \marking_app\lib\config\RequestConfig.dart
|
|
||||||
* @Description: 请求工具类
|
|
||||||
*/
|
|
||||||
import 'package:school_asignment_app/common/job/common/base_page.dart';
|
|
||||||
|
|
||||||
class RequestConfig {
|
|
||||||
/* 测试地址
|
|
||||||
static const devBaseUrl = "http://192.168.2.9:6600"; // 测试环境 ==> 基本请求接口
|
|
||||||
// static const devBaseUrl = "http://192.168.2.8:6700"; // 测试环境 ==> 基本请求接口
|
|
||||||
static const devLoginBaseUrl = "http://192.168.2.9:6400"; // 基本请求接口
|
|
||||||
static const devBaseUrlOfReport = "http://192.168.2.9:4000"; // 获取报告接口*/
|
|
||||||
|
|
||||||
static const devBaseUrl = "https://mk-hw.23544.com"; // 基本请求
|
|
||||||
static const devLoginBaseUrl = "https://mk-hw.23544.com"; // 登录接口
|
|
||||||
static const devBaseUrlOfReport = "https://mhw.qwit.top"; // 获取报告接口
|
|
||||||
static const proBaseUrlOfHomework = "https://mk-hw.23544.com/hw"; // 获取作业接口
|
|
||||||
|
|
||||||
/* 正式地址 */
|
|
||||||
static const proBaseUrl = "https://mk-hw.23544.com"; // 基本请求
|
|
||||||
static const proLoginBaseUrl = "https://mk-hw.23544.com"; // 登录接口
|
|
||||||
static const proBaseUrlOfReport = "https://dc-api.23544.com"; // 获取报告接口
|
|
||||||
// static const proBaseUrlOfHomework = "https://mk-hw.23544.com/hw"; // 获取作业接口
|
|
||||||
|
|
||||||
static const hwProxyKeywords = "/hw"; // 作业代理条件关键字
|
|
||||||
|
|
||||||
// https://mk-api.23544.com/hw/hw/api/Task/answer
|
|
||||||
// http://192.168.2.9:6400/hw/api/Task/answer
|
|
||||||
|
|
||||||
static RequestConfig? _instance;
|
|
||||||
String baseUrl;
|
|
||||||
String loginBaseUrl;
|
|
||||||
String baseUrlOfReport;
|
|
||||||
|
|
||||||
static const connectTimeout = 8000; // 连接超时
|
|
||||||
static const receiveTimeout = 8000; // 接收超时
|
|
||||||
|
|
||||||
static const bool requestDataPrinting = true; // 打印返回数据
|
|
||||||
static const bool printSwitch = true; // 打印返回数据
|
|
||||||
|
|
||||||
static const successCode = [200, 204]; // 返回成功code
|
|
||||||
static final BasePage basePage = BasePage(1, 10); // 分页参数
|
|
||||||
|
|
||||||
// 私有化构造函数,防止外部直接实例化
|
|
||||||
// 私有化构造函数,防止外部直接实例化
|
|
||||||
RequestConfig._({required this.baseUrl, required this.baseUrlOfReport, required this.loginBaseUrl});
|
|
||||||
|
|
||||||
factory RequestConfig() {
|
|
||||||
if (_instance == null) {
|
|
||||||
late String newBaseUrl;
|
|
||||||
late String newBaseUrlOfReport;
|
|
||||||
late String newLoginBaseUrl;
|
|
||||||
|
|
||||||
if (bool.fromEnvironment('dart.vm.product')) {
|
|
||||||
// 正式环境下的代码
|
|
||||||
|
|
||||||
newLoginBaseUrl = proLoginBaseUrl;
|
|
||||||
newBaseUrl = proBaseUrl;
|
|
||||||
newBaseUrlOfReport = proBaseUrlOfReport;
|
|
||||||
} else {
|
|
||||||
// 在生产环境下执行的代码
|
|
||||||
newBaseUrl = devBaseUrl;
|
|
||||||
newBaseUrlOfReport = devBaseUrlOfReport;
|
|
||||||
newLoginBaseUrl = devLoginBaseUrl;
|
|
||||||
}
|
|
||||||
_instance = RequestConfig._(baseUrl: newBaseUrl, baseUrlOfReport: newBaseUrlOfReport, loginBaseUrl: newLoginBaseUrl);
|
|
||||||
}
|
|
||||||
return _instance!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,8 +4,8 @@ import 'package:get/get.dart' as getx;
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:package_info/package_info.dart';
|
import 'package:package_info/package_info.dart';
|
||||||
import 'package:school_asignment_app/common/api/retrofit_client.dart';
|
import 'package:school_asignment_app/common/api/retrofit_client.dart';
|
||||||
|
import 'package:school_asignment_app/common/config/request_config.dart';
|
||||||
import 'package:school_asignment_app/common/job/user_info.dart';
|
import 'package:school_asignment_app/common/job/user_info.dart';
|
||||||
import 'package:school_asignment_app/common/request/request_config.dart';
|
|
||||||
import 'package:school_asignment_app/common/store/user_store.dart';
|
import 'package:school_asignment_app/common/store/user_store.dart';
|
||||||
import 'package:school_asignment_app/common/utils/toast_utils.dart';
|
import 'package:school_asignment_app/common/utils/toast_utils.dart';
|
||||||
import 'package:school_asignment_app/routes/app_pages.dart';
|
import 'package:school_asignment_app/routes/app_pages.dart';
|
||||||
|
|
@ -145,13 +145,30 @@ class TheError extends Interceptor {
|
||||||
if (error.response == null) {
|
if (error.response == null) {
|
||||||
print('请求进入异常但是请求response');
|
print('请求进入异常但是请求response');
|
||||||
} else {
|
} else {
|
||||||
var errorMap = error.response!.data;
|
Response? response = error.response;
|
||||||
if (errorMap['error'] != null) {
|
if (response != null) {
|
||||||
|
int? statusCode = response.statusCode;
|
||||||
|
|
||||||
|
var errorMap = response.data;
|
||||||
|
// var runtimeType = errorMap.runtimeType;
|
||||||
|
// print(runtimeType);
|
||||||
|
if ((errorMap is Map || errorMap is Object) && errorMap['error'] != null) {
|
||||||
message = errorMap['error']?['message'] ?? '请求错误,请重试';
|
message = errorMap['error']?['message'] ?? '请求错误,请重试';
|
||||||
}
|
} else {
|
||||||
if (error.response!.statusCode == 401) {
|
if (statusCode != null) {
|
||||||
|
switch (statusCode) {
|
||||||
|
case 401:
|
||||||
message = '用户登录失效,请重新登录';
|
message = '用户登录失效,请重新登录';
|
||||||
Future.delayed(const Duration(seconds: 2), () => getx.Get.offAllNamed(Routes.login));
|
Future.delayed(const Duration(seconds: 2), () => getx.Get.offAllNamed(Routes.login));
|
||||||
|
break;
|
||||||
|
case 404:
|
||||||
|
// message = '用户登录失效,请重新登录';
|
||||||
|
// Future.delayed(const Duration(seconds: 2), () => getx.Get.offAllNamed(Routes.login));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue