zodiac_love_today_controller.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. if (PlatformUtil.isIOS) {
  66. LoginPage.start();
  67. } else {
  68. LoginDialog.show();
  69. }
  70. } else if (error.code == ErrorCode.noMember) {
  71. // 需要VIP
  72. ToastUtil.show(StringName.needVipTip);
  73. NewDiscountPage.start();
  74. } else {
  75. ErrorHandler.toastError(error);
  76. }
  77. } else {
  78. ErrorHandler.toastError(error);
  79. }
  80. } finally {
  81. // 生成结束
  82. isReportCreating.value = false;
  83. }
  84. }
  85. /// 点击解锁按钮
  86. void clickUnlockBtn() {
  87. // 跳转去会员活动页
  88. NewDiscountPage.start();
  89. }
  90. }