| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- import 'dart:io';
- import 'package:flutter/material.dart';
- import 'package:flutter/rendering.dart';
- import 'package:injectable/injectable.dart';
- import 'package:keyboard/base/base_controller.dart';
- import 'package:keyboard/data/api/response/user_info_response.dart';
- import 'package:keyboard/data/bean/member_info.dart';
- import 'package:keyboard/module/about/about_page.dart';
- import 'package:keyboard/module/feedback/feedback_controller.dart';
- import 'package:keyboard/module/feedback/feedback_page.dart';
- import 'package:keyboard/module/user_info/user_info_page.dart';
- import '../../data/consts/build_config.dart';
- import '../../data/consts/web_url.dart';
- import '../../data/repository/account_repository.dart';
- import '../../dialog/login/login_dialog.dart';
- import '../../plugins/keyboard_android_platform.dart';
- import '../../resource/string.gen.dart';
- import '../../utils/app_info_util.dart';
- import '../../utils/date_util.dart';
- import '../../utils/keyboard_tutorial_util.dart';
- import '../../utils/toast_util.dart';
- import '../browser/browser_page.dart';
- import '../store/store_page.dart';
- import '../user_profile/user_profile_page.dart';
- @injectable
- class MineController extends BaseController {
- final AccountRepository accountRepository;
- MineController(this.accountRepository);
- bool get isLogin => accountRepository.isLogin.value;
- String? get phone => accountRepository.loginPhoneNum.value;
- UserInfoResponse? get userInfo => accountRepository.userInfo.value;
- MemberInfo? get memberInfo => accountRepository.memberStatusInfo.value;
- String getUserName() {
- if (!isLogin) return StringName.mineAccountNoLogin;
- final name = userInfo?.name;
- if (name != null && name.isNotEmpty) {
- return name;
- }
- if (phone != null && phone!.length > 4) {
- return '${StringName.mineAccountLoggedDesc}${phone!.substring(phone!.length - 4)}';
- }
- return StringName.mineAccountNoLogin;
- }
- clickVip() {
- debugPrint('clickVip');
- StorePage.start();
- }
- longClickVip() {
- if (isLogin) {
- UserInfoPage.start();
- } else {
- LoginDialog.show();
- }
- // KeyboardAndroidPlatform.enableFloatingWindow(true);
- // KeyboardAndroidPlatform.openInputMethodSettings();
- }
- clickOnlineCustomerService() {
- final userInfo = accountRepository.userInfo.value;
- if (isLogin) {
- debugPrint('clickOnlineCustomerService');
- goToCustomerService();
- } else {
- ToastUtil.show('请先登录');
- LoginDialog.show();
- return;
- }
- }
- // 七鱼客服
- void goToCustomerService() {
- final userInfo = accountRepository.userInfo.value;
- if (userInfo == null) {
- ToastUtil.show('网络异常,请稍后再试');
- accountRepository.refreshUserInfo();
- return;
- }
- int appPlatform = 0;
- if (Platform.isAndroid) {
- appPlatform = 1;
- } else if (Platform.isIOS) {
- appPlatform = 2;
- }
- //拼接字符串
- String url =
- "${WebUrl.qiyuService}?ssid=${userInfo.ssid}&device_id=${userInfo.deviceId}&app_platform=$appPlatform&app_version=${appInfoUtil.appVersionName}&package_name=${appInfoUtil.packageName}&app_name=${appInfoUtil.appName}";
- BrowserPage.start(url);
- }
- clickUserCard() {
- if (isLogin) {
- UserInfoPage.start();
- } else {
- LoginDialog.show();
- }
- }
- clickTutorials() {
- debugPrint('clickTutorials');
- KeyboardTutorialUtil.start();
- // 测试模isDebug式才生效
- // if (BuildConfig.isDebug) {
- // KeyboardAndroidPlatform.enableFloatingWindow(true);
- // KeyboardAndroidPlatform.openInputMethodSettings();
- // }
- }
- clickPersonalProfile() {
- debugPrint('clickPersonalProfile');
- UserProfilePage.start();
- }
- clickFeedback(FeedbackType type) {
- if (isLogin) {
- debugPrint('clickOnlineCustomerService');
- FeedbackPage.start(type);
- } else {
- ToastUtil.show('请先登录');
- LoginDialog.show();
- return;
- }
- }
- clickAboutUs() {
- debugPrint('clickAboutUs');
- AboutPage.start();
- }
- String getVipButtonDesc() {
- if (memberInfo?.isMember == true && isLogin) {
- if (memberInfo?.permanent == true && isLogin) {
- return StringName.vipLevel2Btn;
- }
- return StringName.vipLevel1Btn;
- }
- return StringName.vipLevel0Btn;
- }
- String getVipLevelDesc() {
- if (memberInfo?.isMember == true && isLogin) {
- if (memberInfo?.permanent == true && isLogin) {
- return StringName.vipLevel2Desc;
- }
- return "${StringName.vipLevel1Desc}${DateUtil.fromMillisecondsSinceEpoch('yyyy年MM月dd日', memberInfo?.endTimestamp ?? 0)}";
- }
- return StringName.vipLevel0Desc;
- }
- }
|