mine_controller.dart 4.8 KB

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