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