Przeglądaj źródła

登录的一些角色选择逻辑

liukai 4 miesięcy temu
rodzic
commit
9a49a092ea

+ 5 - 0
packages/cpt_auth/lib/modules/login/login_controller.dart

@@ -3,7 +3,9 @@ import 'package:cpt_auth/modules/reset_psd/reset_psd_page.dart';
 import 'package:domain/entity/response/hotel_info_entity.dart';
 import 'package:domain/repository/auth_repository.dart';
 import 'package:get/get.dart';
+import 'package:plugin_basic/constants/app_constant.dart';
 import 'package:plugin_basic/service/user_service.dart';
+import 'package:plugin_platform/engine/sp/sp_util.dart';
 import 'package:plugin_platform/engine/toast/toast_engine.dart';
 import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
 import 'package:router/componentRouter/component_router_service.dart';
@@ -74,6 +76,9 @@ class LoginController extends GetxController with DioCancelableMixin {
     final token = result.token;
     UserService.to.setToken(token);
 
+    //保存是否是管理员登录
+    SPUtil.putInt(AppConstant.storageIsAdmin, state.loginOptionPosition);
+
     //去首页
     MainPage.startWithPopAll();
   }

+ 1 - 1
packages/cpt_auth/lib/modules/login/login_state.dart

@@ -23,7 +23,7 @@ class LoginState {
   //登录的功能选项
   final loginOption = ['Sign in/Sign out'.tr, 'Admin'.tr];
 
-  //登录选项默认选中索引为0
+  //登录选项默认选中索引为0  (0是签到签出 , 1是管理员)
   int loginOptionPosition = 0;
 
   //是否明文展示密码

+ 13 - 4
packages/cpt_auth/lib/modules/main/main_controller.dart

@@ -3,7 +3,9 @@ import 'package:domain/entity/home_module.dart';
 import 'package:domain/entity/response/hotel_info_entity.dart';
 import 'package:domain/repository/auth_repository.dart';
 import 'package:get/get.dart';
+import 'package:plugin_basic/constants/app_constant.dart';
 import 'package:plugin_basic/service/user_service.dart';
+import 'package:plugin_platform/engine/sp/sp_util.dart';
 import 'package:plugin_platform/engine/toast/toast_engine.dart';
 import 'package:router/componentRouter/component_router_service.dart';
 import 'package:widgets/load_state_layout.dart';
@@ -80,12 +82,19 @@ class MainController extends GetxController {
       //有数据,判断是刷新还是加载更多的数据
       state.datas.clear();
 
-      //根据Key筛选需要展示的模块
-      for (var hotelInfo in list) {
-        if (hotelInfo.key != null) {
-          state.datas.addAll(_filterModulesByKey(hotelInfo.key!));
+      int? isAdmin = SPUtil.getInt(AppConstant.storageIsAdmin);
+      if (isAdmin == 1) {
+        //如果是管理员登录,根据Key筛选需要展示的模块
+        for (var hotelInfo in list) {
+          if (hotelInfo.key != null) {
+            state.datas.addAll(_filterModulesByKey(hotelInfo.key!));
+          }
         }
+      } else {
+        //如果只是签到签出模式,手动的添加模块
+        state.datas.addAll(_filterModulesByKey("sign"));
       }
+
       //更新状态
       changeLoadingState(LoadState.State_Success);
     } else {

+ 1 - 0
packages/cs_plugin_basic/lib/constants/app_constant.dart

@@ -13,6 +13,7 @@ class AppConstant {
   // 本地SP存储key
   static const storageGuideFirst = 'guide_first'; //是否经历过Guide
   static const storageToken = 'token'; //用户的Token
+  static const storageIsAdmin = 'is_admin'; //登录选项是签到签出还是管理员登录(是否展示全功能) 0是签到签出 , 1是管理员
   static const searchJobHistoryRecord = 'search_job_history_record'; //兼职工作搜索记录
   static const storageNotificationEnable = 'storage_notification_enable'; //应用设置的推送是否开启
   static const storageDeviceUUID = 'storage_device_uuid'; //设备的UUID

+ 1 - 25
packages/cs_plugin_basic/lib/service/user_service.dart

@@ -56,35 +56,11 @@ class UserService extends GetxService {
     Log.d('UserService =========> 设置Token为:$token');
   }
 
-  // /// 请求接口获取用户详情
-  // Future<HotelInfoEntity?> fetchHotelInfo() async {
-  //   //获取到数据
-  //   var result = await _authRepository.fetchHotelInfo();
-  //
-  //   //处理数据
-  //   if (result.isSuccess) {
-  //     final userProfile = result.data;
-  //     if (userProfile != null) {
-  //       //赋值给Rx对象
-  //       this.hotelInfo.value = userProfile;
-  //       bus.emit(AppConstant.eventHotelInfoRefreshFinish, true);
-  //
-  //       return userProfile;
-  //     } else {
-  //       bus.emit(AppConstant.eventHotelInfoRefreshFinish, true);
-  //       return null;
-  //     }
-  //   } else {
-  //     SmartDialog.showToast(result.errorMsg ?? '');
-  //     bus.emit(AppConstant.eventHotelInfoRefreshFinish, true);
-  //     return null;
-  //   }
-  //
-  // }
 
   /// 处理退出登录之后的数据清除
   void handleLogoutParams() {
     SPUtil.remove(AppConstant.storageToken);
+    SPUtil.remove(AppConstant.storageIsAdmin);
     haslogin.value = false;
     hotelInfo.value = HotelInfoEntity();
   }