diff --git a/app/lib/features/calendar/views/calendar_page.dart b/app/lib/features/calendar/views/calendar_page.dart index df0166f..86ff7a2 100644 --- a/app/lib/features/calendar/views/calendar_page.dart +++ b/app/lib/features/calendar/views/calendar_page.dart @@ -83,6 +83,9 @@ class _CalendarView extends StatelessWidget { ); context.read().add(CalendarMonthChanged(next)); }, + onToday: () { + context.read().add(CalendarMonthChanged(DateTime.now())); + }, ), // 视图模式切换 @@ -543,11 +546,13 @@ class _MonthNavigator extends StatelessWidget { required this.month, required this.onPrevious, required this.onNext, + this.onToday, }); final DateTime month; final VoidCallback onPrevious; final VoidCallback onNext; + final VoidCallback? onToday; @override Widget build(BuildContext context) { @@ -580,6 +585,22 @@ class _MonthNavigator extends StatelessWidget { fontWeight: FontWeight.bold, ), ), + // "今天" 按钮 — 不在当前月时显示 + if (onToday != null && !_isCurrentMonth(month)) + Padding( + padding: const EdgeInsets.only(left: 8), + child: TextButton( + onPressed: onToday, + style: TextButton.styleFrom( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), + minimumSize: Size.zero, + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + ), + child: const Text('今天', style: TextStyle(fontSize: 13)), + ), + ) + else + const SizedBox(width: 8), SizedBox( width: 44, height: 44, @@ -607,6 +628,11 @@ class _MonthNavigator extends StatelessWidget { ]; return '${date.year}年 ${months[date.month - 1]}'; } + + bool _isCurrentMonth(DateTime date) { + final now = DateTime.now(); + return date.year == now.year && date.month == now.month; + } } // ===== 星期标题行 ===== diff --git a/app/lib/features/editor/views/editor_page.dart b/app/lib/features/editor/views/editor_page.dart index 0e2b4c7..0e8a9e2 100644 --- a/app/lib/features/editor/views/editor_page.dart +++ b/app/lib/features/editor/views/editor_page.dart @@ -554,8 +554,17 @@ class _EditorViewState extends State<_EditorView> { ); } - /// 返回处理 + /// 返回处理 — 有未保存修改时弹出确认 void _handleBack(BuildContext context) { + final bloc = context.read(); + if (bloc.state.isDirty) { + _showDiscardDialog(context); + } else { + _doNavigateBack(context); + } + } + + void _doNavigateBack(BuildContext context) { if (context.canPop()) { context.pop(); } else { @@ -563,6 +572,29 @@ class _EditorViewState extends State<_EditorView> { } } + void _showDiscardDialog(BuildContext context) { + showDialog( + context: context, + builder: (ctx) => AlertDialog( + title: const Text('放弃编辑?'), + content: const Text('你有未保存的修改,确定要离开吗?'), + actions: [ + TextButton( + onPressed: () => Navigator.pop(ctx), + child: const Text('继续编辑'), + ), + TextButton( + onPressed: () { + Navigator.pop(ctx); + _doNavigateBack(context); + }, + child: const Text('放弃'), + ), + ], + ), + ); + } + /// 保存处理 void _handleSave(BuildContext context, EditorState state) { widget.onSaveComplete();