feat(client): 登录体验 — 记住邮箱 + 密码显隐 + 7天免登陆
1. 记住邮箱:登录页预填上次邮箱(TokenStore.saveLastEmail,登录/注册成功时存, 退出登录不清除)。 2. 密码显隐:登录/注册密码框加眼睛按钮切换明文(PangolinIcons.eye/eyeOff)。 3. 7天免登陆:RootFlow 改为响应 authProvider——启动时有有效会话直接进主界面; AuthNotifier.refresh() 在服务端拒绝(refresh 过期/超 7 天)时 logout 回登录页, 网络错误则保留会话。会话恢复期间显示极简启动屏。 flutter analyze 0 error;114 tests passed。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,7 @@ class _AuthScreenState extends ConsumerState<AuthScreen> {
|
||||
int _step = 0;
|
||||
bool _sent = false;
|
||||
bool _loading = false;
|
||||
bool _pwVisible = false;
|
||||
String? _errorZh;
|
||||
|
||||
final _email = TextEditingController();
|
||||
@@ -42,6 +43,17 @@ class _AuthScreenState extends ConsumerState<AuthScreen> {
|
||||
|
||||
bool get _emailValid => RegExp(r'\S+@\S+\.\S+').hasMatch(_email.text);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 预填上次登录邮箱。
|
||||
ref.read(tokenStoreProvider).loadLastEmail().then((email) {
|
||||
if (email != null && email.isNotEmpty && mounted) {
|
||||
setState(() => _email.text = email);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_email.dispose();
|
||||
@@ -71,6 +83,7 @@ class _AuthScreenState extends ConsumerState<AuthScreen> {
|
||||
code: _code.text.trim(),
|
||||
password: _pw.text,
|
||||
);
|
||||
await ref.read(tokenStoreProvider).saveLastEmail(_email.text.trim());
|
||||
await ref.read(authProvider.notifier).saveTokens(tokens);
|
||||
if (mounted) widget.onDone();
|
||||
} on AuthApiException catch (e) {
|
||||
@@ -85,6 +98,7 @@ class _AuthScreenState extends ConsumerState<AuthScreen> {
|
||||
email: _email.text.trim(),
|
||||
password: _pw.text,
|
||||
);
|
||||
await ref.read(tokenStoreProvider).saveLastEmail(_email.text.trim());
|
||||
await ref.read(authProvider.notifier).saveTokens(tokens);
|
||||
if (mounted) widget.onDone();
|
||||
} on AuthApiException catch (e) {
|
||||
@@ -182,13 +196,31 @@ class _AuthScreenState extends ConsumerState<AuthScreen> {
|
||||
InputDecoration get _bare =>
|
||||
const InputDecoration(border: InputBorder.none, isCollapsed: true, contentPadding: EdgeInsets.symmetric(vertical: 12));
|
||||
|
||||
// 密码输入 + 显示/隐藏切换(眼睛按钮)。
|
||||
Widget _pwInput(PangolinScheme c, String hint) => Row(children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _pw,
|
||||
obscureText: !_pwVisible,
|
||||
decoration: _bare.copyWith(hintText: hint),
|
||||
onChanged: (_) => setState(() {}),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () => setState(() => _pwVisible = !_pwVisible),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Icon(_pwVisible ? PangolinIcons.eyeOff : PangolinIcons.eye, size: 18, color: c.fg3),
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
Widget _login(PangolinScheme c, AppText t) {
|
||||
return Column(children: [
|
||||
_field(c, icon: PangolinIcons.mail, label: t.emailLabel,
|
||||
child: TextField(controller: _email, decoration: _bare.copyWith(hintText: t.emailPh), onChanged: (_) => setState(() {}))),
|
||||
const SizedBox(height: 16),
|
||||
_field(c, icon: PangolinIcons.lock, label: t.pwLabel,
|
||||
child: TextField(controller: _pw, obscureText: true, decoration: _bare.copyWith(hintText: t.pwPh), onChanged: (_) => setState(() {}))),
|
||||
_field(c, icon: PangolinIcons.lock, label: t.pwLabel, child: _pwInput(c, t.pwPh)),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Padding(
|
||||
@@ -239,8 +271,7 @@ class _AuthScreenState extends ConsumerState<AuthScreen> {
|
||||
return Column(children: [
|
||||
Row(children: [Icon(PangolinIcons.checkCircle, size: 15, color: c.success), const SizedBox(width: 7), Text(_email.text, style: PangolinText.sm.copyWith(color: c.fg2))]),
|
||||
const SizedBox(height: 16),
|
||||
_field(c, icon: PangolinIcons.lock, label: t.pwLabel,
|
||||
child: TextField(controller: _pw, obscureText: true, decoration: _bare.copyWith(hintText: t.setPwPh), onChanged: (_) => setState(() {}))),
|
||||
_field(c, icon: PangolinIcons.lock, label: t.pwLabel, child: _pwInput(c, t.setPwPh)),
|
||||
const SizedBox(height: 18),
|
||||
PangolinButton(
|
||||
label: _loading ? '...' : t.doCreate,
|
||||
|
||||
@@ -18,6 +18,8 @@ class PangolinIcons {
|
||||
|
||||
// ── 导航 / 操作 ──
|
||||
static const settings = LucideIcons.settings;
|
||||
static const eye = LucideIcons.eye;
|
||||
static const eyeOff = LucideIcons.eyeOff;
|
||||
static const user = LucideIcons.user;
|
||||
static const search = LucideIcons.search;
|
||||
static const check = LucideIcons.check;
|
||||
|
||||
Reference in New Issue
Block a user