From ef88390b340e0fee4527e46a5c5b0635a0d9bff0 Mon Sep 17 00:00:00 2001 From: ZV Dev Date: Sat, 24 Oct 2026 09:13:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Dashboard=20=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E8=A1=A5=E5=9B=9E=E7=BC=96=E8=BE=91/?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=85=A5=E5=8F=A3=EF=BC=88v2.0=20=E6=94=B9?= =?UTF-8?q?=E7=89=88=E9=81=97=E6=BC=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/features/dashboard/dashboard_page.dart | 55 +++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/features/dashboard/dashboard_page.dart b/lib/features/dashboard/dashboard_page.dart index d6eed01..1dd0d0c 100644 --- a/lib/features/dashboard/dashboard_page.dart +++ b/lib/features/dashboard/dashboard_page.dart @@ -75,6 +75,47 @@ class _DashboardPageState extends State { _refreshAll(); } + /// 服务器卡片菜单:编辑 / 删除。 + Future _onServerAction(BuildContext context, ServerConfig s, String action) async { + final serverProvider = context.read(); + final rconProvider = context.read(); + final holder = context.read(); + if (action == 'edit') { + final updated = await showDialog( + context: context, + builder: (_) => ServerFormDialog(existingServer: s), + ); + if (updated == null || !mounted) return; + await serverProvider.updateServer(updated); + // 若编辑的是当前选中服务器,刷新选中引用 + if (holder.server?.id == updated.id) holder.select(updated); + _refreshAll(); + return; + } + if (action == 'delete') { + final confirmed = await showDialog( + context: context, + builder: (_) => AlertDialog( + title: const Text('删除服务器'), + content: Text('确定要删除「${s.name}」吗?仅删除本应用中的连接配置,不影响服务器本身。'), + actions: [ + TextButton(onPressed: () => Navigator.pop(context, false), child: const Text('取消')), + FilledButton( + style: FilledButton.styleFrom(backgroundColor: Colors.red), + onPressed: () => Navigator.pop(context, true), + child: const Text('删除'), + ), + ], + ), + ); + if (confirmed != true || !mounted) return; + await serverProvider.removeServer(s.id); + rconProvider.disposeServer(s.id); + if (holder.server?.id == s.id) holder.select(null); + setState(() => _status.remove(s.id)); + } + } + /// 断线提醒:页面内 SnackBar + 顶部全局提示。 void _showDisconnectAlert(String serverName) { final nav = navigatorKey.currentContext; @@ -227,7 +268,19 @@ class _DashboardPageState extends State { '${st.tps != null ? " · TPS ${st.tps!.toStringAsFixed(1)}" : ""}' : '离线', ), - trailing: isSel ? const Icon(Icons.check) : null, + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (isSel) const Icon(Icons.check, color: Colors.green), + PopupMenuButton( + onSelected: (a) => _onServerAction(context, s, a), + itemBuilder: (_) => const [ + PopupMenuItem(value: 'edit', child: Text('编辑')), + PopupMenuItem(value: 'delete', child: Text('删除')), + ], + ), + ], + ), onTap: () { holder.select(s); setState(() {});