account_controller.dart 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'package:get/get.dart';
  2. import '../../../../config/translations/strings_enum.dart';
  3. import '../../../../utils/device_manager.dart';
  4. import '../../../constants/enums.dart';
  5. import '../../../controllers/api_controller.dart';
  6. import '../../../data/sp/ix_sp.dart';
  7. import '../../../dialog/loading/loading_dialog.dart';
  8. import '../../../routes/app_pages.dart';
  9. class AccountController extends GetxController {
  10. final _apiController = Get.find<ApiController>();
  11. // 是否是会员(true: Premium, false: Free)
  12. final _isPremium = false.obs;
  13. bool get isPremium => _isPremium.value;
  14. set isPremium(bool value) => _isPremium.value = value;
  15. //是否是游客
  16. final _isGuest = false.obs;
  17. bool get isGuest => _isGuest.value;
  18. set isGuest(bool value) => _isGuest.value = value;
  19. // UID
  20. String uid = '';
  21. // Free 用户剩余时间
  22. final freeTime = '01:60:59 / Days';
  23. // Premium 用户有效期
  24. final validTerm = 'Year / 2026-12-12';
  25. // 设备授权数量
  26. final deviceCount = 1;
  27. final maxDeviceCount = 4;
  28. /// 切换会员状态(用于测试)
  29. void togglePremium() {
  30. isPremium = !isPremium;
  31. }
  32. @override
  33. void onInit() {
  34. super.onInit();
  35. initIsGuest();
  36. uid = DeviceManager.getCacheDeviceId().length > 12
  37. ? '${DeviceManager.getCacheDeviceId().substring(0, 6)}***${DeviceManager.getCacheDeviceId().substring(DeviceManager.getCacheDeviceId().length - 6)}'
  38. : DeviceManager.getCacheDeviceId();
  39. }
  40. void initIsGuest() {
  41. final user = IXSP.getUser();
  42. if (user != null) {
  43. isGuest = user.memberLevel == MemberLevel.guest.level;
  44. }
  45. }
  46. // 处理退出登录
  47. Future<void> handleLogout() async {
  48. await LoadingDialog.show(
  49. context: Get.context!,
  50. loadingText: Strings.loggingOut.tr,
  51. successText: Strings.logoutSuccessful.tr,
  52. onRequest: () async {
  53. // 执行你的异步请求
  54. await _apiController.logout();
  55. },
  56. onSuccess: () {
  57. // 成功后的操作
  58. Get.offAllNamed(Routes.HOME);
  59. },
  60. );
  61. }
  62. // 处理删除账户
  63. Future<void> handleDeleteAccount() async {
  64. await LoadingDialog.show(
  65. context: Get.context!,
  66. loadingText: Strings.deletingAccount.tr,
  67. successText: Strings.deleteAccountSuccessful.tr,
  68. onRequest: () async {
  69. // 执行你的异步请求
  70. await _apiController.deleteAccount();
  71. },
  72. onSuccess: () {
  73. // 成功后的操作
  74. Get.offAllNamed(Routes.HOME);
  75. },
  76. );
  77. }
  78. }