yangyang hace 2 años
padre
commit
b3311a71ad

+ 36 - 0
lib/common/dialog/LoadingDialogWidget.dart

@@ -0,0 +1,36 @@
+import 'package:flutter/material.dart';
+
+///Loading弹窗
+///网络请求等场景使用
+class LoadingDialogWidget extends StatelessWidget {
+  bool dismissible = false;
+
+  LoadingDialogWidget({Key? key, required this.dismissible}) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return Stack(
+      alignment: Alignment.center,
+      children: [
+        ///拦截返回导航
+        WillPopScope(
+            child: Container(
+              decoration: BoxDecoration(
+                  borderRadius: BorderRadius.circular(4),
+                  color: Colors.grey[200]),
+              padding: const EdgeInsets.all(20),
+              height: 80,
+              width: 80,
+              child: CircularProgressIndicator(
+                color: Theme.of(context).primaryColor,
+                backgroundColor: Colors.grey[300],
+              ),
+            ),
+
+            ///拦截返回按钮:false = 不允许通过返回按钮关闭弹窗
+            onWillPop: () => Future.value(dismissible))
+      ],
+    );
+  }
+}
+

+ 4 - 10
lib/common/utils/DioUtil.dart

@@ -1,6 +1,5 @@
 import 'package:deus_app/common/local/StoreHelper.dart';
 import 'package:deus_app/common/utils/ConstantString.dart';
-import 'package:deus_app/common/utils/ToastUtils.dart';
 import 'package:dio/dio.dart';
 
 /// 请求方法
@@ -20,10 +19,10 @@ class DioUtil {
   static DioUtil? get instance => _instance ?? DioUtil._internal();
 
   /// 连接超时时间
-  static const int connectTimeout = 60 * 1000;
+  static const int connectTimeout = 30 * 1000;
 
   /// 响应超时时间
-  static const int receiveTimeout = 60 * 1000;
+  static const int receiveTimeout = 30 * 1000;
 
   /// Dio实例
   static Dio _dio = Dio();
@@ -31,12 +30,8 @@ class DioUtil {
   /// 初始化
   DioUtil._internal() {
     // 初始化基本选项
-    Map<String, String> map={
-      // 'Bearer Token':''
-    };
     BaseOptions options = BaseOptions(
         baseUrl: 'https://fqgz.flowbb.cn:7070/system-api/',
-        headers: map,
         connectTimeout: connectTimeout,
         receiveTimeout: receiveTimeout);
     _instance = this;
@@ -79,7 +74,6 @@ class DioUtil {
   /// 错误处理
   void _onError(DioError error, ErrorInterceptorHandler handler) {
     handler.next(error);
-    showToast(error.message);
   }
 
   /// 请求类
@@ -113,8 +107,8 @@ class DioUtil {
           onReceiveProgress: onReceiveProgress);
         return response.data;
     } on DioError catch (e) {
-      showToast(e.message);
-      rethrow;
+      // showToast(e.message);
+      return e.response?.data;
     }
   }
 

+ 22 - 0
lib/common/utils/LoadingDialogHelper.dart

@@ -0,0 +1,22 @@
+import 'package:deus_app/common/dialog/LoadingDialogWidget.dart';
+import 'package:flutter/material.dart';
+
+class LoadingDialogHelper {
+  ///展示loading弹窗
+  static void showLoading(BuildContext context, {bool dismissible = false}) {
+    showDialog(
+        barrierDismissible: dismissible,
+        context: context,
+        builder: (context) {
+          return LoadingDialogWidget(
+            dismissible: dismissible,
+          );
+        });
+  }
+
+  ///关闭弹窗
+  static void dismissLoading(BuildContext context) {
+    Navigator.pop(context);
+  }
+}
+

+ 14 - 5
lib/page/login/login_page.dart

@@ -11,6 +11,7 @@ import 'package:deus_app/widget/gsy_flex_button.dart';
 import 'package:flutter/material.dart';
 
 import '../../common/utils/ConstantString.dart';
+import '../../common/utils/LoadingDialogHelper.dart';
 import '../../generated/json/login_response_entity_helper.dart';
 
 // import 'package:deus_app/common/utils/common_utils.dart';
@@ -190,6 +191,7 @@ class _LoginPageState extends State<LoginPage> {
     if (!CommonUtils.validationInput(_username)) {
       showToast(ConstantString.loginNull);
     } else {
+      LoadingDialogHelper.showLoading(context);
       var result = await DioUtil().request('auth/login',
           method: DioMethod.post,
           data: {'username': _username, 'password': _password});
@@ -200,6 +202,7 @@ class _LoginPageState extends State<LoginPage> {
         debugPrint(loginResponseEntity.data.token);
         getInfo();
       } else {
+        LoadingDialogHelper.dismissLoading(context);
         showToast(loginResponseEntity.msg);
       }
     }
@@ -207,11 +210,17 @@ class _LoginPageState extends State<LoginPage> {
   getInfo() async{
     var result = await DioUtil().request('user/current-user',
         method: DioMethod.post);
+    LoadingDialogHelper.dismissLoading(context);
     UserResponseEntity entity=userResponseEntityFromJson(UserResponseEntity(), result);
-    StoreHelper.putStorage(ConstantString.name, entity.data.name);
-    StoreHelper.putStorage(ConstantString.orgName, entity.data.orgName);
-    StoreHelper.putStorage(ConstantString.phone, entity.data.phone);
-    await Navigator.pushNamed(context, HomePage.routeName);
-    Navigator.pop(context);
+    if(entity.code==0){
+      StoreHelper.putStorage(ConstantString.name, entity.data.name);
+      StoreHelper.putStorage(ConstantString.orgName, entity.data.orgName);
+      StoreHelper.putStorage(ConstantString.phone, entity.data.phone);
+      await Navigator.pushNamed(context, HomePage.routeName);
+      Navigator.pop(context);
+    }else{
+      showToast(entity.msg);
+    }
+
   }
 }