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 9 import 'package:wow_english/common/core/user_util.dart';
10 10 import 'package:wow_english/common/extension/string_extension.dart';
11 11 import 'package:wow_english/common/request/config.dart';
  12 +import 'package:wow_english/common/request/dao/user_dao.dart';
12 13 import 'package:wow_english/models/user_entity.dart';
13 14 import 'package:wow_english/route/route.dart';
14 15 import 'package:wow_english/utils/log_util.dart';
... ... @@ -38,23 +39,30 @@ class _TransitionViewState extends State<TransitionView> {
38 39 UserEntity? userEntity = UserUtil.getUser();
39 40 Log.d('当前模式:kDebugMode=$kDebugMode, kProfileMode=$kProfileMode, kReleaseMode=$kReleaseMode');
40 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 46 int apartInMilliseconds = 0;
45 47 // 调一下接口判断一下有效性再往下
46 48 if (userEntity != null) {
  49 + String token = userEntity.token;
47 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 62 apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds;
55 63 }
56   - Log.d('Splash getUserInfo 耗时:${apartInMilliseconds}ms');
57 64 int duration = max(2000 - apartInMilliseconds, 0);
  65 + Log.d('Splash getUserInfo 耗时:${apartInMilliseconds}ms, 最终duration=$duration');
58 66 Timer(Duration(milliseconds: duration), () {
59 67 /*if (userEntity != null) {
60 68 pushNamedAndRemoveUntil(AppRouteName.home, (route) => false);
... ...
lib/common/core/user_util.dart
... ... @@ -2,6 +2,7 @@ import 'dart:convert';
2 2  
3 3 import 'package:flutter/foundation.dart';
4 4 import 'package:flutter/material.dart';
  5 +import 'package:flutter/widgets.dart';
5 6 import 'package:wow_english/common/core/sp_const.dart';
6 7 import 'package:wow_english/models/user_entity.dart';
7 8 import 'package:wow_english/route/route.dart';
... ... @@ -55,6 +56,12 @@ class UserUtil {
55 56  
56 57 static void logout() {
57 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 65 Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(AppRouteName.login, (route) => false);
59 66 }
60 67 }
... ...
lib/common/request/basic_config.dart
1 1 class BasicConfig {
2 2 bool isTestDev = true;
  3 + // bool isTestDev = false;
3 4 }
... ...
lib/common/request/request_client.dart
... ... @@ -3,6 +3,7 @@ import 'dart:convert';
3 3 import 'package:dio/dio.dart';
4 4 import 'package:flutter/foundation.dart';
5 5 import 'package:pretty_dio_logger/pretty_dio_logger.dart';
  6 +import 'package:wow_english/utils/toast_util.dart';
6 7  
7 8 import '../core/user_util.dart';
8 9 import 'api_response/api_response_entity.dart';
... ... @@ -49,6 +50,7 @@ class RequestClient {
49 50 } catch (e) {
50 51 print("e type=${e.runtimeType}");
51 52 if (e is ApiException && e.code == 405) {
  53 + showToast('登录已失效,请重新登录!', duration: const Duration(seconds: 3));
52 54 UserUtil.logout();
53 55 return null;
54 56 }
... ...
lib/models/user_entity.dart
... ... @@ -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 43  
44 44 /// 用户详细信息页
45 45 static const String userInformation = 'userInformation';
  46 +
46 47 /// 修改用户头像
47 48 static const String userAvatar = 'userAvatar';
48 49  
... ... @@ -50,12 +51,13 @@ class AppRouteName {
50 51 //static const String userModifyInformation = 'userModifyInformation';
51 52 ///看视频
52 53 static const String lookVideo = 'lookVideo';
  54 +
53 55 ///绘本
54 56 static const String reading = 'reading';
  57 +
55 58 ///视频跟读详情
56 59 static const String readAfterContent = 'readAfterContent';
57 60  
58   -
59 61 static const String tab = '/';
60 62 }
61 63  
... ... @@ -82,8 +84,8 @@ class AppRouter {
82 84 }
83 85 return CupertinoPageRoute(
84 86 builder: (_) => HomePage(
85   - moduleId: moduleId,
86   - ));
  87 + moduleId: moduleId,
  88 + ));
87 89 case AppRouteName.fogPwd:
88 90 return CupertinoPageRoute(builder: (_) => const ForgetPasswordHomePage());
89 91 case AppRouteName.lesson:
... ... @@ -105,11 +107,14 @@ class AppRouter {
105 107 case AppRouteName.userAvatar:
106 108 var pageType = 0;
107 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 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 118 return CupertinoPageRoute(builder: (_) {
114 119 ModifyUserInformationType argument = ModifyUserInformationType.name;
115 120 if (settings.arguments != null) {
... ... @@ -120,18 +125,18 @@ class AppRouter {
120 125 case AppRouteName.topicPic:
121 126 var courseLessonId = '';
122 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 131 case AppRouteName.lookVideo:
127 132 final videoUrl = (settings.arguments as Map)['videoUrl'] as String;
128 133 final title = (settings.arguments as Map)['title'] as String?;
129 134 return CupertinoPageRoute(
130 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 140 case AppRouteName.setPwd:
136 141 phoneNum: phoneNum,
137 142 smsCode: smsCode,
... ... @@ -142,16 +147,15 @@ class AppRouter {
142 147 final webViewTitle = (settings.arguments as Map)['webViewTitle'] as String;
143 148 return CupertinoPageRoute(
144 149 builder: (_) => WowWebViewPage(
145   - urlStr: urlStr,
146   - webViewTitle: webViewTitle,
147   - ));
  150 + urlStr: urlStr,
  151 + webViewTitle: webViewTitle,
  152 + ));
148 153 case AppRouteName.readAfterContent:
149 154 var videoFollowReadId = '';
150 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 159 case AppRouteName.tab:
156 160 return PageRouteBuilder(
157 161 opaque: false,
... ... @@ -162,7 +166,7 @@ class AppRouter {
162 166 case AppRouteName.reading:
163 167 var courseLessonId = '';
164 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 171 return CupertinoPageRoute(builder: (_) => ReadingPage(courseLessonId: courseLessonId));
168 172 default:
... ... @@ -173,11 +177,11 @@ class AppRouter {
173 177 }
174 178  
175 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 187 void popPage() {
... ...
lib/utils/aliyun_oss_util.dart
... ... @@ -37,7 +37,7 @@ class AliyunOssUtil {
37 37 onReceiveProgress: (count, total) {
38 38 Log.d("receive: count = $count, and total = $total");
39 39 },
40   - aclModel: AclMode.private,
  40 + aclModel: AclMode.publicRead,
41 41 callback: Callback(
42 42 callbackUrl: stsEntity.callbackParam.callbackUrl,
43 43 callbackBody: stsEntity.callbackParam.callbackBody,
... ...