fix(frontend): 添加新账号时显示加载状态提示

- 添加 _isAddingAccount 状态变量
- 点击"添加新账号"时显示"正在准备..."加载提示
- 添加 try-catch 错误处理,失败时显示错误提示
- 防止重复点击

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-15 06:14:49 -08:00
parent 2a4efe0828
commit 3942cb405a
1 changed files with 33 additions and 14 deletions

View File

@ -20,6 +20,7 @@ class _AccountSwitchPageState extends ConsumerState<AccountSwitchPage> {
String? _currentAccountId; String? _currentAccountId;
bool _isLoading = true; bool _isLoading = true;
bool _isSwitching = false; bool _isSwitching = false;
bool _isAddingAccount = false;
@override @override
void initState() { void initState() {
@ -88,16 +89,34 @@ class _AccountSwitchPageState extends ConsumerState<AccountSwitchPage> {
} }
Future<void> _addNewAccount() async { Future<void> _addNewAccount() async {
// if (_isAddingAccount) return;
final multiAccountService = ref.read(multiAccountServiceProvider);
await multiAccountService.saveCurrentAccountData();
// 退 setState(() => _isAddingAccount = true);
await multiAccountService.logoutCurrentAccount();
// try {
if (mounted) { final multiAccountService = ref.read(multiAccountServiceProvider);
context.go(RoutePaths.guide);
//
await multiAccountService.saveCurrentAccountData();
// 退
await multiAccountService.logoutCurrentAccount();
//
if (mounted) {
context.go(RoutePaths.guide);
}
} catch (e) {
debugPrint('[AccountSwitchPage] 添加新账号失败: $e');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('添加新账号失败: $e')),
);
}
} finally {
if (mounted) {
setState(() => _isAddingAccount = false);
}
} }
} }
@ -179,18 +198,18 @@ class _AccountSwitchPageState extends ConsumerState<AccountSwitchPage> {
color: Color(0xFFD4AF37), color: Color(0xFFD4AF37),
), ),
) )
: _isSwitching : (_isSwitching || _isAddingAccount)
? const Center( ? Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
CircularProgressIndicator( const CircularProgressIndicator(
color: Color(0xFFD4AF37), color: Color(0xFFD4AF37),
), ),
SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
'正在切换账号...', _isAddingAccount ? '正在准备...' : '正在切换账号...',
style: TextStyle( style: const TextStyle(
fontSize: 14, fontSize: 14,
color: Color(0xFF5D4037), color: Color(0xFF5D4037),
), ),