From cdb55ec4cbb4b329b896f3406d372513671cb57c Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 20 Dec 2025 17:40:09 -0800 Subject: [PATCH] =?UTF-8?q?fix(mobile-app):=20=E4=BF=AE=E5=A4=8D=E7=9F=AD?= =?UTF-8?q?=E4=BF=A1=E9=AA=8C=E8=AF=81=E7=A0=81=E7=95=8C=E9=9D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 减小验证码输入框字体大小从 24.sp 到 20.sp,防止在某些设备上被截断 - 添加行高 height: 1.2 确保文字垂直居中 - 在手机号注册页面添加 60 秒倒计时功能 - 倒计时期间禁用获取验证码按钮 - 显示剩余秒数提示 "X秒后重新发送" --- .../pages/phone_register_page.dart | 37 +++++++++++++++++-- .../presentation/pages/sms_verify_page.dart | 3 +- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/frontend/mobile-app/lib/features/auth/presentation/pages/phone_register_page.dart b/frontend/mobile-app/lib/features/auth/presentation/pages/phone_register_page.dart index 234650e4..e76c0422 100644 --- a/frontend/mobile-app/lib/features/auth/presentation/pages/phone_register_page.dart +++ b/frontend/mobile-app/lib/features/auth/presentation/pages/phone_register_page.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -35,6 +36,11 @@ class _PhoneRegisterPageState extends ConsumerState { bool _isSending = false; String? _errorMessage; + // 倒计时 + int _countdown = 0; + Timer? _countdownTimer; + bool _canSend = true; + @override void initState() { super.initState(); @@ -44,12 +50,31 @@ class _PhoneRegisterPageState extends ConsumerState { @override void dispose() { + _countdownTimer?.cancel(); _phoneController.removeListener(_onPhoneChanged); _phoneController.dispose(); _phoneFocusNode.dispose(); super.dispose(); } + void _startCountdown() { + _countdown = 60; + _canSend = false; + _countdownTimer?.cancel(); + _countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) { + if (_countdown > 0) { + setState(() { + _countdown--; + }); + } else { + setState(() { + _canSend = true; + }); + timer.cancel(); + } + }); + } + void _onPhoneChanged() { // 清除错误信息 if (_errorMessage != null) { @@ -93,6 +118,9 @@ class _PhoneRegisterPageState extends ConsumerState { if (!mounted) return; + // 启动倒计时 + _startCountdown(); + // 跳转到验证码页面 context.push( RoutePaths.smsVerify, @@ -275,14 +303,15 @@ class _PhoneRegisterPageState extends ConsumerState { Widget _buildNextButton() { final isValid = _isValidPhoneNumber(_phoneController.text.trim()); + final canClick = isValid && !_isSending && _canSend; return GestureDetector( - onTap: isValid && !_isSending ? _sendSmsCode : null, + onTap: canClick ? _sendSmsCode : null, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 16.h), decoration: BoxDecoration( - color: isValid && !_isSending + color: canClick ? const Color(0xFF2E7D32) : const Color(0xFFE0E0E0), borderRadius: BorderRadius.circular(12.r), @@ -298,11 +327,11 @@ class _PhoneRegisterPageState extends ConsumerState { ), ) : Text( - '获取验证码', + !_canSend ? '$_countdown秒后重新发送' : '获取验证码', style: TextStyle( fontSize: 16.sp, fontWeight: FontWeight.w600, - color: isValid ? Colors.white : const Color(0xFF999999), + color: canClick ? Colors.white : const Color(0xFF999999), ), ), ), diff --git a/frontend/mobile-app/lib/features/auth/presentation/pages/sms_verify_page.dart b/frontend/mobile-app/lib/features/auth/presentation/pages/sms_verify_page.dart index 9587ccfc..afb9eb07 100644 --- a/frontend/mobile-app/lib/features/auth/presentation/pages/sms_verify_page.dart +++ b/frontend/mobile-app/lib/features/auth/presentation/pages/sms_verify_page.dart @@ -404,9 +404,10 @@ class _SmsVerifyPageState extends ConsumerState { ), ), style: TextStyle( - fontSize: 24.sp, + fontSize: 20.sp, fontWeight: FontWeight.w700, color: const Color(0xFF333333), + height: 1.2, ), onChanged: (value) => _onCodeChanged(index, value), ),