Commit 278208b8573ecc4d18c2f4576a8e448c4f7e0a5a

Authored by 吴启风
1 parent 578f1729

feat:1、用户访问权限调整;2、添加游戏访问权限

lib/app/splash_page.dart
@@ -45,8 +45,8 @@ class _TransitionViewState extends State<TransitionView> { @@ -45,8 +45,8 @@ class _TransitionViewState extends State<TransitionView> {
45 Log.d('Splash读本地, userEntity: $userEntity'); 45 Log.d('Splash读本地, userEntity: $userEntity');
46 int apartInMilliseconds = 0; 46 int apartInMilliseconds = 0;
47 // 调一下接口判断一下有效性再往下 47 // 调一下接口判断一下有效性再往下
48 - if (userEntity != null) {  
49 - String token = userEntity.token; 48 + if (userEntity != null && userEntity.token != null) {
  49 + String token = userEntity.token!;
50 DateTime startTime = DateTime.now(); 50 DateTime startTime = DateTime.now();
51 try { 51 try {
52 userEntity = await UserDao.getUserInfo(); 52 userEntity = await UserDao.getUserInfo();
lib/common/core/user_util.dart
@@ -11,8 +11,6 @@ import 'package:wow_english/utils/sp_util.dart'; @@ -11,8 +11,6 @@ import 'package:wow_english/utils/sp_util.dart';
11 class UserUtil { 11 class UserUtil {
12 static UserEntity? _userEntity; 12 static UserEntity? _userEntity;
13 13
14 - static String get token => _userEntity?.token ?? '';  
15 -  
16 static void saveUser(UserEntity? user) { 14 static void saveUser(UserEntity? user) {
17 if (user == null) { 15 if (user == null) {
18 _clearUserData(); 16 _clearUserData();
@@ -64,4 +62,18 @@ class UserUtil { @@ -64,4 +62,18 @@ class UserUtil {
64 }*/ 62 }*/
65 Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(AppRouteName.login, (route) => false, arguments: {'showPasswordPage': showPasswordLoginPage}); 63 Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(AppRouteName.login, (route) => false, arguments: {'showPasswordPage': showPasswordLoginPage});
66 } 64 }
  65 +
  66 + // 是否有游戏权限
  67 + static bool hasGamePermission() {
  68 + return _userEntity?.valid ?? false;
  69 + }
  70 +
  71 + // 是否登录(token是否有效)
  72 + static bool isLogined() {
  73 + return getUserToken().isNotEmpty;
  74 + }
  75 +
  76 + static String getUserToken() {
  77 + return _userEntity?.token ?? '';
  78 + }
67 } 79 }
lib/common/request/dao/user_dao.dart
@@ -16,6 +16,12 @@ class UserDao { @@ -16,6 +16,12 @@ class UserDao {
16 ); 16 );
17 if (data != null) { 17 if (data != null) {
18 UserUtil.saveUser(data); 18 UserUtil.saveUser(data);
  19 + // 由于userInfo接口不会返回token,所以这里需要再次保存一下token
  20 + final token = data.token;
  21 + //登录成功后zip一下getUserInfo,因为进入首页需要的信息在userinfo里,保证进入首页数据是最新的
  22 + data = await getUserInfo();
  23 + data?.token = token;
  24 + UserUtil.saveUser(data);
19 } 25 }
20 return data; 26 return data;
21 } 27 }
lib/common/request/token_interceptor.dart
@@ -5,8 +5,8 @@ class TokenInterceptor extends Interceptor { @@ -5,8 +5,8 @@ class TokenInterceptor extends Interceptor {
5 @override 5 @override
6 void onRequest(RequestOptions options, RequestInterceptorHandler handler) { 6 void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
7 // 判断token不为空插入, todo token的取法应该跟user在一起,这里取不到user 7 // 判断token不为空插入, todo token的取法应该跟user在一起,这里取不到user
8 - if (UserUtil.token.isNotEmpty) {  
9 - options.headers["Auth-token"] = UserUtil.token; 8 + if (UserUtil.isLogined()) {
  9 + options.headers["Auth-token"] = UserUtil.getUserToken();
10 } 10 }
11 options.headers["version"] = '1.0.0'; 11 options.headers["version"] = '1.0.0';
12 super.onRequest(options, handler); 12 super.onRequest(options, handler);
lib/generated/json/user_entity.g.dart
@@ -45,6 +45,14 @@ UserEntity $UserEntityFromJson(Map<String, dynamic> json) { @@ -45,6 +45,14 @@ UserEntity $UserEntityFromJson(Map<String, dynamic> json) {
45 if (effectiveDate != null) { 45 if (effectiveDate != null) {
46 userEntity.effectiveDate = effectiveDate; 46 userEntity.effectiveDate = effectiveDate;
47 } 47 }
  48 + final int? validDay = jsonConvert.convert<int>(json['validDay']);
  49 + if (validDay != null) {
  50 + userEntity.validDay = validDay;
  51 + }
  52 + final bool? valid = jsonConvert.convert<bool>(json['valid']);
  53 + if (valid != null) {
  54 + userEntity.valid = valid;
  55 + }
48 return userEntity; 56 return userEntity;
49 } 57 }
50 58
@@ -60,6 +68,8 @@ Map&lt;String, dynamic&gt; $UserEntityToJson(UserEntity entity) { @@ -60,6 +68,8 @@ Map&lt;String, dynamic&gt; $UserEntityToJson(UserEntity entity) {
60 data['fillUserInfo'] = entity.fillUserInfo; 68 data['fillUserInfo'] = entity.fillUserInfo;
61 data['nowCourseModuleId'] = entity.nowCourseModuleId; 69 data['nowCourseModuleId'] = entity.nowCourseModuleId;
62 data['effectiveDate'] = entity.effectiveDate; 70 data['effectiveDate'] = entity.effectiveDate;
  71 + data['validDay'] = entity.validDay;
  72 + data['valid'] = entity.valid;
63 return data; 73 return data;
64 } 74 }
65 75
@@ -75,6 +85,8 @@ extension UserEntityExtension on UserEntity { @@ -75,6 +85,8 @@ extension UserEntityExtension on UserEntity {
75 int? fillUserInfo, 85 int? fillUserInfo,
76 int? nowCourseModuleId, 86 int? nowCourseModuleId,
77 String? effectiveDate, 87 String? effectiveDate,
  88 + int? validDay,
  89 + bool? valid,
78 }) { 90 }) {
79 return UserEntity() 91 return UserEntity()
80 ..id = id ?? this.id 92 ..id = id ?? this.id
@@ -86,6 +98,8 @@ extension UserEntityExtension on UserEntity { @@ -86,6 +98,8 @@ extension UserEntityExtension on UserEntity {
86 ..phoneNum = phoneNum ?? this.phoneNum 98 ..phoneNum = phoneNum ?? this.phoneNum
87 ..fillUserInfo = fillUserInfo ?? this.fillUserInfo 99 ..fillUserInfo = fillUserInfo ?? this.fillUserInfo
88 ..nowCourseModuleId = nowCourseModuleId ?? this.nowCourseModuleId 100 ..nowCourseModuleId = nowCourseModuleId ?? this.nowCourseModuleId
89 - ..effectiveDate = effectiveDate ?? this.effectiveDate; 101 + ..effectiveDate = effectiveDate ?? this.effectiveDate
  102 + ..validDay = validDay ?? this.validDay
  103 + ..valid = valid ?? this.valid;
90 } 104 }
91 } 105 }
92 \ No newline at end of file 106 \ No newline at end of file
lib/models/user_entity.dart
@@ -9,7 +9,7 @@ class UserEntity { @@ -9,7 +9,7 @@ class UserEntity {
9 late String name; 9 late String name;
10 10
11 /// 一定有也必须要有 11 /// 一定有也必须要有
12 - late String token; 12 + String? token;
13 13
14 //late int expireTime; 14 //late int expireTime;
15 15
@@ -29,6 +29,12 @@ class UserEntity { @@ -29,6 +29,12 @@ class UserEntity {
29 /// 有效时间,VIP,为null没有 29 /// 有效时间,VIP,为null没有
30 String? effectiveDate; 30 String? effectiveDate;
31 31
  32 + /// 有效天数
  33 + int? validDay;
  34 +
  35 + /// 游戏权限
  36 + bool? valid;
  37 +
32 UserEntity(); 38 UserEntity();
33 39
34 factory UserEntity.fromJson(Map<String, dynamic> json) => $UserEntityFromJson(json); 40 factory UserEntity.fromJson(Map<String, dynamic> json) => $UserEntityFromJson(json);
lib/pages/home/home_page.dart
@@ -33,20 +33,20 @@ class _HomePageView extends StatelessWidget { @@ -33,20 +33,20 @@ class _HomePageView extends StatelessWidget {
33 if (type == HeaderActionType.video) { 33 if (type == HeaderActionType.video) {
34 pushNamed(AppRouteName.reAfter); 34 pushNamed(AppRouteName.reAfter);
35 } else if (type == HeaderActionType.phase) { 35 } else if (type == HeaderActionType.phase) {
36 - if(UserUtil.token.isEmpty) {  
37 - pushNamed(AppRouteName.login);  
38 - } else { 36 + if (UserUtil.isLogined()) {
39 pushNamed(AppRouteName.lesson); 37 pushNamed(AppRouteName.lesson);
  38 + } else {
  39 + pushNamed(AppRouteName.login);
40 } 40 }
41 } else if (type == HeaderActionType.listen) { 41 } else if (type == HeaderActionType.listen) {
42 pushNamed(AppRouteName.listen); 42 pushNamed(AppRouteName.listen);
43 } else if (type == HeaderActionType.shop) { 43 } else if (type == HeaderActionType.shop) {
44 pushNamed(AppRouteName.shop); 44 pushNamed(AppRouteName.shop);
45 } else if (type == HeaderActionType.user) { 45 } else if (type == HeaderActionType.user) {
46 - if(UserUtil.token.isEmpty) {  
47 - pushNamed(AppRouteName.login);  
48 - } else { 46 + if (UserUtil.isLogined()) {
49 pushNamed(AppRouteName.user); 47 pushNamed(AppRouteName.user);
  48 + } else {
  49 + pushNamed(AppRouteName.login);
50 } 50 }
51 } else { 51 } else {
52 52
@@ -155,7 +155,7 @@ class _HomePageView extends StatelessWidget { @@ -155,7 +155,7 @@ class _HomePageView extends StatelessWidget {
155 //彩蛋 155 //彩蛋
156 return GestureDetector( 156 return GestureDetector(
157 onTap: () { 157 onTap: () {
158 - if(UserUtil.token.isEmpty) { 158 + if (!UserUtil.isLogined()) {
159 pushNamed(AppRouteName.login); 159 pushNamed(AppRouteName.login);
160 return; 160 return;
161 } 161 }
@@ -173,7 +173,7 @@ class _HomePageView extends StatelessWidget { @@ -173,7 +173,7 @@ class _HomePageView extends StatelessWidget {
173 } else { 173 } else {
174 return GestureDetector( 174 return GestureDetector(
175 onTap: () { 175 onTap: () {
176 - if(UserUtil.token.isEmpty) { 176 + if (!UserUtil.isLogined()) {
177 pushNamed(AppRouteName.login); 177 pushNamed(AppRouteName.login);
178 return; 178 return;
179 } 179 }
lib/pages/moduleSelect/view.dart
@@ -4,6 +4,8 @@ import &#39;package:wow_english/common/extension/string_extension.dart&#39;; @@ -4,6 +4,8 @@ import &#39;package:wow_english/common/extension/string_extension.dart&#39;;
4 import 'package:wow_english/pages/moduleSelect/state.dart'; 4 import 'package:wow_english/pages/moduleSelect/state.dart';
5 import 'package:wow_english/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart'; 5 import 'package:wow_english/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart';
6 6
  7 +import '../../common/core/user_util.dart';
  8 +import '../../common/dialogs/show_dialog.dart';
7 import 'bloc.dart'; 9 import 'bloc.dart';
8 import 'event.dart'; 10 import 'event.dart';
9 import 'package:flutter_screenutil/flutter_screenutil.dart'; 11 import 'package:flutter_screenutil/flutter_screenutil.dart';
@@ -47,7 +49,11 @@ class _HomePageView extends StatelessWidget { @@ -47,7 +49,11 @@ class _HomePageView extends StatelessWidget {
47 Expanded( 49 Expanded(
48 child: GestureDetector( 50 child: GestureDetector(
49 onTap: () { 51 onTap: () {
50 - pushNamed(AppRouteName.home); 52 + if (UserUtil.isLogined()) {
  53 + pushNamed(AppRouteName.home);
  54 + } else {
  55 + pushNamed(AppRouteName.login);
  56 + }
51 }, 57 },
52 child: Column( 58 child: Column(
53 mainAxisAlignment: MainAxisAlignment.center, 59 mainAxisAlignment: MainAxisAlignment.center,
@@ -74,7 +80,23 @@ class _HomePageView extends StatelessWidget { @@ -74,7 +80,23 @@ class _HomePageView extends StatelessWidget {
74 Expanded( 80 Expanded(
75 child: GestureDetector( 81 child: GestureDetector(
76 onTap: () { 82 onTap: () {
77 - pushNamed(AppRouteName.games); 83 + //如果没登录先登录
  84 + if (UserUtil.isLogined()) {
  85 + if (UserUtil.hasGamePermission()) {
  86 + pushNamed(AppRouteName.games);
  87 + } else {
  88 + showTwoActionDialog(
  89 + '提示', '忽略', '去续费',
  90 + '您的课程已到期,请快快续费继续学习吧!', leftTap: () {
  91 + popPage();
  92 + }, rightTap: () {
  93 + popPage();
  94 + pushNamed(AppRouteName.shop);
  95 + });
  96 + }
  97 + } else {
  98 + pushNamed(AppRouteName.login);
  99 + }
78 }, 100 },
79 child: Column( 101 child: Column(
80 mainAxisAlignment: MainAxisAlignment.center, 102 mainAxisAlignment: MainAxisAlignment.center,
lib/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart
@@ -96,9 +96,9 @@ class BaseHomeHeaderWidget extends StatelessWidget { @@ -96,9 +96,9 @@ class BaseHomeHeaderWidget extends StatelessWidget {
96 } 96 }
97 97
98 void onUserClick() { 98 void onUserClick() {
99 - if (UserUtil.token.isEmpty) {  
100 - pushNamed(AppRouteName.login);  
101 - } else { 99 + if (UserUtil.isLogined()) {
102 pushNamed(AppRouteName.user); 100 pushNamed(AppRouteName.user);
  101 + } else {
  102 + pushNamed(AppRouteName.login);
103 } 103 }
104 } 104 }