fix:已登录显示

This commit is contained in:
jingyun
2026-06-07 11:16:38 +08:00
parent 544468f207
commit 6a7fa5a067
+222 -66
View File
@@ -54,75 +54,70 @@ class ProfilePage extends ConsumerWidget {
), ),
children: [ children: [
const PageHeader(title: '我的'), const PageHeader(title: '我的'),
AppCard( if (auth.loggedIn) ...[
color: colors.secondary, const _LoggedInHeader(),
child: Row( const SizedBox(height: YantingSpacing.x3),
children: [ _StatsCard(
CircleAvatar( favoriteCount: favoriteCount,
radius: 27, historyCount: historyCount,
backgroundColor: colors.background, savedListenCount: savedListenCount,
foregroundColor: colors.mutedForeground,
child: const Icon(AppIcons.user, size: 28),
),
const SizedBox(width: 15),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
auth.loggedIn ? '已登录' : '未登录',
style: YantingText.cardTitle.copyWith(
fontSize: 18,
color: colors.foreground,
),
),
const SizedBox(height: 5),
Text(
auth.loggedIn ? '收藏、历史和听单已在本地同步' : '登录后同步收藏、历史和听单',
style: YantingText.meta.copyWith(
height: 1.5,
color: colors.mutedForeground,
),
),
],
),
),
],
), ),
), ] else ...[
const SizedBox(height: YantingSpacing.x3), AppCard(
AppButton( color: colors.secondary,
label: auth.loggedIn ? '退出登录' : '登录 / 注册', child: Row(
expand: true, children: [
onPressed: auth.loggedIn CircleAvatar(
? () => ref.read(authControllerProvider.notifier).logout() radius: 27,
: () => showLoginSheet( backgroundColor: colors.background,
context, foregroundColor: colors.mutedForeground,
reason: '登录后同步收藏、历史和听单', child: const Icon(AppIcons.user, size: 28),
onPhoneLogin: () => _login(ref, LoginMethod.phone),
onSecondaryLogin: () => _login(ref, LoginMethod.wechat),
), ),
), const SizedBox(width: 15),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'未登录',
style: YantingText.cardTitle.copyWith(
fontSize: 18,
color: colors.foreground,
),
),
const SizedBox(height: 5),
Text(
'登录后同步收藏、历史和听单',
style: YantingText.meta.copyWith(
height: 1.5,
color: colors.mutedForeground,
),
),
],
),
),
],
),
),
const SizedBox(height: YantingSpacing.x3),
AppButton(
label: '登录 / 注册',
expand: true,
onPressed: () => showLoginSheet(
context,
reason: '登录后同步收藏、历史和听单',
onPhoneLogin: () => _login(ref, LoginMethod.phone),
onSecondaryLogin: () => _login(ref, LoginMethod.wechat),
),
),
],
const SizedBox(height: 18), const SizedBox(height: 18),
_MenuGroup( _MenuGroup(
children: [ children: [
_MenuRow(
icon: AppIcons.history,
title: '本地浏览记录',
trailing: '$historyCount 条 · 本地临时',
onTap: () => _showProfileListSheet(
context,
ref,
title: '本地浏览记录',
snapshot: historySnapshot,
emptyTitle: '暂无本地浏览记录',
emptyMessage: '打开研报详情或播放音频后会出现在这里',
),
),
_MenuRow( _MenuRow(
icon: AppIcons.heart, icon: AppIcons.heart,
title: '我的收藏', title: '我的收藏',
trailing: '$favoriteCount ', trailing: '$favoriteCount ',
onTap: () => _showLoginAwareList( onTap: () => _showLoginAwareList(
context, context,
ref, ref,
@@ -135,18 +130,37 @@ class ProfilePage extends ConsumerWidget {
), ),
_MenuRow( _MenuRow(
icon: AppIcons.headphones, icon: AppIcons.headphones,
title: '已存听单', title: '保存的听单',
trailing: '$savedListenCount ', trailing: '$savedListenCount ',
onTap: () => _showLoginAwareList( onTap: () => _showLoginAwareList(
context, context,
ref, ref,
auth, auth,
title: '已存听单', title: '保存的听单',
snapshot: savedListenSnapshot, snapshot: savedListenSnapshot,
emptyTitle: '暂无已存听单', emptyTitle: '暂无保存的听单',
emptyMessage: '在音频研报详情页保存听单后会出现在这里', emptyMessage: '在音频研报详情页保存听单后会出现在这里',
), ),
), ),
_MenuRow(
icon: AppIcons.history,
title: '浏览/收听历史',
trailing: '$historyCount',
onTap: () => _showProfileListSheet(
context,
ref,
title: '浏览/收听历史',
snapshot: historySnapshot,
emptyTitle: '暂无浏览/收听历史',
emptyMessage: '打开研报详情或播放音频后会出现在这里',
),
),
_MenuRow(
icon: Icons.download_outlined,
title: '下载记录',
trailing: 'Phase 1 预留',
onTap: () => showAppToast(context, '下载记录将在后续版本接入'),
),
], ],
), ),
const SizedBox(height: YantingSpacing.x3), const SizedBox(height: YantingSpacing.x3),
@@ -157,6 +171,12 @@ class ProfilePage extends ConsumerWidget {
title: '设置', title: '设置',
onTap: () => context.push(AppRoutes.settings), onTap: () => context.push(AppRoutes.settings),
), ),
if (auth.loggedIn)
_MenuRow(
icon: Icons.logout,
title: '退出登录',
onTap: () => ref.read(authControllerProvider.notifier).logout(),
),
_MenuRow( _MenuRow(
icon: AppIcons.fileList, icon: AppIcons.fileList,
title: '用户协议', title: '用户协议',
@@ -316,6 +336,142 @@ class ProfilePage extends ConsumerWidget {
} }
} }
class _LoggedInHeader extends StatelessWidget {
const _LoggedInHeader();
@override
Widget build(BuildContext context) {
return AppCard(
color: const Color(0xFF133D00),
borderColor: const Color(0xFF133D00),
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 30),
child: Row(
children: [
CircleAvatar(
radius: 34,
backgroundColor: const Color(0xFF385E26),
foregroundColor: YantingColors.primary,
child: Text(
'',
style: YantingText.sectionTitle.copyWith(
color: YantingColors.primary,
fontSize: 27,
),
),
),
const SizedBox(width: 22),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'研界用户',
style: YantingText.sectionTitle.copyWith(
color: Colors.white,
fontSize: 22,
),
),
const SizedBox(height: 4),
Text(
'已登录 · 手机号',
style: YantingText.body.copyWith(
color: Colors.white.withValues(alpha: 0.75),
fontSize: 15,
),
),
],
),
),
],
),
);
}
}
class _StatsCard extends StatelessWidget {
const _StatsCard({
required this.favoriteCount,
required this.historyCount,
required this.savedListenCount,
});
final int favoriteCount;
final int historyCount;
final int savedListenCount;
@override
Widget build(BuildContext context) {
final colors = ShadTheme.of(context).colorScheme;
return AppCard(
padding: EdgeInsets.zero,
child: Row(
children: [
Expanded(
child: _StatCell(value: favoriteCount, label: '收藏'),
),
SizedBox(
height: 66,
child: VerticalDivider(
width: 1,
thickness: 1,
color: colors.border,
),
),
Expanded(
child: _StatCell(value: historyCount, label: '历史'),
),
SizedBox(
height: 66,
child: VerticalDivider(
width: 1,
thickness: 1,
color: colors.border,
),
),
Expanded(
child: _StatCell(value: savedListenCount, label: '听单'),
),
],
),
);
}
}
class _StatCell extends StatelessWidget {
const _StatCell({required this.value, required this.label});
final int value;
final String label;
@override
Widget build(BuildContext context) {
final colors = ShadTheme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 18),
child: Column(
children: [
Text(
'$value',
style: YantingText.sectionTitle.copyWith(
color: const Color(0xFF163E08),
fontSize: 22,
fontFeatures: YantingTypographyFeatures.tabularNums,
),
),
const SizedBox(height: 3),
Text(
label,
style: YantingText.meta.copyWith(
color: colors.mutedForeground,
fontSize: 14,
),
),
],
),
);
}
}
class _MenuGroup extends StatelessWidget { class _MenuGroup extends StatelessWidget {
const _MenuGroup({required this.children}); const _MenuGroup({required this.children});
@@ -361,7 +517,7 @@ class _MenuRow extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 15), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 15),
child: Row( child: Row(
children: [ children: [
Icon(icon, size: 20, color: colors.foreground), Icon(icon, size: 20, color: const Color(0xFF143B05)),
const SizedBox(width: 13), const SizedBox(width: 13),
Expanded(child: Text(title, style: YantingText.body)), Expanded(child: Text(title, style: YantingText.body)),
if (trailing != null) if (trailing != null)