mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add function
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:qinglong_app/base/http/token_interceptor.dart';
|
||||
import 'package:qinglong_app/base/userinfo_viewmodel.dart';
|
||||
|
||||
import '../../json.jc.dart';
|
||||
import '../../main.dart';
|
||||
|
||||
class Http {
|
||||
static const int NOT_LOGIN = 1000;
|
||||
@@ -31,7 +32,7 @@ class Http {
|
||||
|
||||
static void _init() {
|
||||
if (_dio == null) {
|
||||
initDioConfig(UserInfoViewModel.getInstance().host!);
|
||||
initDioConfig(getIt<UserInfoViewModel>().host!);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:qinglong_app/main.dart';
|
||||
|
||||
import '../userinfo_viewmodel.dart';
|
||||
|
||||
class TokenInterceptor extends Interceptor {
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
if (userInfoViewModel.token != null) {
|
||||
options.headers["Authorization"] = "Bearer " + userInfoViewModel.token!;
|
||||
if (getIt<UserInfoViewModel>().token != null) {
|
||||
options.headers["Authorization"] = "Bearer " + getIt<UserInfoViewModel>().token!;
|
||||
}
|
||||
options.queryParameters["t"] = (DateTime.now().millisecondsSinceEpoch~/1000).toString();
|
||||
return handler.next(options);
|
||||
|
||||
Reference in New Issue
Block a user