Commit a4d8eaa2176819ff86c6929727eeb4c6d7c5ecbe

Authored by Key
1 parent fc75f209

feat: 登录时账户有效性校验

android/app/src/main/AndroidManifest.xml
1 1 <manifest xmlns:tools="http://schemas.android.com/tools"
2 2 xmlns:android="http://schemas.android.com/apk/res/android">
3 3 <application
4   - android:label="wow_english"
  4 + android:label="Wow English"
5 5 android:name="${applicationName}"
6 6 android:icon="@mipmap/ic_launcher"
7 7 android:usesCleartextTraffic="true">
... ...
android/app/src/main/res/mipmap-hdpi/ic_launcher.png

544 Bytes | W: | H:

11.1 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
android/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted

442 Bytes

android/app/src/main/res/mipmap-xhdpi/ic_launcher.png deleted

721 Bytes

android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png

1.01 KB | W: | H:

17.9 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

1.41 KB | W: | H:

34.7 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
lib/app/splash_page.dart
1 1 import 'dart:async';
2 2 import 'dart:io';
  3 +import 'dart:math';
3 4  
4 5 import 'package:flutter/foundation.dart';
5 6 import 'package:flutter/material.dart';
  7 +import 'package:flutter/services.dart';
  8 +import 'package:limiting_direction_csx/limiting_direction_csx.dart';
6 9 import 'package:wow_english/common/core/user_util.dart';
7 10 import 'package:wow_english/common/extension/string_extension.dart';
  11 +import 'package:wow_english/common/request/config.dart';
  12 +import 'package:wow_english/common/request/dao/user_dao.dart';
8 13 import 'package:wow_english/models/user_entity.dart';
9 14 import 'package:wow_english/route/route.dart';
  15 +import 'package:wow_english/utils/log_util.dart';
