zodiac_love_today_controller.dart 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:get/get.dart';
  2. import 'package:injectable/injectable.dart';
  3. import 'package:keyboard/base/base_controller.dart';
  4. import 'package:keyboard/dialog/login/login_dialog.dart';
  5. import 'package:keyboard/module/login/login_page.dart';
  6. import 'package:keyboard/resource/string.gen.dart';
  7. import 'package:keyboard/utils/error_handler.dart';
  8. import 'package:keyboard/widget/platform_util.dart';
  9. import '../../../data/api/response/zodiac_love_intimacy_response.dart';
  10. import '../../../data/bean/member_info.dart';
  11. import '../../../data/consts/error_code.dart';
  12. import '../../../data/repository/account_repository.dart';
  13. import '../../../data/repository/zodiac_love_intimacy_repository.dart';
  14. import '../../../utils/http_handler.dart';
  15. import '../../../utils/toast_util.dart';
  16. import '../../store/new_discount/new_discount_page.dart';
  17. /// 星座恋爱分析-今日Tab-Controller
  18. @injectable
  19. class ZodiacLoveTodayController extends BaseController {
  20. /// 星座恋爱分析的Repository
  21. final ZodiacLoveIntimacyRepository zodiacLoveIntimacyRepository;
  22. /// 用户信息
  23. final AccountRepository accountRepository;
  24. /// 分析列表
  25. final Rxn<ZodiacLoveIntimacyResponse> zodiacLoveIntimacyResp =
  26. Rxn<ZodiacLoveIntimacyResponse>();
  27. /// 当前用户的会员信息
  28. Rxn<MemberInfo> get memberInfo => accountRepository.memberStatusInfo;
  29. /// 报告是否生成中
  30. RxBool isReportCreating = false.obs;
  31. ZodiacLoveTodayController(
  32. this.zodiacLoveIntimacyRepository,
  33. this.accountRepository,
  34. );
  35. @override
  36. void onInit() {
  37. super.onInit();
  38. ever(memberInfo, (info) {
  39. // 如果是会员了,重新拉取数据
  40. if (info != null) {
  41. if (info.isMember) {
  42. _getZodiacLoveIntimacyToday();
  43. }
  44. }
  45. });
  46. }
  47. @override
  48. void onReady() {
  49. super.onReady();
  50. _getZodiacLoveIntimacyToday();
  51. }
  52. /// 星座恋爱分析-获取今日指数分析
  53. void _getZodiacLoveIntimacyToday() async {
  54. // 生成中
  55. isReportCreating.value = true;
  56. try {
  57. ZodiacLoveIntimacyResponse resp =
  58. await zodiacLoveIntimacyRepository.getZodiacLoveIntimacyToday();
  59. zodiacLoveIntimacyResp.value = resp;
  60. } catch (error) {
  61. if (error is ServerErrorException) {
  62. // 未登录
  63. if (error.code == ErrorCode.noLoginError) {
  64. ToastUtil.show(StringName.accountNoLogin);
  65. LoginDialog.show();
  66. } else if (error.code == ErrorCode.noMember) {
  67. // 需要VIP
  68. ToastUtil.show(StringName.needVipTip);
  69. NewDiscountPage.start();
  70. } else {
  71. ErrorHandler.toastError(error);
  72. }
  73. } else {
  74. ErrorHandler.toastError(error);
  75. }
  76. } finally {
  77. // 生成结束
  78. isReportCreating.value = false;
  79. }
  80. }
  81. /// 点击解锁按钮
  82. void clickUnlockBtn() {
  83. // 跳转去会员活动页
  84. NewDiscountPage.start();
  85. }
  86. }