8be21b856b
P3 Task 3 移动端(对接 Task 2 api client + 本任务新增的后端契约): - 登录页实装:账号/密码表单(空值客户端校验)→ api.login(会话自动 持久化)→ pushReplacement /home;错误码本地化(AUTH_INVALID_ CREDENTIALS / AUTH_RATE_LIMITED(含稍后再试文案)/ 网络 / 校验); 提交加载态防重复提交。 - 修改密码页(设置页入口):当前/新/确认三字段,客户端校验(≥8 位、 两次一致)→ api.changePassword → toast + pop;成功后本地会话不变 (服务端保留当前会话);旧密码错误(401 AUTH_INVALID_CREDENTIALS) 显示「当前密码错误」且不触发 401 驱逐。 - 退出登录:设置页按钮 → api.logout 尽力而为 → 清会话 → 清栈回 /login;App 壳 initState 注册 onUnauthorized(业务 401 → 清栈 /login), 根 navigatorKey 接线;password-change 的 401 豁免会话驱逐(拦截器 豁免集合与令牌附加分离)。 - l10n:新增 16 组 zh/en 文案;错误码 → 文案解析扩展 (core/error_l10n.dart,errorCode→AppLocalizations)。 - 测试:ApiClient.changePassword 单测 ×2(Bearer+请求体;旧密码 401 不驱逐);widget 测试 ×12(登录 5:空值/成功跳转/凭据错误/限速文案/ 加载禁用;改密 4:过短/不一致/旧密码错误文案+会话保留/成功 toast+pop 且令牌不变;设置 2:改密入口跳转/登出清会话回登录;App 壳 1:401 清栈回 /login)。flutter analyze 0 issue;flutter test 81/81。 Co-Authored-By: Claude Code <noreply@anthropic.com>
132 lines
3.8 KiB
Dart
132 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../core/api_client.dart';
|
|
import '../l10n/app_localizations.dart';
|
|
|
|
/// 主壳:底部导航(相册 / 队列 / 设置)。
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
int _selectedIndex = 0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context);
|
|
return Scaffold(
|
|
body: IndexedStack(
|
|
index: _selectedIndex,
|
|
children: const [
|
|
AlbumsTab(),
|
|
QueueTab(),
|
|
SettingsTab(),
|
|
],
|
|
),
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: _selectedIndex,
|
|
onDestinationSelected: (index) =>
|
|
setState(() => _selectedIndex = index),
|
|
destinations: [
|
|
NavigationDestination(
|
|
icon: const Icon(Icons.photo_library_outlined),
|
|
selectedIcon: const Icon(Icons.photo_library),
|
|
label: l10n.homeTabAlbums,
|
|
),
|
|
NavigationDestination(
|
|
icon: const Icon(Icons.cloud_upload_outlined),
|
|
selectedIcon: const Icon(Icons.cloud_upload),
|
|
label: l10n.homeTabQueue,
|
|
),
|
|
NavigationDestination(
|
|
icon: const Icon(Icons.settings_outlined),
|
|
selectedIcon: const Icon(Icons.settings),
|
|
label: l10n.homeTabSettings,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 相册列表(桩)。Task 4:游标分页、创建/编辑、二维码分享。
|
|
class AlbumsTab extends StatelessWidget {
|
|
const AlbumsTab({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context);
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(l10n.albums)),
|
|
body: Center(
|
|
child: Text(
|
|
l10n.albums,
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 上传队列(桩)。Task 6/9:状态机展示、筛选与重试。
|
|
class QueueTab extends StatelessWidget {
|
|
const QueueTab({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context);
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(l10n.queue)),
|
|
body: Center(
|
|
child: Text(
|
|
l10n.queue,
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 设置页(P3 Task 3:修改密码入口 + 退出登录;Task 10 补语言切换持久化)。
|
|
class SettingsTab extends ConsumerWidget {
|
|
const SettingsTab({super.key});
|
|
|
|
Future<void> _logout(BuildContext context, WidgetRef ref) async {
|
|
// api.logout 尽力而为(服务端撤销失败也照常本地清会话——客户端内已处理)。
|
|
await ref.read(apiClientProvider).logout();
|
|
if (!context.mounted) return;
|
|
Navigator.of(context).pushNamedAndRemoveUntil('/login', (route) => false);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final l10n = AppLocalizations.of(context);
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(l10n.settings)),
|
|
body: ListView(
|
|
children: [
|
|
ListTile(
|
|
leading: const Icon(Icons.language),
|
|
title: Text(l10n.language),
|
|
subtitle: Text(l10n.localeFollowSystem),
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.password_outlined),
|
|
title: Text(l10n.passwordChangeTitle),
|
|
onTap: () => Navigator.of(context).pushNamed('/password-change'),
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.logout),
|
|
title: Text(l10n.logout),
|
|
onTap: () => _logout(context, ref),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|