Commit bb902091 by tanghuan

学习机登录界面调整

1 parent 34e1546b
......@@ -120,11 +120,18 @@ class LoginQrCubit extends Cubit<LoginQrState> {
int? errCode = response.errCode;
if (errCode != null && errCode == 0) {
_doLogin(response.authCode!);
} else {
} else if (errCode == -2) {
// 用户主动取消
emit(state.copyWith(
status: 3,
tip: '你已取消此次登录',
));
} else {
// 其它非 0 错误码(含二维码过期/超时/网络异常等),引导用户刷新
emit(state.copyWith(
status: 4,
tip: '请刷新二维码,再次登录',
));
}
}
}
......@@ -247,6 +254,22 @@ class LoginQrCubit extends Cubit<LoginQrState> {
router.go('/loginMain');
}
void goLoginPhone() {
router.go('/loginPhone');
}
/// 刷新二维码:停止当前授权流程并重新走 init() 生成新的二维码
Future<void> refresh() async {
// 重置为加载中状态(tip 与初次进入区分,避免 Equatable 短路掉相同 state 的 emit)
emit(const LoginQrState(status: 0, tip: '正在重新生成二维码...'));
try {
_fluwx.stopAuthByQRCode();
} catch (e) {
debugPrint('stopAuthByQRCode error: $e');
}
await init();
}
@override
Future<void> close() {
_fluwxCancelable.cancel();
......
......@@ -21,7 +21,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
final GoRouter router = GoRouter(
initialLocation: '/web',
initialLocation: '/loginQr',
observers: Platform.isIOS ? [LinkPageObserver(), IosGestureObserver()] : [LinkPageObserver()],
routes: <RouteBase>[
GoRoute(
......
......@@ -239,6 +239,50 @@ class LoginQrPage extends StatelessWidget {
),
],
);
} else if (state.status == 4) {
// 二维码过期,提示点击刷新
return Column(
children: [
SizedBox(height: 15.5),
Image.asset(
"assets/images/login_v2/refused.png",
width: 217,
height: 190,
),
SizedBox(height: 15.5),
Text(
"二维码已过期",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
fontFamily: '黑体',
color: Color(0xFF333333),
),
strutStyle: StrutStyle(height: 21 / 16),
),
SizedBox(height: 8),
InkWell(
onTap: () {
loginQrCubit.refresh();
},
borderRadius: BorderRadius.circular(4),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
child: Text(
'点击刷新',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
color: Color(0xFF7691FA),
decoration: TextDecoration.underline,
decorationColor: Color(0xFF7691FA),
),
strutStyle: StrutStyle(height: 16 / 14),
),
),
),
],
);
}
return null;
}
......
......@@ -87,15 +87,6 @@ class LoginPhonePageV3 extends StatelessWidget {
children: [
InkWell(
onTap: () {
context.read<LoginPhoneCubit>().goLoginMain();
},
child: Image.asset(
'assets/images/login_v3/wechat.png',
),
),
SizedBox(width: 25),
InkWell(
onTap: () {
context.read<LoginPhoneCubit>().goLoginQr();
},
child: Image.asset(
......
......@@ -73,10 +73,10 @@ class LoginQrPageV3 extends StatelessWidget {
children: [
InkWell(
onTap: () {
context.read<LoginQrCubit>().goLoginMain();
context.read<LoginQrCubit>().goLoginPhone();
},
child: Image.asset(
'assets/images/login_v3/wechat.png',
'assets/images/login_v3/phone.png',
),
),
],
......@@ -237,6 +237,101 @@ class LoginQrPageV3 extends StatelessWidget {
),
],
);
} else if (state.status == 4) {
// 二维码过期,提示点击刷新
return Column(
children: [
Container(
width: 230,
height: 230,
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
border: Border.all(
color: Color(0x29265ECF),
width: 0.5,
),
borderRadius: BorderRadius.circular(20),
),
child: Stack(
alignment: Alignment.center,
children: [
Image.memory(
state.image!,
width: 190,
height: 190,
),
Container(
width: 190,
height: 190,
color: Color(0xFF000000).withOpacity(0.5),
alignment: Alignment.center,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'二维码已过期',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
height: 1.0,
fontWeight: FontWeight.bold,
fontFamily: '黑体',
color: Color(0xFFFFFFFF),
),
),
SizedBox(height: 12),
InkWell(
onTap: () {
loginQrCubit.refresh();
},
borderRadius: BorderRadius.circular(22),
child: Container(
height: 44,
width: 129,
padding: EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFF7691FA),
borderRadius: BorderRadius.circular(22),
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/login_v3/refresh_icon.png',
),
SizedBox(width: 4),
Text(
'点击刷新',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
height: 1.0,
color: Colors.white,
),
),
],
),
),
),
],
),
),
],
),
),
SizedBox(height: 15),
Text(
state.tip,
style: TextStyle(
fontSize: 14,
height: 1.0,
color: Color(0xFF333333),
),
),
],
);
}
return null;
}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!