47 lines
1.5 KiB
Dart
47 lines
1.5 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:ef/ef.dart';
|
|
import 'package:vbvs_app/common/util/MyUtils.dart';
|
|
|
|
class ApiService {
|
|
static Dio dio = Dio();
|
|
|
|
static Dio request = Dio();
|
|
static Dio requestNoInfo = Dio();
|
|
static Dio requestNoError = Dio(); //不处理错误的请求,用于设备操作上报
|
|
|
|
static Dio reservation = Dio();
|
|
|
|
static void init() {
|
|
reservationInit();
|
|
}
|
|
|
|
static void reservationInit() {
|
|
try {
|
|
reservation.options.baseUrl = "https://crm-api.swes.com.cn";
|
|
reservation.options.connectTimeout = const Duration(seconds: 15);
|
|
reservation.options.receiveTimeout = const Duration(seconds: 10);
|
|
reservation.options.sendTimeout = const Duration(seconds: 10);
|
|
reservation.interceptors.add(InterceptorsWrapper(
|
|
onRequest: (options, handler) {
|
|
print("---> ${options.method}, ${options.path}, ${options.data}");
|
|
options.headers['token'] =
|
|
"bMAQVR1x48t66u8EDYSftAJGo17r0rIB3z15JgyyoGz1rAEZHs1htHOCorYFJ2RT";
|
|
return handler.next(options);
|
|
},
|
|
onResponse: (response, ResponseInterceptorHandler handler) {
|
|
print("<--- ${response.statusCode} ${response.data}");
|
|
return handler.next(response);
|
|
},
|
|
onError: (e, handler) {
|
|
// 错误处理,例如打印错误信息
|
|
showToast("网络异常或服务连接异常,请稍候再试", color: color_error);
|
|
print("DioError: $e");
|
|
return handler.reject(e);
|
|
},
|
|
));
|
|
} catch (e) {
|
|
ef.log("$e");
|
|
}
|
|
}
|
|
}
|