setting_controller.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. ToastEngine.show("确定删除账号");
  30. },
  31. ));
  32. }
  33. //确定退出登录
  34. void doLogout() {
  35. DialogEngine.show(
  36. widget: AppDefaultDialog(
  37. title: "Confirmation".tr,
  38. message: "Are you sure you need to exit the system?".tr,
  39. confirmAction: () {
  40. _requestLogout();
  41. },
  42. ));
  43. }
  44. /// 请求接口退出账号
  45. void _requestLogout() async {
  46. var result = await _authRepository.userLogout(cancelToken: cancelToken);
  47. //处理数据
  48. if (result.isSuccess) {
  49. //保存Token,去首页
  50. UserService.to.handleLogoutParams();
  51. LoginPage.startWithPopAll();
  52. } else {
  53. ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
  54. }
  55. }
  56. }