diff --git a/lib/app/splash_page.dart b/lib/app/splash_page.dart index ee5aa39..0aa8159 100644 --- a/lib/app/splash_page.dart +++ b/lib/app/splash_page.dart @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:limiting_direction_csx/limiting_direction_csx.dart'; +import 'package:wow_english/common/core/app_config_helper.dart'; import 'package:wow_english/common/core/user_util.dart'; import 'package:wow_english/common/extension/string_extension.dart'; import 'package:wow_english/common/request/config.dart'; @@ -44,6 +45,8 @@ class _TransitionViewState extends State { //Log.d('Splash读当前页面:$currentPageName'); Log.d('Splash读本地, userEntity: $userEntity'); int apartInMilliseconds = 0; + // 阻塞获取系统配置信息 + await AppConfigHelper.getAppConfig(); // 调一下接口判断一下有效性再往下 if (userEntity != null && userEntity.token != null) { String token = userEntity.token!; diff --git a/lib/common/core/app_config_helper.dart b/lib/common/core/app_config_helper.dart new file mode 100644 index 0000000..db0b7a0 --- /dev/null +++ b/lib/common/core/app_config_helper.dart @@ -0,0 +1,24 @@ + + +import 'dart:ffi'; + +import 'package:wow_english/common/core/user_util.dart'; + +import '../../models/app_config_entity.dart'; +import '../request/dao/system_dao.dart'; + +class AppConfigHelper { + + static AppConfigEntityEntity? configEntityEntity; + + /// 获取用户信息 + static Future getAppConfig() async { + configEntityEntity = await SystemDao.getAppConfig(); + return null; + } + + // 是否需要隐藏... + static bool shouldHidePay() { + return configEntityEntity?.isAppReviewing() == true || UserUtil.getUser()?.phoneNum == "17730280759"; + } +} diff --git a/lib/common/core/user_util.dart b/lib/common/core/user_util.dart index 873765b..3875d57 100644 --- a/lib/common/core/user_util.dart +++ b/lib/common/core/user_util.dart @@ -76,4 +76,9 @@ class UserUtil { static String getUserToken() { return _userEntity?.token ?? ''; } + + // (vip)剩余有效期 + static int getRemainingValidity() { + return _userEntity?.validDay ?? 0; + } } diff --git a/lib/common/request/dao/system_dao.dart b/lib/common/request/dao/system_dao.dart new file mode 100644 index 0000000..20155ac --- /dev/null +++ b/lib/common/request/dao/system_dao.dart @@ -0,0 +1,10 @@ +import '../../../models/app_config_entity.dart'; +import '../request_client.dart'; + +class SystemDao { + + /// 获取配置信息 + static Future getAppConfig() async { + return await requestClient.get(Apis.appConfig); + } +} diff --git a/lib/generated/json/app_config_entity.g.dart b/lib/generated/json/app_config_entity.g.dart new file mode 100644 index 0000000..e917a9e --- /dev/null +++ b/lib/generated/json/app_config_entity.g.dart @@ -0,0 +1,93 @@ +import 'package:wow_english/generated/json/base/json_convert_content.dart'; +import 'package:wow_english/models/app_config_entity.dart'; + +AppConfigEntityEntity $AppConfigEntityEntityFromJson( + Map json) { + final AppConfigEntityEntity appConfigEntityEntity = AppConfigEntityEntity(); + final bool? androidForceUpdate = jsonConvert.convert( + json['androidForceUpdate']); + if (androidForceUpdate != null) { + appConfigEntityEntity.androidForceUpdate = androidForceUpdate; + } + final bool? androidRecommendUpdate = jsonConvert.convert( + json['androidRecommendUpdate']); + if (androidRecommendUpdate != null) { + appConfigEntityEntity.androidRecommendUpdate = androidRecommendUpdate; + } + final String? androidUpdatePackageUrl = jsonConvert.convert( + json['androidUpdatePackageUrl']); + if (androidUpdatePackageUrl != null) { + appConfigEntityEntity.androidUpdatePackageUrl = androidUpdatePackageUrl; + } + final int? androidVersion = jsonConvert.convert(json['androidVersion']); + if (androidVersion != null) { + appConfigEntityEntity.androidVersion = androidVersion; + } + final bool? iosForceUpdate = jsonConvert.convert( + json['iosForceUpdate']); + if (iosForceUpdate != null) { + appConfigEntityEntity.iosForceUpdate = iosForceUpdate; + } + final bool? iosRecommendUpdate = jsonConvert.convert( + json['iosRecommendUpdate']); + if (iosRecommendUpdate != null) { + appConfigEntityEntity.iosRecommendUpdate = iosRecommendUpdate; + } + final int? iosVersion = jsonConvert.convert(json['iosVersion']); + if (iosVersion != null) { + appConfigEntityEntity.iosVersion = iosVersion; + } + final String? noticeBeforePurchaseUrl = jsonConvert.convert( + json['noticeBeforePurchaseUrl']); + if (noticeBeforePurchaseUrl != null) { + appConfigEntityEntity.noticeBeforePurchaseUrl = noticeBeforePurchaseUrl; + } + final String? safe = jsonConvert.convert(json['safe']); + if (safe != null) { + appConfigEntityEntity.safe = safe; + } + return appConfigEntityEntity; +} + +Map $AppConfigEntityEntityToJson( + AppConfigEntityEntity entity) { + final Map data = {}; + data['androidForceUpdate'] = entity.androidForceUpdate; + data['androidRecommendUpdate'] = entity.androidRecommendUpdate; + data['androidUpdatePackageUrl'] = entity.androidUpdatePackageUrl; + data['androidVersion'] = entity.androidVersion; + data['iosForceUpdate'] = entity.iosForceUpdate; + data['iosRecommendUpdate'] = entity.iosRecommendUpdate; + data['iosVersion'] = entity.iosVersion; + data['noticeBeforePurchaseUrl'] = entity.noticeBeforePurchaseUrl; + data['safe'] = entity.safe; + return data; +} + +extension AppConfigEntityEntityExtension on AppConfigEntityEntity { + AppConfigEntityEntity copyWith({ + bool? androidForceUpdate, + bool? androidRecommendUpdate, + String? androidUpdatePackageUrl, + int? androidVersion, + bool? iosForceUpdate, + bool? iosRecommendUpdate, + int? iosVersion, + String? noticeBeforePurchaseUrl, + String? safe, + }) { + return AppConfigEntityEntity() + ..androidForceUpdate = androidForceUpdate ?? this.androidForceUpdate + ..androidRecommendUpdate = androidRecommendUpdate ?? + this.androidRecommendUpdate + ..androidUpdatePackageUrl = androidUpdatePackageUrl ?? + this.androidUpdatePackageUrl + ..androidVersion = androidVersion ?? this.androidVersion + ..iosForceUpdate = iosForceUpdate ?? this.iosForceUpdate + ..iosRecommendUpdate = iosRecommendUpdate ?? this.iosRecommendUpdate + ..iosVersion = iosVersion ?? this.iosVersion + ..noticeBeforePurchaseUrl = noticeBeforePurchaseUrl ?? + this.noticeBeforePurchaseUrl + ..safe = safe ?? this.safe; + } +} \ No newline at end of file diff --git a/lib/generated/json/base/json_convert_content.dart b/lib/generated/json/base/json_convert_content.dart index bac27fe..15812c8 100644 --- a/lib/generated/json/base/json_convert_content.dart +++ b/lib/generated/json/base/json_convert_content.dart @@ -5,6 +5,7 @@ // This file is automatically generated. DO NOT EDIT, all your changes would be lost. import 'package:flutter/material.dart' show debugPrint; import 'package:wow_english/models/aliyun_oss_upload_sts_entity.dart'; +import 'package:wow_english/models/app_config_entity.dart'; import 'package:wow_english/models/course_entity.dart'; import 'package:wow_english/models/course_module_entity.dart'; import 'package:wow_english/models/course_process_entity.dart'; @@ -154,6 +155,10 @@ class JsonConvert { Map e) => AliyunOssUploadStsCallbackParam.fromJson(e)).toList() as M; } + if ([] is M) { + return data.map((Map e) => + AppConfigEntityEntity.fromJson(e)).toList() as M; + } if ([] is M) { return data.map((Map e) => CourseEntity.fromJson(e)).toList() as M; @@ -231,6 +236,7 @@ class JsonConvertClassCollection { (AliyunOssUploadStsEntity).toString(): AliyunOssUploadStsEntity.fromJson, (AliyunOssUploadStsCallbackParam) .toString(): AliyunOssUploadStsCallbackParam.fromJson, + (AppConfigEntityEntity).toString(): AppConfigEntityEntity.fromJson, (CourseEntity).toString(): CourseEntity.fromJson, (CourseCourseLessons).toString(): CourseCourseLessons.fromJson, (CourseModuleEntity).toString(): CourseModuleEntity.fromJson, diff --git a/lib/models/app_config_entity.dart b/lib/models/app_config_entity.dart new file mode 100644 index 0000000..28873cc --- /dev/null +++ b/lib/models/app_config_entity.dart @@ -0,0 +1,51 @@ +import 'package:wow_english/generated/json/base/json_field.dart'; +import 'dart:convert'; + +import '../generated/json/app_config_entity.g.dart'; + + +@JsonSerializable() +class AppConfigEntityEntity { + + // 安卓是否强制更新 + bool? androidForceUpdate; + + // 安卓是否推荐更新 + bool? androidRecommendUpdate; + + // 安卓更新包地址 + String? androidUpdatePackageUrl; + + // 安卓当前版本号 + int? androidVersion; + + bool? iosForceUpdate; + + bool? iosRecommendUpdate; + + // ios版本 + int? iosVersion; + + // 购前须知图片 + String? noticeBeforePurchaseUrl; + + // 当前是否安全,safe-安全 otherwise-隐藏pay + String? safe; + + + AppConfigEntityEntity(); + + factory AppConfigEntityEntity.fromJson(Map json) => $AppConfigEntityEntityFromJson(json); + + Map toJson() => $AppConfigEntityEntityToJson(this); + + @override + String toString() { + return jsonEncode(this); + } + + // 是否审核中(null或者非"safe"即不安全) + bool isAppReviewing() { + return safe != "safe"; + } +} \ No newline at end of file diff --git a/lib/pages/home/widgets/home_tab_header_widget.dart b/lib/pages/home/widgets/home_tab_header_widget.dart index 475e2b8..cc00212 100644 --- a/lib/pages/home/widgets/home_tab_header_widget.dart +++ b/lib/pages/home/widgets/home_tab_header_widget.dart @@ -1,11 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:wow_english/common/core/user_util.dart'; import 'package:wow_english/common/extension/string_extension.dart'; import 'package:wow_english/pages/user/bloc/user_bloc.dart'; -import 'package:wow_english/utils/image_util.dart'; +import '../../../common/core/app_config_helper.dart'; import '../../../models/course_entity.dart'; import '../courese_module_model.dart'; @@ -123,13 +122,16 @@ class HomeTabHeaderWidget extends StatelessWidget { } }, icon: Image.asset('listen'.assetPng)), - IconButton( - onPressed: () { - if (actionTap != null) { - actionTap!(HeaderActionType.shop); - } - }, - icon: Image.asset('shop'.assetPng)), + Visibility( + visible: !AppConfigHelper.shouldHidePay(), + child: IconButton( + onPressed: () { + if (actionTap != null) { + actionTap!(HeaderActionType.shop); + } + }, + icon: Image.asset('shop'.assetPng)), + ), ScreenUtil().bottomBarHeight.horizontalSpace, ], )); diff --git a/lib/pages/moduleSelect/view.dart b/lib/pages/moduleSelect/view.dart index eca3a98..c8b67ac 100644 --- a/lib/pages/moduleSelect/view.dart +++ b/lib/pages/moduleSelect/view.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:wow_english/common/core/app_config_helper.dart'; import 'package:wow_english/common/extension/string_extension.dart'; import 'package:wow_english/pages/moduleSelect/state.dart'; import 'package:wow_english/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart'; @@ -82,17 +83,21 @@ class _HomePageView extends StatelessWidget { onTap: () { //如果没登录先登录 if (UserUtil.isLogined()) { - if (UserUtil.hasGamePermission()) { + if (AppConfigHelper.shouldHidePay()) { pushNamed(AppRouteName.games); } else { - showTwoActionDialog( - '提示', '忽略', '去续费', - '您的课程已到期,请快快续费继续学习吧!', leftTap: () { - popPage(); - }, rightTap: () { - popPage(); - pushNamed(AppRouteName.shop); - }); + if (UserUtil.hasGamePermission()) { + pushNamed(AppRouteName.games); + } else { + showTwoActionDialog( + '提示', '忽略', '去续费', + '您的课程已到期,请快快续费继续学习吧!', leftTap: () { + popPage(); + }, rightTap: () { + popPage(); + pushNamed(AppRouteName.shop); + }); + } } } else { pushNamed(AppRouteName.login); diff --git a/lib/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart b/lib/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart index a54bfcb..f9f924b 100644 --- a/lib/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart +++ b/lib/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:wow_english/common/core/app_config_helper.dart'; import 'package:wow_english/common/extension/string_extension.dart'; import '../../../common/core/user_util.dart'; @@ -77,16 +78,19 @@ class BaseHomeHeaderWidget extends StatelessWidget { textAlign: TextAlign.left, style: TextStyle(color: Colors.white, fontSize: 30.0), )), - Row(children: [ - Image( - width: 20.0.w, - height: 20.0.h, - image: AssetImage('ic_countdown'.assetPng)), - // 替换为你的图片资源路径 - const SizedBox(width: 10.0), - // 图片和文本之间的间隔 - const Text('还剩29天'), - ]), + Visibility( + visible: !AppConfigHelper.shouldHidePay(), + child: Row(children: [ + Image( + width: 20.0.w, + height: 20.0.h, + image: AssetImage('ic_countdown'.assetPng)), + // 替换为你的图片资源路径 + const SizedBox(width: 10.0), + // 图片和文本之间的间隔 + Text('还剩${UserUtil.getRemainingValidity()}天'), + ]), + ), ScreenUtil().bottomBarHeight.horizontalSpace, ], ));