Commit f8c19f9e 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 == -4) {
// 用户主动取消
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();
......
......@@ -235,6 +235,126 @@ class LoginQrPageV3 extends StatelessWidget {
color: Color(0xFF333333),
),
),
SizedBox(height: 20),
InkWell(
onTap: () {
loginQrCubit.refresh();
},
borderRadius: BorderRadius.circular(25),
child: Container(
width: 200,
height: 50,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFF7691FA),
borderRadius: BorderRadius.circular(25),
),
child: Text(
'重新登录',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
height: 1.0,
color: Color(0xFFFFFFFF),
),
),
),
),
],
);
} 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),
),
),
],
);
}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!