fix: 全链路问题修复 — 编辑器返回/Tab导航/数据库编码/Token注入
修复内容:
- 编辑器返回按钮: 所有 context.go('/editor') 改为 context.push(),pop() 加安全守卫 fallback 到 /home
- Tab 导航: Web 平台强制使用移动端底部 TabBar 布局 (kIsWeb 守卫)
- 数据库编码: db.rs 自动追加 client_encoding=utf8 参数,修复中文 display_name 乱码
- AuthBloc token: 清理冗余 TODO,token 注入已在 AuthRepository 中正常工作
- 影响 9 个文件的编辑器导航调用点统一修改
This commit is contained in:
@@ -54,12 +54,10 @@ class NuanjiApp extends StatelessWidget {
|
||||
// 异步恢复 SyncEngine 持久化队列(fire-and-forget,不阻塞 UI)
|
||||
syncEngine.restorePendingQueue();
|
||||
|
||||
// 认证成功后注入 JWT token 到 ApiClient
|
||||
// 认证状态监听:登出时清除 token
|
||||
// 注意:登录时 token 由 AuthRepository.login() 直接注入 ApiClient
|
||||
authBloc.stream.listen((state) {
|
||||
if (state is Authenticated) {
|
||||
// TODO: 从 SecureStorage 读取 token 并设置
|
||||
// apiClient.setToken(token);
|
||||
} else {
|
||||
if (state is! Authenticated) {
|
||||
apiClient.clearToken();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -260,7 +260,7 @@ class _AppShell extends StatelessWidget {
|
||||
body: child,
|
||||
floatingActionButton: selectedIndex == 0
|
||||
? FloatingActionButton(
|
||||
onPressed: () => context.go('/editor'),
|
||||
onPressed: () => context.push('/editor'),
|
||||
child: const Icon(Icons.edit_rounded),
|
||||
)
|
||||
: null,
|
||||
|
||||
@@ -385,7 +385,7 @@ class _EmptyDayView extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.tonal(
|
||||
onPressed: () => context.go('/editor'),
|
||||
onPressed: () => context.push('/editor'),
|
||||
child: const Text('写一篇'),
|
||||
),
|
||||
],
|
||||
@@ -420,7 +420,7 @@ class _DayJournalList extends StatelessWidget {
|
||||
side: BorderSide(color: colorScheme.outlineVariant),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () => context.go('/editor?id=${journal.id}'),
|
||||
onTap: () => context.push('/editor?id=${journal.id}'),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
|
||||
@@ -296,7 +296,7 @@ class _DiaryWallCard extends StatelessWidget {
|
||||
side: BorderSide(color: colorScheme.outlineVariant),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () => context.go('/editor?id=${journal.id}'),
|
||||
onTap: () => context.push('/editor?id=${journal.id}'),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -417,7 +417,7 @@ class _TopicsTab extends StatelessWidget {
|
||||
side: BorderSide(color: colorScheme.outlineVariant),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () => context.go('/editor?topic=${topic.id}'),
|
||||
onTap: () => context.push('/editor?topic=${topic.id}'),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
|
||||
@@ -50,7 +50,13 @@ class EditorPage extends StatelessWidget {
|
||||
),
|
||||
child: _EditorView(
|
||||
journalId: journalId,
|
||||
onSaveComplete: () => context.pop(),
|
||||
onSaveComplete: () {
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go('/home');
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -202,7 +208,13 @@ class _EditorView extends StatelessWidget {
|
||||
children: [
|
||||
// 返回按钮
|
||||
IconButton(
|
||||
onPressed: () => context.pop(),
|
||||
onPressed: () {
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go('/home');
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back_rounded),
|
||||
tooltip: '返回',
|
||||
),
|
||||
|
||||
@@ -173,7 +173,7 @@ class _QuickMoodCard extends StatelessWidget {
|
||||
children: moods.map((mood) {
|
||||
final isTop = topMood == mood.$3;
|
||||
return GestureDetector(
|
||||
onTap: () => context.go('/editor'),
|
||||
onTap: () => context.push('/editor'),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
@@ -225,7 +225,7 @@ class _JournalList extends StatelessWidget {
|
||||
side: BorderSide(color: colorScheme.outlineVariant),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () => context.go('/editor?id=${journal.id}'),
|
||||
onTap: () => context.push('/editor?id=${journal.id}'),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -292,7 +292,7 @@ class _EmptyJournalState extends StatelessWidget {
|
||||
style: theme.textTheme.bodyLarge?.copyWith(color: colorScheme.onSurface.withValues(alpha: 0.5))),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.icon(
|
||||
onPressed: () => context.go('/editor'),
|
||||
onPressed: () => context.push('/editor'),
|
||||
icon: const Icon(Icons.add_rounded),
|
||||
label: const Text('写日记'),
|
||||
),
|
||||
|
||||
@@ -139,7 +139,7 @@ class _TemplateCard extends StatelessWidget {
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
// 使用模板创建日记
|
||||
context.go('/editor?template=${template.id}');
|
||||
context.push('/editor?template=${template.id}');
|
||||
},
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// 暖记响应式骨架 — 三级自适应布局
|
||||
// 手机: 底部 TabBar | 平板: 侧边导航 | 桌面: 三栏
|
||||
// Web 平台始终使用底部 TabBar(移动端布局)以保证导航交互正常
|
||||
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/material.dart';
|
||||
import '../core/constants/breakpoints.dart';
|
||||
|
||||
@@ -31,7 +33,11 @@ class _ResponsiveScaffoldState extends State<ResponsiveScaffold> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.sizeOf(context).width;
|
||||
final deviceType = Breakpoints.getDeviceType(width);
|
||||
// Web 平台:始终使用移动端底部 TabBar 布局
|
||||
// 原因:Web 上 NavigationRail 点击事件可能被 Flutter CanvasKit 拦截
|
||||
final deviceType = kIsWeb
|
||||
? DeviceType.mobile
|
||||
: Breakpoints.getDeviceType(width);
|
||||
|
||||
switch (deviceType) {
|
||||
case DeviceType.mobile:
|
||||
|
||||
Reference in New Issue
Block a user