|
@@ -1,22 +1,73 @@
|
|
import 'package:cpt_auth/modules/login/login_page.dart';
|
|
import 'package:cpt_auth/modules/login/login_page.dart';
|
|
import 'package:cpt_auth/modules/reset_psd/reset_psd_page.dart';
|
|
import 'package:cpt_auth/modules/reset_psd/reset_psd_page.dart';
|
|
|
|
+import 'package:cpt_auth/modules/setting/dialog/switch_project_dialog.dart';
|
|
|
|
+import 'package:domain/entity/response/index_option_entity.dart';
|
|
import 'package:domain/repository/auth_repository.dart';
|
|
import 'package:domain/repository/auth_repository.dart';
|
|
|
|
+import 'package:domain/repository/ms_repository.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
+import 'package:plugin_basic/constants/app_constant.dart';
|
|
|
|
+import 'package:plugin_basic/service/app_config_service.dart';
|
|
import 'package:plugin_basic/service/user_service.dart';
|
|
import 'package:plugin_basic/service/user_service.dart';
|
|
import 'package:plugin_platform/engine/dialog/dialog_engine.dart';
|
|
import 'package:plugin_platform/engine/dialog/dialog_engine.dart';
|
|
|
|
+import 'package:plugin_platform/engine/notify/notify_engine.dart';
|
|
import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
|
|
import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
|
|
|
|
+import 'package:shared/utils/event_bus.dart';
|
|
|
|
+import 'package:shared/utils/util.dart';
|
|
import 'package:widgets/dialog/app_default_dialog.dart';
|
|
import 'package:widgets/dialog/app_default_dialog.dart';
|
|
|
|
|
|
import 'setting_state.dart';
|
|
import 'setting_state.dart';
|
|
|
|
|
|
class SettingController extends GetxController with DioCancelableMixin {
|
|
class SettingController extends GetxController with DioCancelableMixin {
|
|
final AuthRepository _authRepository = Get.find();
|
|
final AuthRepository _authRepository = Get.find();
|
|
|
|
+ final MSRepository _msRepository = Get.find();
|
|
final SettingState state = SettingState();
|
|
final SettingState state = SettingState();
|
|
|
|
|
|
//切换账号
|
|
//切换账号
|
|
- void switchProjects() {
|
|
|
|
- ToastEngine.show("切换账号");
|
|
|
|
|
|
+ void switchProjects() async {
|
|
|
|
+
|
|
|
|
+ final result = await _msRepository.fetchSwitchProjectList(cancelToken: cancelToken);
|
|
|
|
+
|
|
|
|
+ if (result.isSuccess) {
|
|
|
|
+ final projects = result.data?.cutUser;
|
|
|
|
+
|
|
|
|
+ if (projects != null && projects.isNotEmpty) {
|
|
|
|
+ _showSwitchProjectDialog(projects);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ final errorMessage = result.errorMsg;
|
|
|
|
+ ToastEngine.show(errorMessage ?? "Network Load Error".tr);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void _showSwitchProjectDialog(List<IndexOptionEntity> projects) {
|
|
|
|
+ DialogEngine.show(
|
|
|
|
+ widget: SwitchProjectDialog(
|
|
|
|
+ options: projects,
|
|
|
|
+ confirmAction: (entity) {
|
|
|
|
+
|
|
|
|
+ _requestSwitchProject(entity);
|
|
|
|
+ },
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void _requestSwitchProject(IndexOptionEntity entity) async{
|
|
|
|
+ final result = await _msRepository.switchProjectSubmit(entity.value,cancelToken: cancelToken);
|
|
|
|
+
|
|
|
|
+ if (result.isSuccess) {
|
|
|
|
+
|
|
|
|
+ NotifyEngine.showSuccess('successful'.tr);
|
|
|
|
+
|
|
|
|
+ final token = result.data?.token;
|
|
|
|
+ UserService.to.setToken(token);
|
|
|
|
+
|
|
|
|
+ //发送通知刷新首页
|
|
|
|
+ bus.emit(AppConstant.eventMainRefresh, true);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ final errorMessage = result.errorMsg;
|
|
|
|
+ ToastEngine.show(errorMessage ?? "Network Load Error".tr);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//去重置密码页面
|
|
//去重置密码页面
|
|
@@ -63,7 +114,7 @@ class SettingController extends GetxController with DioCancelableMixin {
|
|
|
|
|
|
/// 请求接口退出账号
|
|
/// 请求接口退出账号
|
|
void _requestLogout() async {
|
|
void _requestLogout() async {
|
|
- var result = await _authRepository.userLogout(cancelToken: cancelToken);
|
|
|
|
|
|
+ var result = await _authRepository.userLogout(country: ConfigService.to.selectCountry.value, cancelToken: cancelToken);
|
|
|
|
|
|
//处理数据
|
|
//处理数据
|
|
if (result.isSuccess) {
|
|
if (result.isSuccess) {
|
|
@@ -74,4 +125,5 @@ class SettingController extends GetxController with DioCancelableMixin {
|
|
ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|