Commit e55bbdf3e9c2e15793aadb445e46b0db70c336d2

Authored by Key
1 parent 20345cbf

fixed: aliyun oss private->public read

fixed: login refresh user info
lib/app/splash_page.dart
@@ -9,6 +9,7 @@ import 'package:limiting_direction_csx/limiting_direction_csx.dart'; @@ -9,6 +9,7 @@ import 'package:limiting_direction_csx/limiting_direction_csx.dart';
9 import 'package:wow_english/common/core/user_util.dart'; 9 import 'package:wow_english/common/core/user_util.dart';
10 import 'package:wow_english/common/extension/string_extension.dart'; 10 import 'package:wow_english/common/extension/string_extension.dart';
11 import 'package:wow_english/common/request/config.dart'; 11 import 'package:wow_english/common/request/config.dart';
  12 +import 'package:wow_english/common/request/dao/user_dao.dart';
12 import 'package:wow_english/models/user_entity.dart'; 13 import 'package:wow_english/models/user_entity.dart';
13 import 'package:wow_english/route/route.dart'; 14 import 'package:wow_english/route/route.dart';
14 import 'package:wow_english/utils/log_util.dart'; 15 import 'package:wow_english/utils/log_util.dart';
@@ -38,23 +39,30 @@ class _TransitionViewState extends State<TransitionView> { @@ -38,23 +39,30 @@ class _TransitionViewState extends State<TransitionView> {
38 UserEntity? userEntity = UserUtil.getUser(); 39 UserEntity? userEntity = UserUtil.getUser();
39 Log.d('当前模式:kDebugMode=$kDebugMode, kProfileMode=$kProfileMode, kReleaseMode=$kReleaseMode'); 40 Log.d('当前模式:kDebugMode=$kDebugMode, kProfileMode=$kProfileMode, kReleaseMode=$kReleaseMode');
40 Log.d('当前API地址:${RequestConfig.baseUrl}'); 41 Log.d('当前API地址:${RequestConfig.baseUrl}');
41 - if (kDebugMode) {  
42 - Log.d('Splash读本地userEntity: $userEntity');  
43 - } 42 + //BuildContext context = Navigator.of(context).context;
  43 + //var currentPageName = ModalRoute.of(Navigator.of(AppRouter.context))?.settings.name;
  44 + //Log.d('Splash读当前页面:$currentPageName');
  45 + Log.d('Splash读本地, userEntity: $userEntity');
44 int apartInMilliseconds = 0; 46 int apartInMilliseconds = 0;
45 // 调一下接口判断一下有效性再往下 47 // 调一下接口判断一下有效性再往下
46 if (userEntity != null) { 48 if (userEntity != null) {
  49 + String token = userEntity.token;
47 DateTime startTime = DateTime.now(); 50 DateTime startTime = DateTime.now();
48 - // try {  
49 - // userEntity = await UserDao.getUserInfo();  
50 - // UserUtil.saveUser(userEntity);  
51 - // } catch (e) {  
52 - // e.logE();  
53 - // } 51 + try {
  52 + userEntity = await UserDao.getUserInfo();
  53 + Log.d('Splash在线更新, userEntity: $userEntity');
  54 + if (userEntity != null) {
  55 + userEntity.token = token;
  56 + Log.d('Splash重设token, userEntity: $userEntity');
  57 + UserUtil.saveUser(userEntity);
  58 + }
  59 + } catch (e) {
  60 + e.logE();
  61 + }
54 apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds; 62 apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds;
55 } 63 }
56 - Log.d('Splash getUserInfo 耗时:${apartInMilliseconds}ms');  
57 int duration = max(2000 - apartInMilliseconds, 0); 64 int duration = max(2000 - apartInMilliseconds, 0);
  65 + Log.d('Splash getUserInfo 耗时:${apartInMilliseconds}ms, 最终duration=$duration');
58 Timer(Duration(milliseconds: duration), () { 66 Timer(Duration(milliseconds: duration), () {
59 /*if (userEntity != null) { 67 /*if (userEntity != null) {
60 pushNamedAndRemoveUntil(AppRouteName.home, (route) => false); 68 pushNamedAndRemoveUntil(AppRouteName.home, (route) => false);
lib/common/core/user_util.dart
@@ -2,6 +2,7 @@ import 'dart:convert'; @@ -2,6 +2,7 @@ import 'dart:convert';
2 2
3 import 'package:flutter/foundation.dart'; 3 import 'package:flutter/foundation.dart';
4 import 'package:flutter/material.dart'; 4 import 'package:flutter/material.dart';
  5 +import 'package:flutter/widgets.dart';
5 import 'package:wow_english/common/core/sp_const.dart'; 6 import 'package:wow_english/common/core/sp_const.dart';
6 import 'package:wow_english/models/user_entity.dart'; 7 import 'package:wow_english/models/user_entity.dart';
7 import 'package:wow_english/route/route.dart'; 8 import 'package:wow_english/route/route.dart';
@@ -55,6 +56,12 @@ class UserUtil { @@ -55,6 +56,12 @@ class UserUtil {
55 56
56 static void logout() { 57 static void logout() {
57 _clearUserData(); 58 _clearUserData();
  59 + // 判断下不在Splash页就跳转
  60 + /*var currentPageName = ModalRoute.of(AppRouter.context)?.settings.name;
  61 + Log.d('当前页面:$currentPageName');
  62 + if (currentPageName != AppRouteName.splash) {
  63 + Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(AppRouteName.login, (route) => false);
  64 + }*/
58 Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(AppRouteName.login, (route) => false); 65 Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(AppRouteName.login, (route) => false);
59 } 66 }
60 } 67 }
lib/common/request/basic_config.dart
1 class BasicConfig { 1 class BasicConfig {
2 bool isTestDev = true; 2 bool isTestDev = true;
  3 + // bool isTestDev = false;
3 } 4 }
lib/common/request/request_client.dart
@@ -3,6 +3,7 @@ import 'dart:convert'; @@ -3,6 +3,7 @@ import 'dart:convert';
3 import 'package:dio/dio.dart'; 3 import 'package:dio/dio.dart';
4 import 'package:flutter/foundation.dart'; 4 import 'package:flutter/foundation.dart';
5 import 'package:pretty_dio_logger/pretty_dio_logger.dart'; 5 import 'package:pretty_dio_logger/pretty_dio_logger.dart';
  6 +import 'package:wow_english/utils/toast_util.dart';
6 7
7 import '../core/user_util.dart'; 8 import '../core/user_util.dart';
8 import 'api_response/api_response_entity.dart'; 9 import 'api_response/api_response_entity.dart';
@@ -49,6 +50,7 @@ class RequestClient { @@ -49,6 +50,7 @@ class RequestClient {
49 } catch (e) { 50 } catch (e) {
50 print("e type=${e.runtimeType}"); 51 print("e type=${e.runtimeType}");
51 if (e is ApiException && e.code == 405) { 52 if (e is ApiException && e.code == 405) {
  53 + showToast('登录已失效,请重新登录!', duration: const Duration(seconds: 3));
52 UserUtil.logout(); 54 UserUtil.logout();
53 return null; 55 return null;
54 } 56 }
lib/models/user_entity.dart
@@ -56,4 +56,29 @@ class UserEntity { @@ -56,4 +56,29 @@ class UserEntity {
56 ? '男' 56 ? '男'
57 : '女'; 57 : '女';
58 } 58 }
  59 +
  60 + UserEntity copyWith({
  61 + int? id,
  62 + String? name,
  63 + String? token,
  64 + int? age,
  65 + int? gender,
  66 + String? avatarUrl,
  67 + String? phoneNum,
  68 + int? fillUserInfo,
  69 + int? nowCourseModuleId,
  70 + String? effectiveDate,
  71 + }) {
  72 + return UserEntity()
  73 + ..id = id ?? this.id
  74 + ..name = name ?? this.name
  75 + ..token = token ?? this.token
  76 + ..age = age ?? this.age
  77 + ..gender = gender ?? this.gender
  78 + ..avatarUrl = avatarUrl ?? this.avatarUrl
  79 + ..phoneNum = phoneNum ?? this.phoneNum
  80 + ..fillUserInfo = fillUserInfo ?? this.fillUserInfo
  81 + ..nowCourseModuleId = nowCourseModuleId ?? this.nowCourseModuleId
  82 + ..effectiveDate = effectiveDate ?? this.effectiveDate;
  83 + }
59 } 84 }
lib/route/route.dart
@@ -43,6 +43,7 @@ class AppRouteName { @@ -43,6 +43,7 @@ class AppRouteName {
43 43
44 /// 用户详细信息页 44 /// 用户详细信息页
45 static const String userInformation = 'userInformation'; 45 static const String userInformation = 'userInformation';
  46 +
46 /// 修改用户头像 47 /// 修改用户头像
47 static const String userAvatar = 'userAvatar'; 48 static const String userAvatar = 'userAvatar';
48 49
@@ -50,12 +51,13 @@ class AppRouteName { @@ -50,12 +51,13 @@ class AppRouteName {
50 //static const String userModifyInformation = 'userModifyInformation'; 51 //static const String userModifyInformation = 'userModifyInformation';
51 ///看视频 52 ///看视频
52 static const String lookVideo = 'lookVideo'; 53 static const String lookVideo = 'lookVideo';
  54 +
53 ///绘本 55 ///绘本
54 static const String reading = 'reading'; 56 static const String reading = 'reading';
  57 +
55 ///视频跟读详情 58 ///视频跟读详情
56 static const String readAfterContent = 'readAfterContent'; 59 static const String readAfterContent = 'readAfterContent';
57 60
58 -  
59 static const String tab = '/'; 61 static const String tab = '/';
60 } 62 }
61 63
@@ -82,8 +84,8 @@ class AppRouter { @@ -82,8 +84,8 @@ class AppRouter {
82 } 84 }
83 return CupertinoPageRoute( 85 return CupertinoPageRoute(
84 builder: (_) => HomePage( 86 builder: (_) => HomePage(
85 - moduleId: moduleId,  
86 - )); 87 + moduleId: moduleId,
  88 + ));
87 case AppRouteName.fogPwd: 89 case AppRouteName.fogPwd:
88 return CupertinoPageRoute(builder: (_) => const ForgetPasswordHomePage()); 90 return CupertinoPageRoute(builder: (_) => const ForgetPasswordHomePage());
89 case AppRouteName.lesson: 91 case AppRouteName.lesson:
@@ -105,11 +107,14 @@ class AppRouter { @@ -105,11 +107,14 @@ class AppRouter {
105 case AppRouteName.userAvatar: 107 case AppRouteName.userAvatar:
106 var pageType = 0; 108 var pageType = 0;
107 if (settings.arguments != null) { 109 if (settings.arguments != null) {
108 - final content = (settings.arguments as Map)['pageType'] as String??'0'; 110 + final content = (settings.arguments as Map)['pageType'] as String ?? '0';
109 pageType = int.parse(content); 111 pageType = int.parse(content);
110 } 112 }
111 - return CupertinoPageRoute(builder: (_) => ModifyUserAvatarPage(pageType: pageType,));  
112 - /*case AppRouteName.userModifyInformation: 113 + return CupertinoPageRoute(
  114 + builder: (_) => ModifyUserAvatarPage(
  115 + pageType: pageType,
  116 + ));
  117 + /*case AppRouteName.userModifyInformation:
113 return CupertinoPageRoute(builder: (_) { 118 return CupertinoPageRoute(builder: (_) {
114 ModifyUserInformationType argument = ModifyUserInformationType.name; 119 ModifyUserInformationType argument = ModifyUserInformationType.name;
115 if (settings.arguments != null) { 120 if (settings.arguments != null) {
@@ -120,18 +125,18 @@ class AppRouter { @@ -120,18 +125,18 @@ class AppRouter {
120 case AppRouteName.topicPic: 125 case AppRouteName.topicPic:
121 var courseLessonId = ''; 126 var courseLessonId = '';
122 if (settings.arguments != null) { 127 if (settings.arguments != null) {
123 - courseLessonId = (settings.arguments as Map)['courseLessonId'] as String??''; 128 + courseLessonId = (settings.arguments as Map)['courseLessonId'] as String ?? '';
124 } 129 }
125 - return CupertinoPageRoute(builder: (_) => TopicPicturePage(courseLessonId: courseLessonId)); 130 + return CupertinoPageRoute(builder: (_) => TopicPicturePage(courseLessonId: courseLessonId));
126 case AppRouteName.lookVideo: 131 case AppRouteName.lookVideo:
127 final videoUrl = (settings.arguments as Map)['videoUrl'] as String; 132 final videoUrl = (settings.arguments as Map)['videoUrl'] as String;
128 final title = (settings.arguments as Map)['title'] as String?; 133 final title = (settings.arguments as Map)['title'] as String?;
129 return CupertinoPageRoute( 134 return CupertinoPageRoute(
130 builder: (_) => LookVideoPage( 135 builder: (_) => LookVideoPage(
131 - videoUrl: videoUrl,  
132 - typeTitle: title,  
133 - ));  
134 - /*case AppRouteName.setPwd: 136 + videoUrl: videoUrl,
  137 + typeTitle: title,
  138 + ));
  139 + /*case AppRouteName.setPwd:
135 case AppRouteName.setPwd: 140 case AppRouteName.setPwd:
136 phoneNum: phoneNum, 141 phoneNum: phoneNum,
137 smsCode: smsCode, 142 smsCode: smsCode,
@@ -142,16 +147,15 @@ class AppRouter { @@ -142,16 +147,15 @@ class AppRouter {
142 final webViewTitle = (settings.arguments as Map)['webViewTitle'] as String; 147 final webViewTitle = (settings.arguments as Map)['webViewTitle'] as String;
143 return CupertinoPageRoute( 148 return CupertinoPageRoute(
144 builder: (_) => WowWebViewPage( 149 builder: (_) => WowWebViewPage(
145 - urlStr: urlStr,  
146 - webViewTitle: webViewTitle,  
147 - )); 150 + urlStr: urlStr,
  151 + webViewTitle: webViewTitle,
  152 + ));
148 case AppRouteName.readAfterContent: 153 case AppRouteName.readAfterContent:
149 var videoFollowReadId = ''; 154 var videoFollowReadId = '';
150 if (settings.arguments != null) { 155 if (settings.arguments != null) {
151 - videoFollowReadId = (settings.arguments as Map)['videoFollowReadId'] as String??''; 156 + videoFollowReadId = (settings.arguments as Map)['videoFollowReadId'] as String ?? '';
152 } 157 }
153 - return CupertinoPageRoute(  
154 - builder: (_) => RepeatAfterContentPage(videoFollowReadId:videoFollowReadId)); 158 + return CupertinoPageRoute(builder: (_) => RepeatAfterContentPage(videoFollowReadId: videoFollowReadId));
155 case AppRouteName.tab: 159 case AppRouteName.tab:
156 return PageRouteBuilder( 160 return PageRouteBuilder(
157 opaque: false, 161 opaque: false,
@@ -162,7 +166,7 @@ class AppRouter { @@ -162,7 +166,7 @@ class AppRouter {
162 case AppRouteName.reading: 166 case AppRouteName.reading:
163 var courseLessonId = ''; 167 var courseLessonId = '';
164 if (settings.arguments != null) { 168 if (settings.arguments != null) {
165 - courseLessonId = (settings.arguments as Map)['courseLessonId'] as String??''; 169 + courseLessonId = (settings.arguments as Map)['courseLessonId'] as String ?? '';
166 } 170 }
167 return CupertinoPageRoute(builder: (_) => ReadingPage(courseLessonId: courseLessonId)); 171 return CupertinoPageRoute(builder: (_) => ReadingPage(courseLessonId: courseLessonId));
168 default: 172 default:
@@ -173,11 +177,11 @@ class AppRouter { @@ -173,11 +177,11 @@ class AppRouter {
173 } 177 }
174 178
175 void pushNamed(String routeName, {Object? arguments}) { 179 void pushNamed(String routeName, {Object? arguments}) {
176 - Navigator.of(AppRouter.context).pushNamed(routeName,arguments: arguments); 180 + Navigator.of(AppRouter.context).pushNamed(routeName, arguments: arguments);
177 } 181 }
178 182
179 -void pushNamedAndRemoveUntil(String routeName,RoutePredicate predicate, {Object? arguments}) {  
180 - Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(routeName, predicate,arguments: arguments); 183 +void pushNamedAndRemoveUntil(String routeName, RoutePredicate predicate, {Object? arguments}) {
  184 + Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(routeName, predicate, arguments: arguments);
181 } 185 }
182 186
183 void popPage() { 187 void popPage() {
lib/utils/aliyun_oss_util.dart
@@ -37,7 +37,7 @@ class AliyunOssUtil { @@ -37,7 +37,7 @@ class AliyunOssUtil {
37 onReceiveProgress: (count, total) { 37 onReceiveProgress: (count, total) {
38 Log.d("receive: count = $count, and total = $total"); 38 Log.d("receive: count = $count, and total = $total");
39 }, 39 },
40 - aclModel: AclMode.private, 40 + aclModel: AclMode.publicRead,
41 callback: Callback( 41 callback: Callback(
42 callbackUrl: stsEntity.callbackParam.callbackUrl, 42 callbackUrl: stsEntity.callbackParam.callbackUrl,
43 callbackBody: stsEntity.callbackParam.callbackBody, 43 callbackBody: stsEntity.callbackParam.callbackBody,