mine_controller.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/rendering.dart';
  4. import 'package:injectable/injectable.dart';
  5. import 'package:keyboard/base/base_controller.dart';
  6. import 'package:keyboard/data/api/response/user_info_response.dart';
  7. import 'package:keyboard/data/bean/member_info.dart';
  8. import 'package:keyboard/module/about/about_page.dart';
  9. import 'package:keyboard/module/auto_renewal/auto_renewal_page.dart';
  10. import 'package:keyboard/module/feedback/feedback_controller.dart';
  11. import 'package:keyboard/module/feedback/feedback_page.dart';
  12. import 'package:keyboard/module/user_info/user_info_page.dart';
  13. import '../../data/consts/build_config.dart';
  14. import '../../data/consts/event_report.dart';
  15. import '../../data/consts/web_url.dart';
  16. import '../../data/repository/account_repository.dart';
  17. import '../../dialog/login/login_dialog.dart';
  18. import '../../handler/event_handler.dart';
  19. import '../../plugins/keyboard_android_platform.dart';
  20. import '../../resource/string.gen.dart';
  21. import '../../utils/app_info_util.dart';
  22. import '../../utils/date_util.dart';
  23. import '../../utils/keyboard_tutorial_util.dart';
  24. import '../../utils/toast_util.dart';
  25. import '../browser/browser_page.dart';
  26. import '../login/login_page.dart';
  27. import '../store/store_page.dart';
  28. import '../user_profile/user_profile_page.dart';
  29. @injectable
  30. class MineController extends BaseController {
  31. final AccountRepository accountRepository;
  32. MineController(this.accountRepository);
  33. bool get isLogin => accountRepository.isLogin.value;
  34. String? get phone => accountRepository.loginPhoneNum.value;
  35. UserInfoResponse? get userInfo => accountRepository.userInfo.value;
  36. MemberInfo? get memberInfo => accountRepository.memberStatusInfo.value;
  37. String getUserName() {
  38. if (!isLogin) return StringName.mineAccountNoLogin;
  39. final name = userInfo?.name;
  40. if (name != null && name.isNotEmpty) {
  41. return name;
  42. }
  43. if (phone != null && phone!.length > 4) {
  44. return '${StringName.mineAccountLoggedDesc}${phone!.substring(phone!.length - 4)}';
  45. }
  46. return StringName.mineAccountNoLogin;
  47. }
  48. clickVip() {
  49. debugPrint('clickVip');
  50. EventHandler.report(EventId.event_14000);
  51. StorePage.start();
  52. }
  53. longClickVip() {
  54. if (isLogin) {
  55. UserInfoPage.start();
  56. } else {
  57. LoginPage.start();
  58. // LoginDialog.show();
  59. }
  60. // KeyboardAndroidPlatform.enableFloatingWindow(true);
  61. // KeyboardAndroidPlatform.openInputMethodSettings();
  62. }
  63. clickOnlineCustomerService() {
  64. debugPrint('clickOnlineCustomerService');
  65. final userInfo = accountRepository.userInfo.value;
  66. if (isLogin) {
  67. EventHandler.report(EventId.event_14006);
  68. debugPrint('clickOnlineCustomerService');
  69. goToCustomerService();
  70. } else {
  71. ToastUtil.show('请先登录');
  72. LoginDialog.show();
  73. return;
  74. }
  75. }
  76. // 七鱼客服
  77. void goToCustomerService() {
  78. final userInfo = accountRepository.userInfo.value;
  79. if (userInfo == null) {
  80. ToastUtil.show('网络异常,请稍后再试');
  81. accountRepository.refreshUserInfo();
  82. return;
  83. }
  84. int appPlatform = 0;
  85. if (Platform.isAndroid) {
  86. appPlatform = 1;
  87. } else if (Platform.isIOS) {
  88. appPlatform = 2;
  89. }
  90. //拼接字符串
  91. String url =
  92. "${WebUrl.qiyuService}?ssid=${userInfo.ssid}&device_id=${userInfo.deviceId}&app_platform=$appPlatform&app_version=${appInfoUtil.appVersionName}&package_name=${appInfoUtil.packageName}&app_name=${appInfoUtil.appName}";
  93. BrowserPage.start(url);
  94. }
  95. clickUserCard() {
  96. if (isLogin) {
  97. EventHandler.report(EventId.event_14001);
  98. UserInfoPage.start();
  99. } else {
  100. LoginPage.start();
  101. // LoginDialog.show();
  102. }
  103. }
  104. clickTutorials() {
  105. debugPrint('clickTutorials');
  106. EventHandler.report(EventId.event_14007);
  107. KeyboardTutorialUtil.start();
  108. }
  109. clickPersonalProfile() {
  110. debugPrint('clickPersonalProfile');
  111. EventHandler.report(EventId.event_14008);
  112. UserProfilePage.start();
  113. }
  114. clickAutoRenewal(){
  115. debugPrint('clickAutoRenewal');
  116. if(isLogin){
  117. AutoRenewalPage.start();
  118. }else{
  119. ToastUtil.show('请先登录');
  120. LoginDialog.show();
  121. return;
  122. }
  123. }
  124. clickFeedback(FeedbackType type) {
  125. if (isLogin) {
  126. debugPrint('clickOnlineCustomerService');
  127. if (type == FeedbackType.feedback) {
  128. EventHandler.report(EventId.event_14009);
  129. }else if (type == FeedbackType.complaint) {
  130. EventHandler.report(EventId.event_14010);
  131. }
  132. FeedbackPage.start(type);
  133. } else {
  134. EventHandler.report(EventId.event_14010);
  135. ToastUtil.show('请先登录');
  136. LoginDialog.show();
  137. return;
  138. }
  139. }
  140. clickAboutUs() {
  141. EventHandler.report(EventId.event_14011);
  142. debugPrint('clickAboutUs');
  143. AboutPage.start();
  144. }
  145. String getVipButtonDesc() {
  146. if (memberInfo?.isMember == true && isLogin) {
  147. if (memberInfo?.permanent == true && isLogin) {
  148. return StringName.vipLevel2Btn;
  149. }
  150. return StringName.vipLevel1Btn;
  151. }
  152. return StringName.vipLevel0Btn;
  153. }
  154. String getVipLevelDesc() {
  155. if (memberInfo?.isMember == true && isLogin) {
  156. if (memberInfo?.permanent == true && isLogin) {
  157. return StringName.vipLevel2Desc;
  158. }
  159. return "${StringName.vipLevel1Desc}${DateUtil.fromMillisecondsSinceEpoch('yyyy年MM月dd日', memberInfo?.endTimestamp ?? 0)}";
  160. }
  161. return StringName.vipLevel0Desc;
  162. }
  163. }