Browse Source

0016712: 【登录】平板未联网,打开app,在登录页面输入正确的用户名密码,点击登录后,一直转圈

Melon 1 year ago
parent
commit
22d9133476
2 changed files with 27 additions and 18 deletions
  1. 0 1
      lib/managers/account.dart
  2. 27 17
      lib/pages/login/controller.dart

+ 0 - 1
lib/managers/account.dart

@@ -26,7 +26,6 @@ class AccountManager implements IAccountManager {
           .handleLogin(account, result.token!, password, isAutoLogin);
       return true;
     } catch (e) {
-      print(e);
       return false;
     }
   }

+ 27 - 17
lib/pages/login/controller.dart

@@ -1,6 +1,8 @@
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 import 'package:vitalapp/architecture/defines.dart';
+import 'package:vitalapp/architecture/utils/prompt_box.dart';
+import 'package:vitalapp/global.dart';
 // import 'package:vitalapp/architecture/utils/prompt_box.dart';
 import 'package:vitalapp/managers/interfaces/account.dart';
 import 'package:vitalapp/managers/interfaces/diagnosis.dart';
@@ -19,39 +21,33 @@ class LoginController extends FControllerBase {
   final state = LoginState();
 
   void onSubmit() async {
+    if (!kIsOnline) {
+      PromptBox.toast("请检查网络连接");
+      return;
+    }
+
     setBusy('登录中');
     // busy = true;
     try {
       final result = await Get.find<IAccountManager>()
           .login(state.account, state.password, state.isAutoLogin);
       if (result) {
-        await Get.find<IDoctorManager>().syncInfo();
-        await Future.wait([
-          // 更新应用级配置
-          Get.find<ISystemSettingManager>().getSettings(true),
-          // 更新机构相关配置
-          Get.find<IOrganizationManager>().syncConfigurations(),
-          //更新本地离线居民数据userCode等于空的数据
-          Get.find<IPatientManager>().resettingUsercodeIsEmptyData(),
-          //更新本地离线测试数据userCode等于空的数据
-          Get.find<IDiagnosisManager>().resettingUsercodeIsEmptyData(),
-        ]);
-
+        await _syncAfterLogin();
         // PromptBox.toast("登录成功");
         busy = false;
         Get.offAllNamed("/");
 
         /// 主页不确定 先跳检测页面
         // Get.offAllNamed('/medical', id: 1001);
-
-        return;
+      } else {
+        busy = false;
+        PromptBox.toast("登录失败");
       }
     } catch (e) {
       logger.e("LoginController login error", e);
-    } finally {
-      // busy = false;
+      busy = false;
+      PromptBox.error("登录异常");
     }
-    // PromptBox.error("登录失败");
   }
 
   @override
@@ -94,5 +90,19 @@ class LoginController extends FControllerBase {
     }
   }
 
+  Future<void> _syncAfterLogin() async {
+    await Get.find<IDoctorManager>().syncInfo();
+    await Future.wait([
+      // 更新应用级配置
+      Get.find<ISystemSettingManager>().getSettings(true),
+      // 更新机构相关配置
+      Get.find<IOrganizationManager>().syncConfigurations(),
+      //更新本地离线居民数据userCode等于空的数据
+      Get.find<IPatientManager>().resettingUsercodeIsEmptyData(),
+      //更新本地离线测试数据userCode等于空的数据
+      Get.find<IDiagnosisManager>().resettingUsercodeIsEmptyData(),
+    ]);
+  }
+
   void _doDispose() {}
 }