10 16 import 'package:wow_english/utils/sp_util.dart';
11   -import 'package:flutter/services.dart';
12   -import 'package:limiting_direction_csx/limiting_direction_csx.dart';
13 17  
14 18 class SplashPage extends StatelessWidget {
15 19 const SplashPage({super.key});
... ... @@ -33,12 +37,27 @@ class _TransitionViewState extends State&lt;TransitionView&gt; {
33 37 Future startTime() async {
34 38 // 判断是否登录
35 39 UserEntity? userEntity = UserUtil.getUser();
  40 + Log.d('当前模式:kDebugMode=$kDebugMode, kProfileMode=$kProfileMode, kReleaseMode=$kReleaseMode');
  41 + Log.d('当前API地址:${RequestConfig.baseUrl}');
36 42 if (kDebugMode) {
37   - print('Splash读本地userEntity: $userEntity');
  43 + Log.d('Splash读本地userEntity: $userEntity');
  44 + }
  45 + int apartInMilliseconds = 0;
  46 + // 调一下接口判断一下有效性再往下
  47 + if (userEntity != null) {
  48 + DateTime startTime = DateTime.now();
  49 + try {
  50 + userEntity = await UserDao.getUserInfo();
  51 + UserUtil.saveUser(userEntity);
  52 + } catch (e) {
  53 + e.logE();
  54 + }
  55 + apartInMilliseconds = DateTime.now().difference(startTime).inMilliseconds;
38 56 }
39   - Timer(const Duration(seconds: 2), () {
  57 + Log.d('Splash getUserInfo 耗时:${apartInMilliseconds}ms');
  58 + int duration = max(2000 - apartInMilliseconds, 0);
  59 + Timer(Duration(milliseconds: duration), () {
40 60 if (userEntity != null) {
41   - // todo 调一下接口判断一下有效性再往下
42 61 pushNamedAndRemoveUntil(AppRouteName.home, (route) => false);
43 62 } else {
44 63 pushNamedAndRemoveUntil(AppRouteName.login, (route) => false);
... ... @@ -64,7 +83,7 @@ class _TransitionViewState extends State&lt;TransitionView&gt; {
64 83 if (Platform.isIOS) {
65 84 await LimitingDirectionCsx.setScreenDirection(DeviceDirectionMask.Landscape);
66 85 } else {
67   - await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);
  86 + await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
68 87 }
69 88 }
70 89  
... ...
lib/common/core/user_util.dart
... ... @@ -12,7 +12,11 @@ class UserUtil {
12 12  
13 13 static String get token => _userEntity?.token ?? '';
14 14  
15   - static void saveUser(UserEntity user) {
  15 + static void saveUser(UserEntity? user) {
  16 + if (user == null) {
  17 + _clearUserData();
  18 + return;
  19 + }
16 20 _userEntity = user;
17 21 _saveUserJson(user.toString());
18 22 }
... ...
lib/common/request/apis.dart
... ... @@ -2,8 +2,8 @@ part of &#39;request_client.dart&#39;;
2 2  
3 3 class Apis {
4 4 /// app初始化配置信息
5   - // GET /system/app/config
6   - // 接口地址:https://app.apifox.com/link/project/2684751/apis/api-89897678
  5 + /// GET /system/app/config
  6 + /// 接口地址:https://app.apifox.com/link/project/2684751/apis/api-89897678
7 7 static const String appConfig = 'system/app/config';
8 8  
9 9 /// 登录
... ... @@ -12,7 +12,11 @@ class Apis {
12 12 /// 登出
13 13 static const String logout = 'logout';
14 14  
  15 + /// 注销账号
  16 + static const String deleteAccount = 'logout';
  17 +
15 18 /// 获取用户信息
  19 + /// get
16 20 static const String getUserInfo = 'student/info';
17 21  
18 22 /// 更新用户信息
... ... @@ -62,4 +66,8 @@ class Apis {
62 66 /// 获取课程内容
63 67 /// GET
64 68 static const String process = '/course/process';
  69 +
  70 + /// 首页弹窗
  71 + /// get
  72 + static const String homePopup = 'home/popup';
65 73 }
... ...
lib/common/request/dao/user_dao.dart
... ... @@ -23,7 +23,13 @@ class UserDao {
23 23 /// 登出
24 24 static Future logout() async {
25 25 var result = await requestClient.post(Apis.logout);
26   - print('logout result=$result');
  26 + UserUtil.logout();
  27 + return result;
  28 + }
  29 +
  30 + /// 注销账号
  31 + static Future deleteAccount() async {
  32 + var result = await requestClient.post(Apis.deleteAccount);
27 33 UserUtil.logout();
28 34 return result;
29 35 }
... ... @@ -69,7 +75,7 @@ class UserDao {
69 75  
70 76 /// 获取用户信息
71 77 static Future<UserEntity?> getUserInfo() async {
72   - return await requestClient.post(Apis.getUserInfo);
  78 + return await requestClient.get(Apis.getUserInfo);
73 79 }
74 80  
75 81 /// 更新用户信息,返回即成功,无body
... ...
lib/pages/user/bloc/user_bloc.dart
... ... @@ -15,6 +15,7 @@ class UserBloc extends Bloc&lt;UserEvent, UserState&gt; {
15 15  
16 16 UserBloc() : super(UserInitial()) {
17 17 on<UserLogout>(_logout);
  18 + on<UserDelete>(_deleteAccount);
18 19 on<UserUpdate>(_updateUser);
19 20 on<UserUIUpdate>(_updateUIUser);
20 21 }
... ... @@ -23,6 +24,10 @@ class UserBloc extends Bloc&lt;UserEvent, UserState&gt; {
23 24 await UserDao.logout();
24 25 }
25 26  
  27 + void _deleteAccount(UserDelete event, Emitter<UserState> emitter) async {
  28 + await UserDao.deleteAccount();
  29 + }
  30 +
26 31 void _updateUIUser(UserUIUpdate event, Emitter<UserState> emitter) async {
27 32 emitter(UserInfoUpdated());
28 33 }
... ...
lib/pages/user/bloc/user_event.dart
... ... @@ -4,8 +4,12 @@ sealed class UserEvent {}
4 4  
5 5 class UserStarted extends UserEvent {}
6 6  
  7 +/// 退出账号
7 8 class UserLogout extends UserEvent {}
8 9  
  10 +/// 注销账号
  11 +class UserDelete extends UserEvent {}
  12 +
9 13 class UserUpdate extends UserEvent {
10 14 final ModifyUserInformationType type;
11 15  
... ...
lib/pages/user/user_page.dart
... ... @@ -189,6 +189,17 @@ class _UserView extends StatelessWidget {
189 189 fontSize: 17.sp,
190 190 ),
191 191 )),
  192 + 30.verticalSpace,
  193 + TextButton(
  194 + onPressed: () => userBloc.add(UserDelete()),
  195 + child: Text(
  196 + "注销账号",
  197 + style: TextStyle(
  198 + //fontWeight: FontWeight.w600,
  199 + color: Colors.red,
  200 + fontSize: 15.sp,
  201 + ),
  202 + )),
192 203 ],
193 204 ),
194 205 ));
... ...
lib/utils/log_util.dart
... ... @@ -4,51 +4,55 @@ class Log {
4 4 static LogLevel level = LogLevel.debug;
5 5  
6 6 /// debug
7   - static void d(String message) {
  7 + static void d(Object? object) {
8 8 if (level.index <= LogLevel.debug.index) {
9   - print(message);
  9 + String line = "$object";
  10 + print(line);
10 11 }
11 12 }
12 13  
13 14 /// info
14   - static void i(String message) {
  15 + static void i(Object? object) {
15 16 if (level.index <= LogLevel.info.index) {
16   - print(message);
  17 + String line = "$object";
  18 + print(line);
17 19 }
18 20 }
19 21  
20 22 /// warning
21   - static void w(String message) {
  23 + static void w(Object? object) {
22 24 if (level.index <= LogLevel.warning.index) {
23   - print(message);
  25 + String line = "$object";
  26 + print(line);
24 27 }
25 28 }
26 29  
27 30 /// error
28   - static void e(String message) {
  31 + static void e(Object? object) {
29 32 if (level.index <= LogLevel.error.index) {
30   - print(message);
  33 + String line = "$object";
  34 + print(line);
31 35 }
32 36 }
33 37 }
34 38  
35   -extension LogExtension on String {
36   - String logD() {
  39 +extension LogExtension on Object? {
  40 + Object? logD() {
37 41 Log.d(this);
38 42 return this;
39 43 }
40 44  
41   - String logI() {
  45 + Object? logI() {
42 46 Log.i(this);
43 47 return this;
44 48 }
45 49  
46   - String logW() {
  50 + Object? logW() {
47 51 Log.w(this);
48 52 return this;
49 53 }
50 54  
51   - String logE() {
  55 + Object? logE() {
52 56 Log.e(this);
53 57 return this;
54 58 }
... ...