From db7c98735b985f2be3229e58ccdcc312cd241334 Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Wed, 26 Mar 2025 15:29:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=9A=E8=AE=AE=E5=8A=A9?= =?UTF-8?q?=E6=89=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/meeting_controller.dart | 20 ++++ .../meeting_record_controller.dart | 10 ++ lib/modules/meeting/views/meeting_view.dart | 94 +++++++++++++++++-- 3 files changed, 115 insertions(+), 9 deletions(-) diff --git a/lib/modules/meeting/controllers/meeting_controller.dart b/lib/modules/meeting/controllers/meeting_controller.dart index ff126b10e..e798e6f36 100644 --- a/lib/modules/meeting/controllers/meeting_controller.dart +++ b/lib/modules/meeting/controllers/meeting_controller.dart @@ -47,4 +47,24 @@ class MeetingController extends GetxController { isLoadingMore = true; } } + + // 修改标题 + void editMeetingTitle(int id, String title) async { + if (title.isEmpty) return; + SqfliteApi.editMeetingTitle(id, title); + int index = dataList.indexWhere((item) => item['id'] == id); + if (index != -1) { + final dataMap = Map.from(dataList[index]); + dataMap['title'] = title; + dataList[index] = dataMap; + } + Get.back(); + } + + // 删除数据 + void deleteMeeting(int id) { + dataList.removeWhere((item) => item['id'] == id); + // 删除数据库中的记录 + SqfliteApi.deleteMeeting(id); + } } diff --git a/lib/modules/meeting/controllers/meeting_record_controller.dart b/lib/modules/meeting/controllers/meeting_record_controller.dart index ba1c239ac..1e569bfd9 100644 --- a/lib/modules/meeting/controllers/meeting_record_controller.dart +++ b/lib/modules/meeting/controllers/meeting_record_controller.dart @@ -5,9 +5,12 @@ import 'package:get/get.dart'; import '../../../data/services/asr_service.dart'; import '../../../data/services/db/sqflite_api.dart'; +import 'meeting_controller.dart'; class MeetingRecordController extends GetxController with GetSingleTickerProviderStateMixin { + final MeetingController meetingController = Get.find(); + late AnimationController lottieController; late AsrService _asrService; @@ -113,6 +116,13 @@ class MeetingRecordController extends GetxController }; final result = await SqfliteApi.insertMeeting(data); if (result != null) { + meetingController.dataList.insert(0, { + 'id': result, + 'title': title, + 'content': firstContent, + 'seconds': seconds.value, + 'creationtime': creationTime, + }); Get.back(); } } diff --git a/lib/modules/meeting/views/meeting_view.dart b/lib/modules/meeting/views/meeting_view.dart index 6d799bdd2..d51e63a86 100644 --- a/lib/modules/meeting/views/meeting_view.dart +++ b/lib/modules/meeting/views/meeting_view.dart @@ -97,6 +97,50 @@ class MeetingView extends GetView { Widget _item(BuildContext context, bool isDarkMode, MeetingModel data) { return GestureDetector( onTap: () {}, + onLongPressStart: (details) { + RenderBox? renderBox = + Overlay.of(context).context.findRenderObject() as RenderBox; + final RelativeRect position = RelativeRect.fromRect( + Rect.fromLTRB( + details.globalPosition.dx, + details.globalPosition.dy, + details.globalPosition.dx + 110, // 菜单显示位置X轴坐标 + details.globalPosition.dy - 40, // 菜单显示位置Y轴坐标 + ), + Offset.zero & renderBox.size, + ); + + showMenu( + context: context, + position: position, + color: isDarkMode ? AppColors.cardBackground : Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.r), + ), + items: [ + _popupMenuEntry( + Icon( + Icons.edit_calendar, + color: isDarkMode ? Colors.white : Colors.black87, + ), + '编辑', + isDarkMode ? Colors.white : Colors.black87, + () { + controller.titleController.text = data.title; + _bottomSheet(context, isDarkMode, id: data.id); + }, + ), + _popupMenuEntry( + const Icon(Icons.delete_outline, color: Colors.red), + '删除', + isDarkMode ? Colors.white : Colors.black87, + () { + controller.deleteMeeting(data.id); + }, + ), + ], + ); + }, child: Container( padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 8.w), margin: EdgeInsets.symmetric(vertical: 5.w), @@ -172,7 +216,35 @@ class MeetingView extends GetView { ); } - void _bottomSheet(BuildContext context, bool isDarkMode) { + PopupMenuEntry _popupMenuEntry( + Icon icon, + String title, + Color color, + Function() onTap, + ) { + return PopupMenuItem( + onTap: onTap, + child: SizedBox( + width: 120.w, + child: Row( + children: [ + icon, + 8.horizontalSpace, + Text( + title, + style: TextStyle(color: color), + ), + ], + ), + ), + ); + } + + void _bottomSheet( + BuildContext context, + bool isDarkMode, { + int? id, + }) { showModalBottomSheet( context: context, isScrollControlled: true, @@ -188,7 +260,7 @@ class MeetingView extends GetView { mainAxisSize: MainAxisSize.min, children: [ Text( - '录音标题(非必填)', + id != null ? '修改录音标题(非必填)' : '录音标题(非必填)', style: TextStyle( color: isDarkMode ? Colors.white : Colors.black87, fontSize: 16.sp, @@ -266,14 +338,18 @@ class MeetingView extends GetView { onTap: () { int time = DateTime.now().millisecondsSinceEpoch; String title = controller.titleController.text; - if (title.isEmpty) { - title = - '${DateUtil.formatDateMs(time, format: DateFormats.y_mo_d)} 录音'; + if (id != null) { + controller.editMeetingTitle(id, title); + } else { + if (title.isEmpty) { + title = + '${DateUtil.formatDateMs(time, format: DateFormats.y_mo_d)} 录音'; + } + Get.back(); + Get.toNamed(Routes.meetingRecord, arguments: { + 'title': title, + }); } - Get.back(); - Get.toNamed(Routes.meetingRecord, arguments: { - 'title': title, - }); }, child: Container( width: 120.w,