zodiac_love_today_controller.dart 2.7 KB

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