diff --git a/lib/features/home/presentation/widgets/map/testmap_pages.dart b/lib/features/home/presentation/widgets/map/testmap_pages.dart index 8e642292..705bdfac 100644 --- a/lib/features/home/presentation/widgets/map/testmap_pages.dart +++ b/lib/features/home/presentation/widgets/map/testmap_pages.dart @@ -59,6 +59,7 @@ class MapPageEnterprise extends StatefulWidget { class _MapPageEnterpriseState extends State { final _dispatcher = sl(); late StreamSubscription _sub; + bool _isRefreshing = false; // 新增:页面刷新状态标志 final MapController _mapController = MapController(); final TextEditingController _plotNameController = TextEditingController(); @@ -366,6 +367,97 @@ class _MapPageEnterpriseState extends State { }); } + // ========== 新增:页面刷新初始化方法 ========== + Future _handleRefresh() async { + // 防止重复刷新 + if (_isRefreshing) return; + + setState(() { + _isRefreshing = true; // 标记开始刷新 + }); + + try { + // 1. 取消旧的定位监听 + await _positionSub?.cancel(); + + // 2. 重置所有页面状态(恢复初始值) + setState(() { + // 清空打点和轨迹数据 + _markedPoints.clear(); + gcjPathPoints.clear(); + gcjOuterPoints.clear(); + _currentTracePoints = null; + + // 重置面板状态 + _isPanelOpen = false; + _directionBoxOpen = false; + _isListBoxOpen = false; + _isWorkPanelOpen = false; + + // 重置选中状态 + _selectedPlot = null; + _selectedPlotPath = null; + + // 重置作业模式 + _currentRobotMode = RobotMode.point; + _currentAreaMode = AreaMode.work; + _currentWorkMode = WorkMode.bow; + + // 重置参数 + _workDistance = 0.0; + _angle = 0.0; + _mapCenter = const LatLng(39.9042, 116.4074); + _hasMovedOnce = false; + _currentLatLng = null; + }); + + // 3. 重新初始化定位 + await _initLocationEnterprise(); + + // 4. 重置轨迹管理器 + _traceManager.reset(); + + // 5. 重新加载作业记录(保持数据最新) + final userId = context.read().state.user?.userId ?? ""; + if (userId.isNotEmpty) { + await context.read().loadWorkRecords(userId); + } + + // 6. 重置地图视角到初始位置 + _mapController.move(const LatLng(39.9042, 116.4074), 17); + + // 刷新成功提示 + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('页面已刷新完成'), + backgroundColor: Colors.green, + duration: Duration(seconds: 2), + ), + ); + } + } catch (e) { + // 错误处理 + debugPrint('刷新失败:$e'); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('刷新失败:${e.toString().substring(0, 50)}'), + backgroundColor: Colors.red, + duration: Duration(seconds: 3), + ), + ); + } + } finally { + // 标记刷新结束 + if (mounted) { + setState(() { + _isRefreshing = false; + }); + } + } + } + /// =============================== /// 更新位置 /// =============================== @@ -987,6 +1079,24 @@ class _MapPageEnterpriseState extends State { ], ), + if (_isRefreshing) + Positioned.fill( + child: Container( + color: Colors.black.withOpacity(0.3), + child: const Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CircularProgressIndicator( + color: Colors.white, + strokeWidth: 3, + ), + ], + ), + ), + ), + ), + // 悬浮返回按钮(核心修改) Positioned( top: 10, @@ -1111,6 +1221,7 @@ class _MapPageEnterpriseState extends State { _currentWorkMode = mode; debugPrint('外部收到作业模式:$mode'); }, + onRefreshTap: _handleRefresh, // 推荐用局部刷新 ), ), ), diff --git a/lib/features/home/presentation/widgets/path_list_pages.dart b/lib/features/home/presentation/widgets/path_list_pages.dart index cdbb9e8f..11267517 100644 --- a/lib/features/home/presentation/widgets/path_list_pages.dart +++ b/lib/features/home/presentation/widgets/path_list_pages.dart @@ -6,6 +6,7 @@ class VerticalFloatMenu extends StatefulWidget { final ValueChanged? onEditTap; final ValueChanged? onListBox; final ValueChanged? onWorkModeSelected; + final VoidCallback? onRefreshTap; // 新增刷新回调 const VerticalFloatMenu({ super.key, @@ -13,6 +14,7 @@ class VerticalFloatMenu extends StatefulWidget { this.onEditTap, this.onListBox, this.onWorkModeSelected, + this.onRefreshTap, // 接收刷新回调 }); @override @@ -31,7 +33,7 @@ class _VerticalFloatMenuState extends State { {"icon": Icons.format_list_bulleted, "name": "列表"}, {"icon": Icons.train, "name": "场站"}, {"icon": Icons.navigation, "name": "定位"}, - {"icon": Icons.edit_note, "name": "刷新"}, + {"icon": Icons.refresh, "name": "刷新"}, {"icon": Icons.videocam, "name": "监控"}, ]; @@ -81,6 +83,14 @@ class _VerticalFloatMenuState extends State { if (index == 1) { widget.onListBox?.call(true); } + if (index == 4) { + // 触发外部传入的刷新回调 + widget.onRefreshTap?.call(); + // 可选:添加刷新动画/状态提示 + setState(() { + // 可以添加刷新中的临时状态(比如图标旋转) + }); + } }, child: Container( width: double.infinity,