完善路线返航和障碍物显示
This commit is contained in:
@@ -140,6 +140,7 @@ class _DeviceDetailPageV2State extends State<DeviceDetailPageV2> {
|
||||
super.initState();
|
||||
// 进入详情即订阅,不依赖切换设备或进入控制页。
|
||||
final sn = widget.robot.name.trim();
|
||||
debugPrint('[MQTT-障碍物] 进入设备详情,启动订阅: mower/$sn/perception/obstacle/post');
|
||||
GetIt.I<DeviceStatusBloc>().startMqttRealtimeListening(sn);
|
||||
_alarmsCubit = GetIt.I<DeviceAlarmsCubit>();
|
||||
_alarmsCubit.logSnapshot('进入设备详情', deviceSn: sn);
|
||||
|
||||
@@ -890,11 +890,17 @@ class _RobotAutonomousWorkPageV2State extends State<RobotAutonomousWorkPageV2> {
|
||||
showWorkSettingPanel(context);
|
||||
}
|
||||
|
||||
void _onReturnHome() {
|
||||
CapsuleToast.show(
|
||||
_l10n.translate('autonomous_work.return_demo'),
|
||||
showCheck: false,
|
||||
Future<void> _onReturnHome() async {
|
||||
await Navigator.of(context).push(
|
||||
RouteEditorPageV2.route(
|
||||
deviceSn: _deviceId,
|
||||
exitToLandscape: true,
|
||||
startReturnEditor: true,
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
_enterLandscape();
|
||||
_statusBloc.startMqttRealtimeListening(_deviceId);
|
||||
}
|
||||
|
||||
void _openMorePanel() {
|
||||
|
||||
@@ -17,14 +17,17 @@ import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/components/input_confirm_dialog.dart';
|
||||
import 'package:maibu_satabot_v2/components/route_type_picker.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/error_handler.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/back_to_rest_point_usecase.dart';
|
||||
import '../../domain/entities/device_entity.dart' as v2;
|
||||
import '../../domain/usecases/get_site_devices_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
|
||||
import 'package:maibu_satabot_v2/features/autonomous_work/domain/entities/work_session_models.dart';
|
||||
import 'package:maibu_satabot_v2/features/autonomous_work/domain/entities/return_plan_models.dart';
|
||||
import 'package:maibu_satabot_v2/features/autonomous_work/data/v2_work_store.dart';
|
||||
import 'package:maibu_satabot_v2/features/autonomous_work/domain/repositories/autonomous_work_gateway.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/running_status_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_state.dart';
|
||||
@@ -322,31 +325,12 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
_draftTimer?.cancel();
|
||||
_persistDraft();
|
||||
setState(() {
|
||||
_draftLoaded = false;
|
||||
_deviceSn = sn;
|
||||
_devicePos = null;
|
||||
_markedPoints.clear();
|
||||
_obstacleHoles.clear();
|
||||
_currentObstaclePoints.clear();
|
||||
_pathPoints = [];
|
||||
_outerPoints = [];
|
||||
_returnPoints.clear();
|
||||
_returnObstacleHoles.clear();
|
||||
_returnObstacleNames.clear();
|
||||
_returnObstacleSizes.clear();
|
||||
_returnDropObstacle = false;
|
||||
_isWorkAreaCompleted = false;
|
||||
_isPanelOpen = false;
|
||||
_isReturnMode = false;
|
||||
_isReturnListOpen = false;
|
||||
_pendingReturnDraft = null;
|
||||
_returnLoading = false;
|
||||
_isObstacleEditing = false;
|
||||
_returnSaved = false;
|
||||
_selectedRouteId = null;
|
||||
_returnDeviceSn = sn;
|
||||
_alignReturnDevice();
|
||||
});
|
||||
_statusBloc.startMqttRealtimeListening(sn);
|
||||
await _restoreDraft();
|
||||
}
|
||||
|
||||
int _tool = -1;
|
||||
@@ -408,14 +392,18 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
/// 是否处于返航打点模式(与圈地面板互斥)
|
||||
bool _isReturnMode = false;
|
||||
|
||||
/// 返航方案是否已保存(本地暂存标记,仅界面)
|
||||
/// 当前返航配置是否与已保存的服务器配置一致。
|
||||
bool _returnSaved = false;
|
||||
|
||||
/// 返航方案保存请求进行中(防重复点击 + 按钮 loading)
|
||||
bool _savingReturn = false;
|
||||
bool _executingReturn = false;
|
||||
List<v2.DeviceEntity> _siteDevices = const [];
|
||||
int? _siteDevicesSiteId;
|
||||
|
||||
/// 进入返航时正在按场站拉取已有方案(selectBySiteId):期间盖一层 loading
|
||||
bool _returnLoading = false;
|
||||
bool _returnGuideOpen = false;
|
||||
|
||||
/// 一键返航方案列表浮层:查到已有方案时先弹列表,选中它才进编辑器=修改态
|
||||
bool _isReturnListOpen = false;
|
||||
@@ -553,12 +541,10 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
);
|
||||
unawaited(_reloadRegions());
|
||||
_deviceSn = widget.deviceSn.trim();
|
||||
if (_deviceSn.isEmpty) {
|
||||
_deviceSn = sl<DevicesCubit>().state.selectedDevice?.deviceName ?? '';
|
||||
if (_deviceSn.isEmpty && _devices.length == 1) {
|
||||
_deviceSn = _devices.single.deviceName;
|
||||
}
|
||||
}
|
||||
_returnDeviceSn = _deviceSn.isEmpty ? null : _deviceSn;
|
||||
unawaited(
|
||||
_loadEditorDevices().catchError((Object _) => <v2.DeviceEntity>[]),
|
||||
);
|
||||
unawaited(
|
||||
_restoreDraft().then((_) async {
|
||||
if (!mounted) return;
|
||||
@@ -775,9 +761,8 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
return _fmtRectName(w, h);
|
||||
}
|
||||
|
||||
bool get _editingObstacles => _isReturnMode
|
||||
? _returnDropObstacle
|
||||
: _isDropPanel && _dropMode == 2;
|
||||
bool get _editingObstacles =>
|
||||
_isReturnMode ? _returnDropObstacle : _isDropPanel && _dropMode == 2;
|
||||
|
||||
List<List<LatLng>> get _activeObstacleHoles =>
|
||||
_isReturnMode ? _returnObstacleHoles : _obstacleHoles;
|
||||
@@ -1444,43 +1429,279 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
}
|
||||
}
|
||||
|
||||
// ================= 一键返航(返航点打点:界面 + 本地暂存,接口待接入)=================
|
||||
// ================= 一键返航:设置保存后,由执行按钮下发 =================
|
||||
|
||||
/// 设备列表(取不到就当空,不让页面挂掉)
|
||||
List<DeviceEntity> get _devices {
|
||||
Future<List<v2.DeviceEntity>> _loadEditorDevices() async {
|
||||
final siteId = sl<SiteCubit>().state.selectedSite?.id;
|
||||
if (siteId == null || siteId != _draftSiteId) {
|
||||
throw StateError(_l10n.translate('region_editor.site_changed'));
|
||||
}
|
||||
final devices = await sl<GetSiteDevicesUseCase>()(siteId);
|
||||
final unique = <String, v2.DeviceEntity>{
|
||||
for (final device in devices)
|
||||
if (device.name.trim().isNotEmpty &&
|
||||
(device.siteId == null || device.siteId == siteId))
|
||||
device.name: device,
|
||||
};
|
||||
final result = unique.values.toList();
|
||||
if (mounted && sl<SiteCubit>().state.selectedSite?.id == siteId) {
|
||||
setState(() {
|
||||
_siteDevices = result;
|
||||
_siteDevicesSiteId = siteId;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> _selectEditorDevice() async {
|
||||
if (!_draftLoaded || _savingReturn || _executingReturn) return;
|
||||
if (widget.deviceSn.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_returnDeviceSn = widget.deviceSn.trim();
|
||||
_alignReturnDevice();
|
||||
});
|
||||
_showReturnEntryHint();
|
||||
return;
|
||||
}
|
||||
final siteId = sl<SiteCubit>().state.selectedSite?.id;
|
||||
var request = _loadEditorDevices();
|
||||
final selected = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, updateDialog) => AlertDialog(
|
||||
title: Text(_l10n.translate('region_editor.choose_device')),
|
||||
content: SizedBox(
|
||||
width: 360,
|
||||
height: (MediaQuery.sizeOf(context).height * 0.45).clamp(
|
||||
100.0,
|
||||
240.0,
|
||||
),
|
||||
child: FutureBuilder<List<v2.DeviceEntity>>(
|
||||
future: request,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(ErrorHandler.getErrorMessage(snapshot.error!)),
|
||||
TextButton(
|
||||
onPressed: () => updateDialog(() {
|
||||
request = _loadEditorDevices();
|
||||
}),
|
||||
child: Text(
|
||||
_l10n.translate('region_editor.return_retry'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
final devices = snapshot.data ?? const <v2.DeviceEntity>[];
|
||||
if (devices.isEmpty) {
|
||||
return Center(
|
||||
child: Text(_l10n.translate('region_editor.devices_empty')),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: devices.length,
|
||||
itemBuilder: (context, index) {
|
||||
final device = devices[index];
|
||||
return ListTile(
|
||||
title: Text(
|
||||
device.deviceAlias?.trim().isNotEmpty == true
|
||||
? device.deviceAlias!
|
||||
: device.name,
|
||||
),
|
||||
subtitle: Text(device.name),
|
||||
trailing: device.name == _deviceSn
|
||||
? const Icon(Icons.check_rounded, color: kWtBlue)
|
||||
: null,
|
||||
onTap: () => Navigator.of(dialogContext).pop(device.name),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: Text(_l10n.translate('common.cancel')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!mounted || selected == null) return;
|
||||
if (sl<SiteCubit>().state.selectedSite?.id != siteId) {
|
||||
_toast(_l10n.translate('region_editor.site_changed'));
|
||||
return;
|
||||
}
|
||||
await _changeEditorDevice(selected);
|
||||
if (mounted && _isReturnMode) _showReturnEntryHint();
|
||||
}
|
||||
|
||||
void _alignReturnDevice() {
|
||||
final sn = _returnDeviceSn;
|
||||
if (sn == null || sn.isEmpty) return;
|
||||
for (var i = 0; i < _returnPoints.length; i++) {
|
||||
if (_returnPoints[i].deviceSn == sn) continue;
|
||||
_returnPoints[i] = _returnPoints[i].copyWith(
|
||||
deviceSn: sn,
|
||||
deviceLabel: _labelOfDevice(sn),
|
||||
);
|
||||
_returnSaved = false;
|
||||
}
|
||||
}
|
||||
|
||||
String get _returnSignature => jsonEncode({
|
||||
'device': _returnDeviceSn,
|
||||
'points': [
|
||||
for (final p in _returnPoints)
|
||||
[p.point.latitude, p.point.longitude, p.deviceSn, p.alias],
|
||||
],
|
||||
'obstacles': [for (final hole in _returnObstacleHoles) _pointsJson(hole)],
|
||||
'names': _returnObstacleNames,
|
||||
'sizes': [
|
||||
for (final size in _returnObstacleSizes) [size.$1, size.$2],
|
||||
],
|
||||
});
|
||||
|
||||
String get _returnEntryHint => (_returnDeviceSn ?? '').isEmpty
|
||||
? _l10n.translate('region_editor.return_entry_unselected')
|
||||
: _l10n.translate('region_editor.return_entry_device', {
|
||||
'device': _labelOfDevice(_returnDeviceSn),
|
||||
});
|
||||
|
||||
void _showReturnEntryHint() => _toast(_returnEntryHint);
|
||||
|
||||
Future<void> _showReturnGuide() async {
|
||||
_returnGuideOpen = true;
|
||||
try {
|
||||
return sl<DevicesCubit>().state.devices;
|
||||
} catch (_) {
|
||||
return const <DeviceEntity>[];
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
backgroundColor: Colors.white,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
insetPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 16,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
scrollable: true,
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.u_turn_left_rounded, color: kWtBlue, size: 22),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_l10n.translate('region_editor.return_guide_title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: kWtNavy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: SizedBox(
|
||||
width: 360,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: kWtSoftBlue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (var step = 1; step <= 3; step++) ...[
|
||||
if (step > 1) const SizedBox(height: 12),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 11,
|
||||
backgroundColor: kWtBlue,
|
||||
child: Text(
|
||||
'$step',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_l10n.translate(
|
||||
'region_editor.return_guide_step_$step',
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.5,
|
||||
color: kWtNavy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: kWtBlue,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: Text(
|
||||
_l10n.translate('region_editor.return_guide_confirm'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
_returnGuideOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 设备下拉项:(deviceSn, 展示名),展示名优先别名
|
||||
List<(String, String)> get _deviceOptions {
|
||||
final options = <(String, String)>[
|
||||
for (final device in _devices)
|
||||
(
|
||||
device.deviceName,
|
||||
(device.deviceAlias?.trim().isNotEmpty ?? false)
|
||||
? device.deviceAlias!.trim()
|
||||
: device.deviceName,
|
||||
),
|
||||
if (_siteDevicesSiteId == _draftSiteId)
|
||||
for (final device in _siteDevices)
|
||||
(
|
||||
device.name,
|
||||
(device.deviceAlias?.trim().isNotEmpty ?? false)
|
||||
? device.deviceAlias!.trim()
|
||||
: device.name,
|
||||
),
|
||||
];
|
||||
if (options.isEmpty && _deviceSn.isNotEmpty) {
|
||||
if (_deviceSn.isNotEmpty && !options.any((item) => item.$1 == _deviceSn)) {
|
||||
options.add((_deviceSn, _deviceSn));
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
/// 把某点已绑定的设备补进选项(设备被解绑时仍能显示原名)
|
||||
List<(String, String)> _deviceOptionsFor(String? sn, String label) {
|
||||
final options = _deviceOptions;
|
||||
if (sn == null || sn.isEmpty || options.any((item) => item.$1 == sn)) {
|
||||
return options;
|
||||
}
|
||||
return <(String, String)>[...options, (sn, label.isEmpty ? sn : label)];
|
||||
}
|
||||
|
||||
String _labelOfDevice(String? sn) {
|
||||
if (sn == null || sn.isEmpty) return '';
|
||||
for (final (value, label) in _deviceOptions) {
|
||||
@@ -1494,13 +1715,7 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
];
|
||||
|
||||
String get _returnHint {
|
||||
if (_returnPoints.isEmpty) {
|
||||
return _l10n.translate('region_editor.return_mark_hint', {
|
||||
'mode': _robotMode == RobotMode.point
|
||||
? _l10n.translate('region_editor.crosshair')
|
||||
: _l10n.translate('region_editor.device'),
|
||||
});
|
||||
}
|
||||
if (_returnPoints.isEmpty) return _returnEntryHint;
|
||||
final int bound = _returnPoints
|
||||
.where((point) => (point.deviceSn ?? '').isNotEmpty)
|
||||
.length;
|
||||
@@ -1518,11 +1733,20 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
/// - 无 → 直接进空白编辑器 = 新建态(按钮「保存」,不带 id)
|
||||
/// 查询以服务器为准,会覆盖本地缓存的返航点;查询失败则保留当前内容不误判为空。
|
||||
Future<void> _enterReturnMode() async {
|
||||
if (_returnGuideOpen || _returnLoading || _savingReturn || _executingReturn) {
|
||||
return;
|
||||
}
|
||||
final siteId = sl<SiteCubit>().state.selectedSite?.id;
|
||||
if (siteId == null) {
|
||||
_toast(_l10n.translate('region_editor.select_site_first'));
|
||||
return;
|
||||
}
|
||||
await _showReturnGuide();
|
||||
if (!mounted) return;
|
||||
if (sl<SiteCubit>().state.selectedSite?.id != siteId) {
|
||||
_toast(_l10n.translate('region_editor.site_changed'));
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_isReturnMode = true;
|
||||
_isListOpen = false;
|
||||
@@ -1533,10 +1757,7 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
_returnLoading = true;
|
||||
_isReturnListOpen = false;
|
||||
_pendingReturnDraft = null;
|
||||
if (_returnDeviceSn == null) {
|
||||
final options = _deviceOptions;
|
||||
if (options.isNotEmpty) _returnDeviceSn = options.first.$1;
|
||||
}
|
||||
_returnDeviceSn = _deviceSn.isEmpty ? null : _deviceSn;
|
||||
});
|
||||
final result = await sl<AutonomousWorkGateway>().fetchReturnPlanBySiteId(
|
||||
siteId: siteId,
|
||||
@@ -1579,7 +1800,7 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
_returnDropObstacle = false;
|
||||
});
|
||||
_persistDraft();
|
||||
_toast(_l10n.translate('region_editor.return_new_hint'));
|
||||
_showReturnEntryHint();
|
||||
}
|
||||
|
||||
/// 选中列表里那条方案:直接回填已拉到的几何 = 修改态(按钮「修改」,带 id)
|
||||
@@ -1590,11 +1811,17 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
_applyReturnDraft(draft);
|
||||
_returnPlanId = draft.id;
|
||||
_returnSaved = true;
|
||||
_alignReturnDevice();
|
||||
_isReturnListOpen = false;
|
||||
_returnDropObstacle = false;
|
||||
_regionFocusPoints = [
|
||||
..._returnLatLngs,
|
||||
for (final hole in _returnObstacleHoles) ...hole,
|
||||
];
|
||||
_regionFocusSignal++;
|
||||
});
|
||||
_persistDraft();
|
||||
_toast(_l10n.translate('region_editor.return_edit_hint'));
|
||||
_showReturnEntryHint();
|
||||
}
|
||||
|
||||
/// 把服务器方案回填到编辑器:返航点(含绑定设备/自定义名)+ 障碍矩形。
|
||||
@@ -1752,7 +1979,7 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
if (index < 0 || index >= _returnPoints.length) return;
|
||||
setState(() {
|
||||
_returnPoints.removeAt(index);
|
||||
if (_returnPoints.isEmpty) _returnSaved = false;
|
||||
_returnSaved = false;
|
||||
});
|
||||
_toast(
|
||||
_l10n.translate('region_editor.return_point_canceled', {
|
||||
@@ -1768,7 +1995,7 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
}
|
||||
setState(() {
|
||||
_returnPoints.removeLast();
|
||||
if (_returnPoints.isEmpty) _returnSaved = false;
|
||||
_returnSaved = false;
|
||||
});
|
||||
_toast(
|
||||
_l10n.translate('region_editor.return_point_undone', {
|
||||
@@ -1777,17 +2004,6 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
);
|
||||
}
|
||||
|
||||
void _setReturnPointDevice(int index, String sn) {
|
||||
if (index < 0 || index >= _returnPoints.length) return;
|
||||
setState(() {
|
||||
_returnPoints[index] = _returnPoints[index].copyWith(
|
||||
deviceSn: sn,
|
||||
deviceLabel: _labelOfDevice(sn),
|
||||
);
|
||||
_returnSaved = false;
|
||||
});
|
||||
}
|
||||
|
||||
/// 返航点显示名:自定义优先,否则「返航点-XX」
|
||||
String _returnPointDisplay(int index) {
|
||||
final name = _returnPoints[index].alias?.trim() ?? '';
|
||||
@@ -1874,7 +2090,7 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
/// 经 [AutonomousWorkGateway.saveReturnPlan] 落库(/system/siteMapInfo/save)。
|
||||
/// 页面只取几何、不拼任何后端字段(报文日志在网关里打印)。
|
||||
Future<void> _saveReturnPlan() async {
|
||||
if (_savingReturn) return;
|
||||
if (_savingReturn || _executingReturn) return;
|
||||
if (_returnPoints.isEmpty && _returnObstacleHoles.isEmpty) {
|
||||
_toast(_l10n.translate('region_editor.add_return_points_first'));
|
||||
return;
|
||||
@@ -1889,6 +2105,11 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((_returnDeviceSn ?? '').isEmpty) {
|
||||
_toast(_l10n.translate('region_editor.return_select_device_first'));
|
||||
return;
|
||||
}
|
||||
_alignReturnDevice();
|
||||
final List<ReturnRestPoint> restPoints = <ReturnRestPoint>[
|
||||
for (int i = 0; i < _returnPoints.length; i++)
|
||||
ReturnRestPoint(
|
||||
@@ -1930,6 +2151,7 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
obstacles: obstacles,
|
||||
);
|
||||
|
||||
final savedSignature = _returnSignature;
|
||||
setState(() => _savingReturn = true);
|
||||
final result = await sl<AutonomousWorkGateway>().saveReturnPlan(draft);
|
||||
if (!mounted) return;
|
||||
@@ -1942,34 +2164,81 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_returnSaved = true;
|
||||
_returnSaved = savedSignature == _returnSignature;
|
||||
// 后端若回写主键则记住,下次保存走更新;否则保持 null
|
||||
if (result.data != null) _returnPlanId = result.data;
|
||||
});
|
||||
_persistDraft();
|
||||
CapsuleToast.show(
|
||||
_l10n.translate('region_editor.return_saved', {
|
||||
'points': restPoints.length,
|
||||
'obstacles': obstacles.isEmpty
|
||||
? ''
|
||||
: _l10n.translate('region_editor.obstacles_suffix', {
|
||||
'count': obstacles.length,
|
||||
}),
|
||||
}),
|
||||
_toast(
|
||||
_l10n.translate(
|
||||
_returnSaved
|
||||
? 'region_editor.return_ready_to_execute'
|
||||
: 'region_editor.return_save_before_execute',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 设备返航接口未开放,保留草稿,不模拟下发成功。
|
||||
/// 仅由执行按钮触发,保存不下发指令。
|
||||
Future<void> _executeReturnPlan() async {
|
||||
_persistDraft();
|
||||
_toast(_l10n.translate('region_editor.return_execute_unavailable'));
|
||||
if (_executingReturn || _savingReturn) return;
|
||||
final sn = _returnDeviceSn?.trim() ?? '';
|
||||
if (sn.isEmpty) {
|
||||
_toast(_l10n.translate('region_editor.return_select_device_first'));
|
||||
return;
|
||||
}
|
||||
if (!_returnSaved || !_returnPoints.any((p) => p.deviceSn == sn)) {
|
||||
_toast(_l10n.translate('region_editor.return_save_before_execute'));
|
||||
return;
|
||||
}
|
||||
final site = sl<SiteCubit>().state.selectedSite;
|
||||
if (site == null || site.id != _draftSiteId) {
|
||||
_toast(_l10n.translate('region_editor.site_changed'));
|
||||
return;
|
||||
}
|
||||
setState(() => _executingReturn = true);
|
||||
try {
|
||||
final devices = await _loadEditorDevices();
|
||||
if (!mounted) return;
|
||||
if (sl<SiteCubit>().state.selectedSite?.id != site.id) {
|
||||
_toast(_l10n.translate('region_editor.site_changed'));
|
||||
return;
|
||||
}
|
||||
v2.DeviceEntity? target;
|
||||
for (final device in devices) {
|
||||
if (device.name == sn) {
|
||||
target = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (target == null || target.orgId == null || target.siteId != site.id) {
|
||||
_toast(_l10n.translate('region_editor.return_device_scope_missing'));
|
||||
return;
|
||||
}
|
||||
if (_returnDeviceSn != sn || !_returnSaved) return;
|
||||
final result = await sl<BackToRestPointUseCase>()(
|
||||
BackToRestPointParams(
|
||||
deviceId: sn,
|
||||
orgId: target.orgId!,
|
||||
siteId: target.siteId!,
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
result.fold(
|
||||
(failure) => _toast(failure.message),
|
||||
(_) => _toast(_l10n.translate('region_editor.return_command_sent')),
|
||||
);
|
||||
} catch (error) {
|
||||
if (mounted) _toast(ErrorHandler.getErrorMessage(error));
|
||||
} finally {
|
||||
if (mounted) setState(() => _executingReturn = false);
|
||||
}
|
||||
}
|
||||
|
||||
/// 监控视频流:与路径规划同一套拼接(device/{sn}/live + 登录 token)
|
||||
String get _videoStreamUrl {
|
||||
final token = sl<AppUserCubit>().state.user?.token;
|
||||
if (_deviceSn.isEmpty || token == null) return '';
|
||||
return 'webrtc://${TCPConsts.TCP_IP}/live/livestream/'
|
||||
return 'webrtc://${EnvConfig.webRtcStreamAuthority}/live/livestream/'
|
||||
'$_deviceSn?token=$token';
|
||||
}
|
||||
|
||||
@@ -2310,7 +2579,7 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
draftPoints: _dropMode == 1 ? const <LatLng>[] : _markedPoints,
|
||||
// 禁行区矩形:返航模式画返航方案独立障碍,否则画圈地障碍(两者互不影响)
|
||||
draftHoles: _isReturnMode
|
||||
? _returnObstacleHoles
|
||||
? const <List<LatLng>>[]
|
||||
: _obstacleHoles,
|
||||
draftHolePoints: _currentObstaclePoints,
|
||||
draftPolygon: _dropMode != 1 && _robotMode == RobotMode.point
|
||||
@@ -2323,6 +2592,9 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
draftCrosshair: _dropMode != 1 && _robotMode == RobotMode.point,
|
||||
// 返航点:独立紫色图层(有数据就画,与圈地草稿互不影响)
|
||||
returnPoints: _returnLatLngs,
|
||||
returnObstacleHoles: _isReturnMode
|
||||
? _returnObstacleHoles
|
||||
: const <List<LatLng>>[],
|
||||
onCenterChanged: _onMapCenterChanged,
|
||||
onDevicePosition: (position) => _devicePos = position,
|
||||
),
|
||||
@@ -2543,13 +2815,10 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
}
|
||||
|
||||
Widget _deviceChip(_EL m) {
|
||||
return PopupMenuButton<String>(
|
||||
enabled: widget.deviceSn.isEmpty && _draftLoaded,
|
||||
onSelected: _changeEditorDevice,
|
||||
itemBuilder: (_) => [
|
||||
for (final (sn, label) in _deviceOptions)
|
||||
PopupMenuItem(value: sn, child: Text(label)),
|
||||
],
|
||||
return InkWell(
|
||||
onTap: widget.deviceSn.trim().isEmpty && _draftLoaded
|
||||
? _selectEditorDevice
|
||||
: null,
|
||||
child: Container(
|
||||
height: (24 * m.k).clamp(18.0, 24.0),
|
||||
constraints: BoxConstraints(maxWidth: (160 * m.k).clamp(96.0, 160.0)),
|
||||
@@ -3385,44 +3654,13 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 默认设备选择(只影响后加的点,已有可单点再改)
|
||||
/// 当前返航车辆,与顶栏和保存绑定保持一致。
|
||||
Widget _returnDeviceChip(_EL m) {
|
||||
final options = _deviceOptions;
|
||||
final String label = _returnDeviceSn == null
|
||||
? _l10n.translate('region_editor.choose_device')
|
||||
: _labelOfDevice(_returnDeviceSn);
|
||||
return PopupMenuButton<String>(
|
||||
tooltip: '',
|
||||
padding: EdgeInsets.zero,
|
||||
color: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
itemBuilder: (context) => <PopupMenuEntry<String>>[
|
||||
if (options.isEmpty)
|
||||
PopupMenuItem<String>(
|
||||
enabled: false,
|
||||
height: 34,
|
||||
child: Text(
|
||||
_l10n.translate('region_editor.devices_empty'),
|
||||
style: TextStyle(fontSize: m.fs(12), color: kWtGray),
|
||||
),
|
||||
),
|
||||
for (final (value, text) in options)
|
||||
PopupMenuItem<String>(
|
||||
value: value,
|
||||
height: 34,
|
||||
child: Text(
|
||||
text,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: m.fs(12),
|
||||
fontWeight: FontWeight.w600,
|
||||
color: kWtNavy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
onSelected: (value) => setState(() => _returnDeviceSn = value),
|
||||
return InkWell(
|
||||
onTap: _selectEditorDevice,
|
||||
child: Container(
|
||||
height: m.tiny ? 24.0 : (28 * m.k).clamp(24.0, 28.0),
|
||||
constraints: const BoxConstraints(maxWidth: 150),
|
||||
@@ -3854,39 +4092,8 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
/// 单点设备选择(点开列表选设备)
|
||||
Widget _returnPointDeviceSelector(_EL m, int index) {
|
||||
final point = _returnPoints[index];
|
||||
final options = _deviceOptionsFor(point.deviceSn, point.deviceLabel);
|
||||
return PopupMenuButton<String>(
|
||||
tooltip: '',
|
||||
padding: EdgeInsets.zero,
|
||||
color: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
itemBuilder: (context) => <PopupMenuEntry<String>>[
|
||||
if (options.isEmpty)
|
||||
PopupMenuItem<String>(
|
||||
enabled: false,
|
||||
height: 34,
|
||||
child: Text(
|
||||
_l10n.translate('region_editor.devices_empty'),
|
||||
style: TextStyle(fontSize: m.fs(12), color: kWtGray),
|
||||
),
|
||||
),
|
||||
for (final (value, text) in options)
|
||||
PopupMenuItem<String>(
|
||||
value: value,
|
||||
height: 34,
|
||||
child: Text(
|
||||
text,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: m.fs(12),
|
||||
fontWeight: FontWeight.w600,
|
||||
color: kWtNavy,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
onSelected: (value) => _setReturnPointDevice(index, value),
|
||||
return InkWell(
|
||||
onTap: _selectEditorDevice,
|
||||
child: Container(
|
||||
height: m.tiny ? 20.0 : 22.0,
|
||||
width: double.infinity,
|
||||
@@ -4041,7 +4248,11 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
SizedBox(width: (6 * m.k).clamp(4.0, 6.0)),
|
||||
_barButton(
|
||||
m,
|
||||
_l10n.translate('region_editor.execute'),
|
||||
_l10n.translate(
|
||||
_executingReturn
|
||||
? 'region_editor.return_sending'
|
||||
: 'region_editor.return_execute',
|
||||
),
|
||||
primary: true,
|
||||
icon: Icons.send_rounded,
|
||||
onPressed: _executeReturnPlan,
|
||||
@@ -4263,8 +4474,11 @@ class _RouteEditorPageV2State extends State<RouteEditorPageV2> {
|
||||
center: center,
|
||||
w: w,
|
||||
h: h,
|
||||
onOk: (double nw, double nh) =>
|
||||
_updateObstacle(corners, _rectCorners(center, nw, nh), forReturn: false),
|
||||
onOk: (double nw, double nh) => _updateObstacle(
|
||||
corners,
|
||||
_rectCorners(center, nw, nh),
|
||||
forReturn: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user