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), ),