setting_controller.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import 'package:cpt_auth/modules/login/login_page.dart';
  2. import 'package:cpt_auth/modules/reset_psd/reset_psd_page.dart';
  3. import 'package:domain/repository/auth_repository.dart';
  4. import 'package:get/get.dart';
  5. import 'package:plugin_basic/service/user_service.dart';
  6. import 'package:plugin_platform/engine/dialog/dialog_engine.dart';
  7. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  8. import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
  9. import 'package:widgets/dialog/app_default_dialog.dart';
  10. import 'setting_state.dart';
  11. class SettingController extends GetxController with DioCancelableMixin {
  12. final AuthRepository _authRepository = Get.find();
  13. final SettingState state = SettingState();
  14. //切换账号
  15. void switchProjects() {
  16. ToastEngine.show("切换账号");
  17. }
  18. //去重置密码页面
  19. void gotoResetPasswordPage() {
  20. ResetPasswordPage.startInstance();
  21. }
  22. //确定删除账号
  23. void doAccountDelete() {
  24. DialogEngine.show(
  25. widget: AppDefaultDialog(
  26. title: "Confirmation".tr,
  27. message: "Are you sure you want to deactivate your account? You will not be able to login into the app once you proceed with the request.".tr,
  28. confirmAction: () {
  29. _requestDeactivate();
  30. },
  31. ));
  32. }
  33. void _requestDeactivate() async {
  34. var result = await _authRepository.hotelDeactivate(cancelToken: cancelToken);
  35. //处理数据
  36. if (result.isSuccess) {
  37. //清除数据,去首页
  38. UserService.to.handleLogoutParams();
  39. LoginPage.startWithPopAll();
  40. } else {
  41. ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
  42. }
  43. }
  44. //确定退出登录
  45. void doLogout() {
  46. DialogEngine.show(
  47. widget: AppDefaultDialog(
  48. title: "Confirmation".tr,
  49. message: "Are you sure you need to exit the system?".tr,
  50. confirmAction: () {
  51. _requestLogout();
  52. },
  53. ));
  54. }
  55. /// 请求接口退出账号
  56. void _requestLogout() async {
  57. var result = await _authRepository.userLogout(cancelToken: cancelToken);
  58. //处理数据
  59. if (result.isSuccess) {
  60. //清除数据,去首页
  61. UserService.to.handleLogoutParams();
  62. LoginPage.startWithPopAll();
  63. } else {
  64. ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
  65. }
  66. }
  67. }