Просмотр исходного кода

1、新增权限获取错误日志
2、优化在无权限的时候获取权限

guanxinyi 4 месяцев назад
Родитель
Сommit
c7e7cc8aca
2 измененных файлов с 20 добавлено и 6 удалено
  1. 19 5
      lib/architecture/states/modules/user.dart
  2. 1 1
      lib/main.dart

+ 19 - 5
lib/architecture/states/modules/user.dart

@@ -249,7 +249,13 @@ extension UserStateHost on UserState {
   /// 是否有指定权限
   ///
   /// [key] 权限Key
-  bool hasFeature(String key) => features.contains(key);
+  bool hasFeature(String key) {
+    if (features.length == 0) {
+      logger.e("current features is empty");
+      setAuthFeatures();
+    }
+    return features.contains(key);
+  }
 
   /// 是否有机构管理员的权限
   bool? hasOrgFeature() {
@@ -304,7 +310,7 @@ extension UserStateHost on UserState {
       else
         return;
     } catch (e) {
-      // logger.e("defaultThesaurus fetch features error.", e);
+      logger.e("defaultThesaurus fetch error.", e);
     }
   }
 
@@ -391,9 +397,13 @@ extension UserStateHost on UserState {
   }
 
   /// 处理科研版获取权限的事件
-  Future<void> handleSetAuth() async {
-    await _fetchFeatures();
-    await Store.persistent();
+  Future<void> handleSetLabAuth() async {
+    try {
+      await _fetchFeatures();
+      await Store.persistent();
+    } catch (err) {
+      logger.e("UserState set lab features error.", err);
+    }
   }
 
   /// 处理注册成功之后事件
@@ -406,6 +416,10 @@ extension UserStateHost on UserState {
     await Store.persistent();
   }
 
+  void setAuthFeatures() async {
+    await _fetchFeatures();
+  }
+
   void _clearFeatures() => _features = RxList<String>();
   void _setFeatures(Iterable<String> arr) =>
       _features.value = List.unmodifiable(arr);

+ 1 - 1
lib/main.dart

@@ -105,7 +105,7 @@ class _App extends StatelessWidget {
     }
     if (Global.isVStationSlave) {
       initRoute = RouteNames.Lab.Main;
-      Store.user.handleSetAuth();
+      Store.user.handleSetLabAuth();
     }
 
     bool ifFirstTime = true; // 是否为首次进入