| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import 'package:get/get.dart';
- import '../../../../config/translations/strings_enum.dart';
- import '../../../../utils/device_manager.dart';
- import '../../../constants/enums.dart';
- import '../../../controllers/api_controller.dart';
- import '../../../data/sp/ix_sp.dart';
- import '../../../dialog/loading/loading_dialog.dart';
- import '../../../routes/app_pages.dart';
- class AccountController extends GetxController {
- final _apiController = Get.find<ApiController>();
- // 是否是会员(true: Premium, false: Free)
- final _isPremium = false.obs;
- bool get isPremium => _isPremium.value;
- set isPremium(bool value) => _isPremium.value = value;
- //是否是游客
- final _isGuest = false.obs;
- bool get isGuest => _isGuest.value;
- set isGuest(bool value) => _isGuest.value = value;
- // UID
- String uid = '';
- // Free 用户剩余时间
- final freeTime = '01:60:59 / Days';
- // Premium 用户有效期
- final validTerm = 'Year / 2026-12-12';
- // 设备授权数量
- final deviceCount = 1;
- final maxDeviceCount = 4;
- /// 切换会员状态(用于测试)
- void togglePremium() {
- isPremium = !isPremium;
- }
- @override
- void onInit() {
- super.onInit();
- initIsGuest();
- uid = DeviceManager.getCacheDeviceId().length > 12
- ? '${DeviceManager.getCacheDeviceId().substring(0, 6)}***${DeviceManager.getCacheDeviceId().substring(DeviceManager.getCacheDeviceId().length - 6)}'
- : DeviceManager.getCacheDeviceId();
- }
- void initIsGuest() {
- final user = IXSP.getUser();
- if (user != null) {
- isGuest = user.memberLevel == MemberLevel.guest.level;
- }
- }
- // 处理退出登录
- Future<void> handleLogout() async {
- await LoadingDialog.show(
- context: Get.context!,
- loadingText: Strings.loggingOut.tr,
- successText: Strings.logoutSuccessful.tr,
- onRequest: () async {
- // 执行你的异步请求
- await _apiController.logout();
- },
- onSuccess: () {
- // 成功后的操作
- Get.offAllNamed(Routes.HOME);
- },
- );
- }
- // 处理删除账户
- Future<void> handleDeleteAccount() async {
- await LoadingDialog.show(
- context: Get.context!,
- loadingText: Strings.deletingAccount.tr,
- successText: Strings.deleteAccountSuccessful.tr,
- onRequest: () async {
- // 执行你的异步请求
- await _apiController.deleteAccount();
- },
- onSuccess: () {
- // 成功后的操作
- Get.offAllNamed(Routes.HOME);
- },
- );
- }
- }
|