parent
68288fdc00
commit
a6c8b475f4
|
|
@ -11,13 +11,8 @@ import 'package:wgshare/utils/toast_utils.dart';
|
|||
import 'package:wgshare/routes/app_routes.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../mixins/request_tool_mixin.dart';
|
||||
import '../models/common/base_structure_result.dart';
|
||||
import '../models/user_info_entity.dart';
|
||||
|
||||
class RequestTool {
|
||||
static late Dio _dio;
|
||||
|
||||
// 初始化请求配置
|
||||
static _init() {
|
||||
// 自定义 HttpClient
|
||||
|
|
@ -25,21 +20,16 @@ class RequestTool {
|
|||
|
||||
BaseOptions options = BaseOptions(
|
||||
baseUrl: RequestConfig().baseUrl,
|
||||
connectTimeout:
|
||||
const Duration(milliseconds: RequestConfig.connectTimeout),
|
||||
receiveTimeout:
|
||||
const Duration(milliseconds: RequestConfig.receiveTimeout),
|
||||
connectTimeout: const Duration(milliseconds: RequestConfig.connectTimeout),
|
||||
receiveTimeout: const Duration(milliseconds: RequestConfig.receiveTimeout),
|
||||
);
|
||||
_dio = Dio(options)
|
||||
..httpClientAdapter =
|
||||
IOHttpClientAdapter(createHttpClient: () => httpClient);
|
||||
_dio = Dio(options)..httpClientAdapter = IOHttpClientAdapter(createHttpClient: () => httpClient);
|
||||
_dio.interceptors.add(AuthInterceptor()); // 添加 token
|
||||
_dio.interceptors.add(ResponseHandle()); // 添加 数据返回拦截
|
||||
_dio.interceptors.add(TheError()); // 添加 数据返回拦截
|
||||
const isProd = bool.fromEnvironment('dart.vm.product');
|
||||
if (!isProd && RequestConfig.requestDataPrinting) {
|
||||
_dio.interceptors
|
||||
.add(LogInterceptor(responseBody: true, requestBody: true)); //添加日志
|
||||
_dio.interceptors.add(LogInterceptor(responseBody: true, requestBody: true)); //添加日志
|
||||
}
|
||||
|
||||
return RetrofitClient(_dio, baseUrl: RequestConfig().baseUrl);
|
||||
|
|
@ -118,10 +108,8 @@ class ResponseHandle extends Interceptor {
|
|||
var data = response.data;
|
||||
|
||||
var flag = data != null &&
|
||||
((data['code'] != null &&
|
||||
(data['code'] == 401 || data['code'] == '401')) ||
|
||||
(data['Code'] != null &&
|
||||
(data['Code'] == 401 || data['Code'] == '401')));
|
||||
((data['code'] != null && (data['code'] == 401 || data['code'] == '401')) ||
|
||||
(data['Code'] != null && (data['Code'] == 401 || data['Code'] == '401')));
|
||||
|
||||
if (statusCode == 401 || flag) {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
|
|
@ -130,22 +118,21 @@ class ResponseHandle extends Interceptor {
|
|||
});
|
||||
}
|
||||
|
||||
if (data['code'] != 200) {
|
||||
/*if(data['code'] != 200){
|
||||
ToastUtils.showError(data['message']);
|
||||
}
|
||||
}*/
|
||||
ToastUtils.showError(data['message']);
|
||||
|
||||
super.onResponse(response, handler);
|
||||
}
|
||||
}
|
||||
|
||||
class TheError extends Interceptor with RequestToolMixin {
|
||||
class TheError extends Interceptor {
|
||||
// late getx.Rx<UserInfoDetail?> userInfo = UserStore.to.userDetailInfo;
|
||||
|
||||
@override
|
||||
Future<void> onError(
|
||||
DioException err, ErrorInterceptorHandler handler) async {
|
||||
void onError(DioException err, ErrorInterceptorHandler handler) {
|
||||
var message = '请求错误,请重试';
|
||||
int? statusCode;
|
||||
|
||||
switch (err.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
|
|
@ -166,7 +153,7 @@ class TheError extends Interceptor with RequestToolMixin {
|
|||
} else {
|
||||
Response? response = err.response;
|
||||
if (response != null) {
|
||||
statusCode = response.statusCode;
|
||||
int? statusCode = response.statusCode;
|
||||
|
||||
var errorMap = response.data;
|
||||
// var runtimeType = errorMap.runtimeType;
|
||||
|
|
@ -177,11 +164,12 @@ class TheError extends Interceptor with RequestToolMixin {
|
|||
switch (statusCode) {
|
||||
case 401:
|
||||
message = '用户登录失效,请重新登录';
|
||||
/*Future.delayed(const Duration(seconds: 2), () {
|
||||
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
// UserStore.to.erase();
|
||||
StorageService.to.erase();
|
||||
getx.Get.offAllNamed(Routes.loginPage);
|
||||
});*/
|
||||
});
|
||||
break;
|
||||
case 404:
|
||||
message = '无效地址';
|
||||
|
|
@ -203,17 +191,11 @@ class TheError extends Interceptor with RequestToolMixin {
|
|||
default:
|
||||
message = '请求错误';
|
||||
}
|
||||
if (statusCode == 401) {
|
||||
BaseStructureResult<UserInfoEntity> res = await getClient()
|
||||
.refreshToken(UserStore.to.userInfoEntity.value!.refreshToken);
|
||||
if (null != res.data) {
|
||||
UserStore.to.setToken(res.data!.token);
|
||||
UserStore.to.setRefreshToken(res.data!.refreshToken);
|
||||
UserStore.to.setUserDetailInfo(res.data!);
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showError(message);
|
||||
}
|
||||
/* if (message == '用户登录失效,请重新登录' && userInfo.value?.id == null) {
|
||||
return handler.next(error);
|
||||
}*/
|
||||
|
||||
ToastUtils.showError(message);
|
||||
return handler.next(err);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,12 +196,13 @@ class _LoginPageState extends State<LoginPage> {
|
|||
color: ColorUtil.Color_153_153_153),
|
||||
),
|
||||
child: TextField(
|
||||
obscureText: true,
|
||||
controller: state.passwordController,
|
||||
style: TextStyle(
|
||||
fontSize: 14.sp,
|
||||
),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
FilteringTextInputFormatter.allow(RegExp("^[a-z0-9A-Z]+")),//只允许输入数字,字母
|
||||
LengthLimitingTextInputFormatter(20)
|
||||
//限制长度
|
||||
],
|
||||
|
|
|
|||
|
|
@ -398,8 +398,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin {
|
|||
debugPrint("wgs输出===:SignalR Socket-重连失败$error");
|
||||
ToastUtils.dismiss();
|
||||
|
||||
if (state.isNormaExit.value == false &&
|
||||
state.isShowOkAlertDialog.value == false) {
|
||||
if ((state.isNormaExit.value == false && state.isShowOkAlertDialog.value == false) || null == UserStore.to.userInfoEntity.value) {
|
||||
showOkAlertDialog(
|
||||
context: Get.context!,
|
||||
title: "提示",
|
||||
|
|
|
|||
|
|
@ -749,10 +749,19 @@ class MeetingMainPageState extends State<MeetingMainPage> {
|
|||
fontWeight: FontWeight.w500),
|
||||
),
|
||||
SizedBox(width: 12.w),
|
||||
Image.asset(
|
||||
'assets/images/meeting_main_copy.png',
|
||||
width: 18.w,
|
||||
height: 18.h,
|
||||
GestureDetector(
|
||||
child: Container(
|
||||
child: Image.asset(
|
||||
'assets/images/meeting_main_copy.png',
|
||||
width: 18.w,
|
||||
height: 18.h,
|
||||
),
|
||||
padding: const EdgeInsets.all(4),
|
||||
),
|
||||
onTap: (){
|
||||
Clipboard.setData(ClipboardData(text: state.roomNumber.value));
|
||||
ToastUtils.showSuccess("复制成功");
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
|
|
@ -780,6 +789,7 @@ class MeetingMainPageState extends State<MeetingMainPage> {
|
|||
Container(
|
||||
width: 100,
|
||||
margin: const EdgeInsets.only(left: 6),
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
UserStore.to.userInfoEntity.value!.userName,
|
||||
maxLines: 1,
|
||||
|
|
|
|||
Loading…
Reference in New Issue