完善路线返航和障碍物显示
This commit is contained in:
@@ -2851,5 +2851,15 @@
|
||||
"route_type_inspection": "Inspection",
|
||||
"route_type_predefined": "Predefined mode",
|
||||
"route_type_other": "Other"
|
||||
},
|
||||
"perception_obstacle": {
|
||||
"bus": "Bus",
|
||||
"car": "Car",
|
||||
"motorcycle": "Motorcycle",
|
||||
"person": "Person",
|
||||
"truck": "Truck",
|
||||
"unknown": "Unknown obstacle",
|
||||
"distance": "Distance: {value} m",
|
||||
"confidence": "Confidence: {value}%"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2752,6 +2752,21 @@
|
||||
"return_save_failed": "返航方案保存失败",
|
||||
"return_saved": "返航方案已保存:{points} 个返航点{obstacles}",
|
||||
"obstacles_suffix": " · {count} 个障碍",
|
||||
"return_guide_title": "先配置,再执行返航",
|
||||
"return_guide_step_1": "确认设备,设置返航点",
|
||||
"return_guide_step_2": "按需添加或调整障碍物",
|
||||
"return_guide_step_3": "点击「保存/修改」,成功后再点「执行返航」",
|
||||
"return_guide_confirm": "知道了,开始配置",
|
||||
"return_entry_device": "当前设备:{device}。选点保存后,再点执行。",
|
||||
"return_entry_unselected": "先选设备,再选点保存,最后点执行。",
|
||||
"return_select_device_first": "请先选择返航设备",
|
||||
"return_save_before_execute": "请先保存当前返航设置",
|
||||
"return_ready_to_execute": "已保存,可执行返航",
|
||||
"return_device_scope_missing": "未获取到设备归属,请刷新后重试",
|
||||
"return_command_sent": "返航指令已下发",
|
||||
"return_sending": "下发中…",
|
||||
"return_execute": "执行返航",
|
||||
"return_retry": "重试",
|
||||
"return_execute_unavailable": "返航执行接口尚未接入,返航点已保留",
|
||||
"work_area_needs_three_points": "作业区域至少需要 3 个打点!",
|
||||
"save_area": "保存区域",
|
||||
@@ -2853,5 +2868,15 @@
|
||||
"route_type_inspection": "巡检任务",
|
||||
"route_type_predefined": "预定义模式",
|
||||
"route_type_other": "其他类型"
|
||||
},
|
||||
"perception_obstacle": {
|
||||
"bus": "公交车",
|
||||
"car": "汽车",
|
||||
"motorcycle": "摩托车",
|
||||
"person": "行人",
|
||||
"truck": "卡车",
|
||||
"unknown": "未知障碍物",
|
||||
"distance": "距离:{value} m",
|
||||
"confidence": "置信度:{value}%"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@ import '../env/env_config.dart';
|
||||
class HttpApiConsts {
|
||||
static String get baseUrl => EnvConfig.baseUrl;
|
||||
static String get handleDeviceAlarm => '$baseUrl/iot/alarm/handle';
|
||||
static String get siteDevicePlans => '$baseUrl/iot/deviceTask/getSiteDevicePlan';
|
||||
static String get siteDevicePlans =>
|
||||
'$baseUrl/iot/deviceTask/getSiteDevicePlan';
|
||||
static String get deleteDevicePlan => '$baseUrl/iot/deviceTask/delete';
|
||||
static String get siteDeviceTaskHistory =>
|
||||
'$baseUrl/iot/deviceTask/getSiteDeviceTaskHistory';
|
||||
static String get createConsecutiveTask =>
|
||||
'$baseUrl/iot/deviceTask/createConsecutiveTask';
|
||||
static String get backToRestPoint =>
|
||||
'$baseUrl/iot/deviceTask/backToRestPoint';
|
||||
static String get saveRegion => '$baseUrl/system/region/save';
|
||||
static String get regionsBySite => '$baseUrl/system/region/selectBySiteId';
|
||||
static String get deleteRegions => '$baseUrl/system/region/delete';
|
||||
|
||||
@@ -190,6 +190,7 @@ import '../../features/regions/domain/usecases/region_usecases.dart';
|
||||
import '../../features/regions/presentation/cubit/region_editor_cubit.dart';
|
||||
import '../../features/regions/presentation/cubit/region_list_cubit.dart';
|
||||
import '../../features/devices/domain/usecases/recovery_task_usecase.dart';
|
||||
import '../../features/devices/domain/usecases/back_to_rest_point_usecase.dart';
|
||||
import '../../features/devices/presentation/bloc/device_task_cubit.dart';
|
||||
import '../../features/autonomous_work/data/gateways/autonomous_work_gateway_factory.dart';
|
||||
import '../../features/autonomous_work/domain/repositories/autonomous_work_gateway.dart';
|
||||
@@ -742,6 +743,9 @@ Future<void> init() async {
|
||||
sl.registerLazySingleton(() => CancelTaskUseCase(sl()));
|
||||
sl.registerLazySingleton(() => PauseTaskUseCase(sl()));
|
||||
sl.registerLazySingleton(() => RecoveryTaskUseCase(sl()));
|
||||
sl.registerLazySingleton(
|
||||
() => BackToRestPointUseCase(sl<DeviceTaskRepository>()),
|
||||
);
|
||||
// 创建定时作业计划(作业计划页·新建 → POST /iot/deviceTask/save)
|
||||
sl.registerLazySingleton(() => SaveDeviceSchedulePlanUseCase(sl()));
|
||||
sl.registerFactory<SchedulePlanCreateCubit>(
|
||||
|
||||
@@ -21,6 +21,11 @@ class ErrorHandler {
|
||||
|
||||
/// 获取友好的错误消息
|
||||
static String _getFriendlyErrorMessage(Object error) {
|
||||
// Repository 的 Failure 保存的是字符串,保留其业务原因,避免一律变成“未知错误”。
|
||||
if (error is String) {
|
||||
final message = error.replaceFirst(RegExp(r'^Exception:\s*'), '').trim();
|
||||
return message.isEmpty ? '操作失败,请稍后重试' : message;
|
||||
}
|
||||
if (error is DioException) {
|
||||
switch (error.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../../domain/entities/mower_location_entity.dart';
|
||||
import '../../domain/entities/real_time_message_entity.dart';
|
||||
import '../../domain/entities/route_status_entity.dart';
|
||||
import '../../domain/entities/host_realtime_message_entity.dart';
|
||||
import '../../domain/entities/mower_obstacle_entity.dart';
|
||||
import '../../domain/entities/mower_task_status_entity.dart';
|
||||
|
||||
/// 割草机实时状态 MQTT 数据源(替代原 TCP 0x02 机器状态推送)
|
||||
@@ -16,6 +17,7 @@ import '../../domain/entities/mower_task_status_entity.dart';
|
||||
/// 订阅主题:
|
||||
/// - 车辆实时状态 mower/{sn}/property/realtime/post(1Hz,不含定位)
|
||||
/// - 高频定位 mower/{sn}/property/location/post(5-10Hz)
|
||||
/// - 障碍物感知 mower/{sn}/perception/obstacle/post(原始日志及地图目标)
|
||||
/// - 路径规划 device/{deviceId}/route/post(任务执行后推送覆盖清扫路线)
|
||||
abstract class MowerRealtimeDataSource {
|
||||
Stream<RealTimeMessageEntity> get vehicleStream;
|
||||
@@ -25,6 +27,8 @@ abstract class MowerRealtimeDataSource {
|
||||
/// 🔥 主机实时状态(device/{sn}/host/realTime/message,新增话题,纯附加)
|
||||
Stream<HostRealtimeMessageEntity> get hostRealtimeStream;
|
||||
|
||||
Stream<List<MowerObstacleEntity>> watchObstacles(String deviceSn);
|
||||
|
||||
Stream<MowerTaskStatusEntity> watchTaskStatus(String deviceSn);
|
||||
|
||||
/// 按设备观察概览所需的电量和控制模式,订阅随监听者释放。
|
||||
@@ -43,6 +47,7 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
|
||||
static const String _realtimeSuffix = 'property/realtime/post';
|
||||
static const String _locationSuffix = 'property/location/post';
|
||||
static const String _obstacleSuffix = 'perception/obstacle/post';
|
||||
static const String _routeSuffix = 'route/post';
|
||||
static const String _hostRealtimeSuffix = 'host/realTime/message';
|
||||
|
||||
@@ -63,6 +68,7 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
int _locationMsgCount = 0;
|
||||
int _routeMsgCount = 0;
|
||||
int _hostMsgCount = 0;
|
||||
int _obstacleMsgCount = 0;
|
||||
|
||||
MowerRealtimeDataSourceImpl(this.mqttClient);
|
||||
|
||||
@@ -81,6 +87,7 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
|
||||
String _realtimeTopic(String sn) => 'mower/$sn/$_realtimeSuffix';
|
||||
String _locationTopic(String sn) => 'mower/$sn/$_locationSuffix';
|
||||
String _obstacleTopic(String sn) => 'mower/$sn/$_obstacleSuffix';
|
||||
String _routeTopic(String sn) => 'device/$sn/$_routeSuffix';
|
||||
String _hostRealtimeTopic(String sn) => 'device/$sn/$_hostRealtimeSuffix';
|
||||
|
||||
@@ -139,6 +146,98 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<MowerObstacleEntity>> watchObstacles(String deviceSn) {
|
||||
final sn = deviceSn.trim();
|
||||
final messages = mqttClient.messageStream;
|
||||
if (sn.isEmpty || messages == null) return const Stream.empty();
|
||||
|
||||
final topic = _obstacleTopic(sn);
|
||||
StreamSubscription<MqttMessage>? messageSubscription;
|
||||
Future<void>? topicSubscription;
|
||||
Timer? staleTimer;
|
||||
late final StreamController<List<MowerObstacleEntity>> controller;
|
||||
|
||||
void clearObstacles() {
|
||||
staleTimer?.cancel();
|
||||
if (!controller.isClosed) controller.add(const []);
|
||||
}
|
||||
|
||||
controller = StreamController<List<MowerObstacleEntity>>(
|
||||
onListen: () {
|
||||
// 地图独立按 SN 订阅,不依赖全局当前设备;先接收再订阅以接住首帧。
|
||||
messageSubscription = messages
|
||||
.where((msg) => msg.topic == topic)
|
||||
.listen(
|
||||
(message) {
|
||||
try {
|
||||
final json = jsonDecode(message.payload);
|
||||
if (json is! Map || json['data'] is! Map) return;
|
||||
final payloadSn = json['sn']?.toString();
|
||||
if (payloadSn != null && payloadSn != sn) return;
|
||||
final data = json['data'] as Map;
|
||||
if (data['fusion_status'] != 'valid' ||
|
||||
data['obstacle_status'] != 'detected' ||
|
||||
data['object_count'] == 0) {
|
||||
clearObstacles();
|
||||
return;
|
||||
}
|
||||
final objects = data['objects'];
|
||||
if (objects is! List) return;
|
||||
final obstacles = <MowerObstacleEntity>[];
|
||||
for (final object in objects) {
|
||||
if (object is! Map) continue;
|
||||
final obstacle = MowerObstacleEntity.tryParse(object);
|
||||
if (obstacle != null) obstacles.add(obstacle);
|
||||
}
|
||||
controller.add(
|
||||
List<MowerObstacleEntity>.unmodifiable(obstacles),
|
||||
);
|
||||
staleTimer?.cancel();
|
||||
// 与设备数据监控的 15 秒超时一致,断流后移除旧目标。
|
||||
staleTimer = Timer(
|
||||
const Duration(seconds: 15),
|
||||
clearObstacles,
|
||||
);
|
||||
} on FormatException catch (error) {
|
||||
debugPrint('[MQTT-障碍物] 报文解析失败 $topic: $error');
|
||||
}
|
||||
},
|
||||
onError: (Object error, StackTrace stackTrace) {
|
||||
clearObstacles();
|
||||
controller.addError(error, stackTrace);
|
||||
},
|
||||
onDone: () {
|
||||
staleTimer?.cancel();
|
||||
controller.close();
|
||||
},
|
||||
);
|
||||
debugPrint('[MQTT-障碍物] 地图订阅: $topic');
|
||||
topicSubscription = mqttClient.subscribe(topic).catchError((
|
||||
Object error,
|
||||
StackTrace stackTrace,
|
||||
) {
|
||||
debugPrint('[MQTT-障碍物] 地图订阅失败 $topic: $error');
|
||||
if (!controller.isClosed) controller.addError(error, stackTrace);
|
||||
});
|
||||
},
|
||||
onCancel: () async {
|
||||
staleTimer?.cancel();
|
||||
await messageSubscription?.cancel();
|
||||
final subscription = topicSubscription;
|
||||
if (subscription == null) return;
|
||||
await subscription;
|
||||
try {
|
||||
// 客户端引用计数保证关闭一个地图不会退掉其他地图/详情页的订阅。
|
||||
await mqttClient.unsubscribe(topic);
|
||||
} catch (error) {
|
||||
debugPrint('[MQTT-障碍物] 释放地图订阅失败 $topic: $error');
|
||||
}
|
||||
},
|
||||
);
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<({double? battery, String controlMode})> watchOverviewStatus(
|
||||
String deviceSn,
|
||||
@@ -226,6 +325,7 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
await mqttClient.unsubscribe(_locationTopic(_deviceSn!));
|
||||
await mqttClient.unsubscribe(_routeTopic(_deviceSn!));
|
||||
await mqttClient.unsubscribe(_hostRealtimeTopic(_deviceSn!));
|
||||
await mqttClient.unsubscribe(_obstacleTopic(_deviceSn!));
|
||||
debugPrint(
|
||||
'${LogTime.now()} 🔕 [MowerRealtimeDataSource] 已退订旧设备: $_deviceSn',
|
||||
);
|
||||
@@ -236,6 +336,7 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
_locationMsgCount = 0;
|
||||
_routeMsgCount = 0;
|
||||
_hostMsgCount = 0;
|
||||
_obstacleMsgCount = 0;
|
||||
|
||||
// 先监听消息,接住订阅后立即到达的推送(包括 retained 消息)。
|
||||
_subscription ??= mqttClient.messageStream?.listen(_handleMessage);
|
||||
@@ -244,6 +345,7 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
await mqttClient.subscribe(_locationTopic(deviceSn));
|
||||
await mqttClient.subscribe(_routeTopic(deviceSn));
|
||||
await mqttClient.subscribe(_hostRealtimeTopic(deviceSn));
|
||||
await mqttClient.subscribe(_obstacleTopic(deviceSn));
|
||||
|
||||
debugPrint(
|
||||
'${LogTime.now()} ✅ [MowerRealtimeDataSource] 开始监听设备: $deviceSn',
|
||||
@@ -252,6 +354,7 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
debugPrint(' 定位: ${_locationTopic(deviceSn)}');
|
||||
debugPrint(' 路径规划: ${_routeTopic(deviceSn)}');
|
||||
debugPrint(' 主机实时: ${_hostRealtimeTopic(deviceSn)}');
|
||||
debugPrint(' 障碍物感知: ${_obstacleTopic(deviceSn)}');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -262,6 +365,7 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
await mqttClient.unsubscribe(_locationTopic(_deviceSn!));
|
||||
await mqttClient.unsubscribe(_routeTopic(_deviceSn!));
|
||||
await mqttClient.unsubscribe(_hostRealtimeTopic(_deviceSn!));
|
||||
await mqttClient.unsubscribe(_obstacleTopic(_deviceSn!));
|
||||
debugPrint(
|
||||
'${LogTime.now()} 🔕 [MowerRealtimeDataSource] 停止监听设备: $_deviceSn',
|
||||
);
|
||||
@@ -272,6 +376,19 @@ class MowerRealtimeDataSourceImpl implements MowerRealtimeDataSource {
|
||||
final sn = _deviceSn;
|
||||
if (sn == null || sn.isEmpty) return;
|
||||
|
||||
// 协议待确认:逐帧输出原始 payload,不预设 JSON 结构或经纬度字段。
|
||||
if (message.topic == _obstacleTopic(sn)) {
|
||||
_obstacleMsgCount++;
|
||||
// debugPrint(
|
||||
// '${LogTime.now()} [MQTT-障碍物] 第$_obstacleMsgCount帧 topic: ${message.topic}',
|
||||
// );
|
||||
// debugPrint('[MQTT-障碍物] payload 开始');
|
||||
// 长报文分行打印,避免单行超过设备日志长度限制。
|
||||
// debugPrint(message.payload, wrapWidth: 800);
|
||||
// debugPrint('[MQTT-障碍物] payload 结束');
|
||||
return;
|
||||
}
|
||||
|
||||
// 🔥 防串台:只处理当前监听设备的主题(mower/ 和 device/ 前缀都要匹配)
|
||||
if (!message.topic.contains('mower/$sn/') &&
|
||||
!message.topic.contains('device/$sn/'))
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../../domain/entities/mower_location_entity.dart';
|
||||
import '../../domain/entities/real_time_message_entity.dart';
|
||||
import '../../domain/entities/route_status_entity.dart';
|
||||
import '../../domain/entities/host_realtime_message_entity.dart';
|
||||
import '../../domain/entities/mower_obstacle_entity.dart';
|
||||
import '../../domain/entities/mower_task_status_entity.dart';
|
||||
|
||||
class MowerRealtimeRepositoryImpl implements MowerRealtimeRepository {
|
||||
@@ -29,6 +30,10 @@ class MowerRealtimeRepositoryImpl implements MowerRealtimeRepository {
|
||||
Stream<HostRealtimeMessageEntity> get hostRealtimeStream =>
|
||||
dataSource.hostRealtimeStream;
|
||||
|
||||
@override
|
||||
Stream<List<MowerObstacleEntity>> watchObstacles(String deviceSn) =>
|
||||
dataSource.watchObstacles(deviceSn);
|
||||
|
||||
@override
|
||||
Stream<MowerTaskStatusEntity> watchTaskStatus(String deviceSn) =>
|
||||
dataSource.watchTaskStatus(deviceSn);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/// mower/{sn}/perception/obstacle/post 中的单个感知目标。
|
||||
/// class_id 是类别依据;x/y/z 为设备局部坐标,地图只使用经纬度。
|
||||
class MowerObstacleEntity {
|
||||
const MowerObstacleEntity({
|
||||
required this.classId,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
this.trackId,
|
||||
this.confidence,
|
||||
this.distance,
|
||||
});
|
||||
|
||||
final int classId;
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
final int? trackId;
|
||||
final double? confidence;
|
||||
final double? distance;
|
||||
|
||||
/// 协议定义:0 bus / 1 car / 2 motorcycle / 3 person / 4 truck。
|
||||
String get categoryKey => switch (classId) {
|
||||
0 => 'bus',
|
||||
1 => 'car',
|
||||
2 => 'motorcycle',
|
||||
3 => 'person',
|
||||
4 => 'truck',
|
||||
_ => 'unknown',
|
||||
};
|
||||
|
||||
static MowerObstacleEntity? tryParse(Map<dynamic, dynamic> json) {
|
||||
final lat = _number(json['latitude']);
|
||||
final lng = _number(json['longitude']);
|
||||
if (lat == null ||
|
||||
lng == null ||
|
||||
lat.abs() > 90 ||
|
||||
lng.abs() > 180 ||
|
||||
(lat == 0 && lng == 0)) {
|
||||
return null;
|
||||
}
|
||||
return MowerObstacleEntity(
|
||||
classId: _number(json['class_id'])?.toInt() ?? -1,
|
||||
latitude: lat,
|
||||
longitude: lng,
|
||||
trackId: _number(json['track_id'])?.toInt(),
|
||||
confidence: _number(json['confidence']),
|
||||
distance: _number(json['distance']),
|
||||
);
|
||||
}
|
||||
|
||||
static double? _number(dynamic value) {
|
||||
final number = value is num
|
||||
? value.toDouble()
|
||||
: double.tryParse(value?.toString() ?? '');
|
||||
return number != null && number.isFinite ? number : null;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import '../entities/mower_location_entity.dart';
|
||||
import '../entities/real_time_message_entity.dart';
|
||||
import '../entities/route_status_entity.dart';
|
||||
import '../entities/host_realtime_message_entity.dart';
|
||||
import '../entities/mower_obstacle_entity.dart';
|
||||
import '../entities/mower_task_status_entity.dart';
|
||||
|
||||
abstract class MowerRealtimeRepository {
|
||||
@@ -14,6 +15,9 @@ abstract class MowerRealtimeRepository {
|
||||
Stream<RouteStatusEntity> get routeStatusStream;
|
||||
Stream<HostRealtimeMessageEntity> get hostRealtimeStream;
|
||||
|
||||
/// 按地图使用的设备 SN 订阅感知目标,取消监听时释放该主题引用。
|
||||
Stream<List<MowerObstacleEntity>> watchObstacles(String deviceSn);
|
||||
|
||||
/// 原始任务状态流,由场站共享订阅管理器维护其主题引用。
|
||||
Stream<MowerTaskStatusEntity> watchTaskStatus(String deviceSn);
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@ import '../../domain/entities/device_schedule_plan_entity.dart';
|
||||
import '../models/device_task_model.dart';
|
||||
|
||||
abstract class DeviceTaskDatasource {
|
||||
Future<void> backToRestPoint({
|
||||
required String deviceId,
|
||||
required int orgId,
|
||||
required int siteId,
|
||||
});
|
||||
|
||||
Future<List<DeviceTaskModel>> getDeviceTaskPool({
|
||||
required String userId,
|
||||
required int siteId,
|
||||
@@ -48,6 +54,50 @@ class DeviceTaskDatasourceImpl implements DeviceTaskDatasource {
|
||||
|
||||
DeviceTaskDatasourceImpl(this.dio);
|
||||
|
||||
@override
|
||||
Future<void> backToRestPoint({
|
||||
required String deviceId,
|
||||
required int orgId,
|
||||
required int siteId,
|
||||
}) async {
|
||||
final body = {
|
||||
'deviceId': deviceId,
|
||||
'orgId': orgId,
|
||||
'siteId': siteId,
|
||||
};
|
||||
final url = HttpApiConsts.backToRestPoint;
|
||||
_logger.logWithLevel(
|
||||
'[机器人返航] 请求: POST $url, 参数: ${jsonEncode(body)}',
|
||||
shouldLog: true,
|
||||
);
|
||||
final response = await dio.post(
|
||||
url,
|
||||
data: body,
|
||||
options: Options(contentType: Headers.jsonContentType),
|
||||
);
|
||||
dynamic data = response.data;
|
||||
if (data is String) {
|
||||
try {
|
||||
data = jsonDecode(data);
|
||||
} on FormatException {
|
||||
throw Exception('返航接口响应格式异常');
|
||||
}
|
||||
}
|
||||
if (response.statusCode != 200 || data is! Map) {
|
||||
throw Exception('返航请求失败(HTTP ${response.statusCode})');
|
||||
}
|
||||
if ('${data['code']}' != '200') {
|
||||
final message = (data['msg'] ?? data['message'])?.toString().trim();
|
||||
throw Exception(
|
||||
message == null || message.isEmpty ? '返航请求未成功' : message,
|
||||
);
|
||||
}
|
||||
if (data['data'] == false) {
|
||||
throw Exception('返航请求未成功,请确认车辆状态后重试');
|
||||
}
|
||||
_logger.logWithLevel('[机器人返航] 服务端已接受请求', shouldLog: true);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DeviceTaskModel>> getDeviceTaskPool({
|
||||
required String userId,
|
||||
|
||||
@@ -10,6 +10,24 @@ class DeviceTaskRepositoryImpl implements DeviceTaskRepository {
|
||||
|
||||
DeviceTaskRepositoryImpl({required this.datasource});
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Unit>> backToRestPoint({
|
||||
required String deviceId,
|
||||
required int orgId,
|
||||
required int siteId,
|
||||
}) async {
|
||||
try {
|
||||
await datasource.backToRestPoint(
|
||||
deviceId: deviceId,
|
||||
orgId: orgId,
|
||||
siteId: siteId,
|
||||
);
|
||||
return const Right(unit);
|
||||
} catch (error) {
|
||||
return Left(Failure(error.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<DeviceTaskEntity>>> getDeviceTaskPool({
|
||||
required String userId,
|
||||
|
||||
@@ -4,6 +4,14 @@ import '../entities/device_schedule_plan_entity.dart';
|
||||
import '../entities/device_task_entity.dart';
|
||||
|
||||
abstract class DeviceTaskRepository {
|
||||
/// 请求车辆返航。deviceId 为车辆 SN,orgId/siteId 为这台车的归属。
|
||||
/// 成功仅表示服务端接受请求,不表示车辆已经完成返航。
|
||||
Future<Either<Failure, Unit>> backToRestPoint({
|
||||
required String deviceId,
|
||||
required int orgId,
|
||||
required int siteId,
|
||||
});
|
||||
|
||||
/// 获取设备任务池列表
|
||||
Future<Either<Failure, List<DeviceTaskEntity>>> getDeviceTaskPool({
|
||||
required String userId,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
|
||||
import '../../../../core/domain/usecases/base_usecase.dart';
|
||||
import '../../../../core/error/failure.dart';
|
||||
import '../repositories/device_task_repository.dart';
|
||||
|
||||
class BackToRestPointUseCase
|
||||
implements BaseUseCase<Unit, BackToRestPointParams> {
|
||||
BackToRestPointUseCase(this.repository);
|
||||
|
||||
final DeviceTaskRepository repository;
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Unit>> call(BackToRestPointParams params) {
|
||||
final sn = params.deviceId.trim();
|
||||
if (sn.isEmpty) {
|
||||
return Future.value(Left(Failure('车辆 SN 不能为空')));
|
||||
}
|
||||
if (params.orgId <= 0 || params.siteId <= 0) {
|
||||
return Future.value(Left(Failure('请确认车辆所属的组织和场站')));
|
||||
}
|
||||
return repository.backToRestPoint(
|
||||
deviceId: sn,
|
||||
orgId: params.orgId,
|
||||
siteId: params.siteId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 由调用方明确传入目标车辆的归属,不从当前登录人或全局场站推断。
|
||||
class BackToRestPointParams {
|
||||
const BackToRestPointParams({
|
||||
required this.deviceId,
|
||||
required this.orgId,
|
||||
required this.siteId,
|
||||
});
|
||||
|
||||
/// 车辆 SN 编码,不是设备数据库数字主键。
|
||||
final String deviceId;
|
||||
final int orgId;
|
||||
final int siteId;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/localization/app_localizations.dart';
|
||||
import '../../../../core/network/mqtt/domain/entities/mower_obstacle_entity.dart';
|
||||
import '../../../../core/network/mqtt/domain/repositories/mower_realtime_repository.dart';
|
||||
|
||||
/// 三处业务地图共用的实时感知层,生命周期与地图一致。
|
||||
class MowerObstacleLayer extends StatefulWidget {
|
||||
const MowerObstacleLayer({super.key, required this.deviceSn});
|
||||
|
||||
final String deviceSn;
|
||||
|
||||
@override
|
||||
State<MowerObstacleLayer> createState() => _MowerObstacleLayerState();
|
||||
}
|
||||
|
||||
class _MowerObstacleLayerState extends State<MowerObstacleLayer> {
|
||||
late Stream<List<MowerObstacleEntity>> _stream = _watchObstacles();
|
||||
|
||||
Stream<List<MowerObstacleEntity>> _watchObstacles() {
|
||||
final sn = widget.deviceSn.trim();
|
||||
return sn.isEmpty
|
||||
? const Stream.empty()
|
||||
: sl<MowerRealtimeRepository>().watchObstacles(sn);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant MowerObstacleLayer oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.deviceSn.trim() != widget.deviceSn.trim()) {
|
||||
_stream = _watchObstacles();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
return StreamBuilder<List<MowerObstacleEntity>>(
|
||||
// 换设备后丢弃旧快照,等待新设备的首帧。
|
||||
key: ValueKey(widget.deviceSn.trim()),
|
||||
stream: _stream,
|
||||
builder: (context, snapshot) {
|
||||
final objects = snapshot.hasError
|
||||
? const <MowerObstacleEntity>[]
|
||||
: snapshot.data ?? const <MowerObstacleEntity>[];
|
||||
return MarkerLayer(
|
||||
markers: [
|
||||
for (final object in objects)
|
||||
Marker(
|
||||
point: LatLng(object.latitude, object.longitude),
|
||||
width: 36,
|
||||
height: 36,
|
||||
child: _marker(object, l10n),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _marker(MowerObstacleEntity object, AppLocalizations l10n) {
|
||||
final (icon, color) = switch (object.classId) {
|
||||
0 => (Icons.directions_bus, const Color(0xFF7C3AED)),
|
||||
1 => (Icons.directions_car, const Color(0xFF1677FF)),
|
||||
2 => (Icons.two_wheeler, const Color(0xFFEA580C)),
|
||||
3 => (Icons.person, const Color(0xFFE11D48)),
|
||||
4 => (Icons.local_shipping, const Color(0xFF0D9488)),
|
||||
_ => (Icons.warning_amber_rounded, const Color(0xFF64748B)),
|
||||
};
|
||||
final category = l10n.translate('perception_obstacle.${object.categoryKey}');
|
||||
final title = object.trackId == null
|
||||
? category
|
||||
: '$category #${object.trackId}';
|
||||
final details = <String>[
|
||||
title,
|
||||
if (object.distance != null && object.distance! >= 0)
|
||||
l10n.translate('perception_obstacle.distance', {
|
||||
'value': object.distance!.toStringAsFixed(1),
|
||||
}),
|
||||
if (object.confidence != null &&
|
||||
object.confidence! >= 0 && object.confidence! <= 1)
|
||||
l10n.translate('perception_obstacle.confidence', {
|
||||
'value': (object.confidence! * 100).toStringAsFixed(0),
|
||||
}),
|
||||
];
|
||||
return Tooltip(
|
||||
message: details.join('\n'),
|
||||
triggerMode: TooltipTriggerMode.tap,
|
||||
child: Semantics(
|
||||
label: title,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: color, width: 2),
|
||||
boxShadow: const [
|
||||
BoxShadow(color: Colors.black26, blurRadius: 3),
|
||||
],
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,18 +19,20 @@ import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../theme/pv_colors.dart';
|
||||
import '../models/work_trace_recorder.dart';
|
||||
import 'mower_obstacle_layer.dart';
|
||||
|
||||
/// HUD 作业地图:与「路径规划」同源、同图层、同样式的**只读**实时地图。
|
||||
///
|
||||
/// 图层顺序与配色完全照抄路径规划(testmap_pages._buildMap),只保留展示所需的部分:
|
||||
/// ① ESRI 卫星底图 ② 场站无人机高清叠加层 ③ 规划路线(金黄) ④ 已走轨迹(绿) ⑤ 机器指针。
|
||||
/// 打点、障碍物、保存、开始作业等交互一概不做;路径规划的文件零改动。
|
||||
/// 实时感知目标由独立图层展示;区域编辑与作业操作由外部页面承载。
|
||||
///
|
||||
/// 数据全部来自 MQTT(TCP 链路已停用):
|
||||
/// - 机器位置/航向:全局单例 [DeviceStatusBloc] 的 `DeviceStatusUpdated`
|
||||
/// (mower/{sn}/property/location/post,bloc 内 500ms 节流),与路径规划同一条流;
|
||||
/// - 规划路线:`MowerRealtimeRepository.routeStatusStream`(device/{sn}/route/post,
|
||||
/// 广播流,这里只是多一个订阅者,不会影响路径规划页的订阅)。
|
||||
/// - 感知障碍物:`mower/{sn}/perception/obstacle/post`,由图层按设备独立订阅。
|
||||
///
|
||||
/// 与路径规划的唯一行为差异(按需求新增):机器**始终显示在正中间**。用户手拖/缩放
|
||||
/// 会暂停跟随,右下角「定位」按钮恢复。
|
||||
@@ -54,6 +56,7 @@ class PvWorkMap extends StatefulWidget {
|
||||
this.draftObstacle = false,
|
||||
this.draftCrosshair = false,
|
||||
this.returnPoints = const <LatLng>[],
|
||||
this.returnObstacleHoles = const <List<LatLng>>[],
|
||||
this.followDevice = true,
|
||||
this.centerOnDeviceOnOpen = false,
|
||||
this.recenterSignal = 0,
|
||||
@@ -79,7 +82,7 @@ class PvWorkMap extends StatefulWidget {
|
||||
});
|
||||
|
||||
/// 设备 SN:用于过滤路线推送(deviceId 不匹配的消息直接丢弃)。
|
||||
/// 订阅本身由页面层 `startMqttRealtimeListening` 保证,这里不重复切换全局设备。
|
||||
/// 机器状态订阅由页面层保证;障碍物图层按此 SN 独立订阅,不切换全局设备。
|
||||
final String deviceSn;
|
||||
|
||||
/// 是否允许拖动/缩放:左栏小卡传 false(避免与列表滚动、摇杆抢手势),
|
||||
@@ -141,6 +144,8 @@ class PvWorkMap extends StatefulWidget {
|
||||
/// 一键返航点:紫色虚线串联 + 紫色编号徽标(首点显示「H」)。
|
||||
/// 与作业区橙色打点、禁行区红色框配色区分,互不影响。
|
||||
final List<LatLng> returnPoints;
|
||||
/// 返航障碍独立显示,不依赖圈地/禁行区的编辑开关。
|
||||
final List<List<LatLng>> returnObstacleHoles;
|
||||
|
||||
/// 是否让地图随设备位置自动居中。区域编辑时传 false:
|
||||
/// 否则每次定位推送都会把地图挪走,正在打的位置就跑了。
|
||||
@@ -831,6 +836,9 @@ class _PvWorkMapState extends State<PvWorkMap> {
|
||||
],
|
||||
),
|
||||
|
||||
/// 感知目标与禁行区草稿分别显示,始终使用当前地图的设备 SN。
|
||||
MowerObstacleLayer(deviceSn: widget.deviceSn),
|
||||
|
||||
/// 机器指针(同一个 HeadingMarkerPainter:绿圆 + 白描边 + 航向箭头)
|
||||
if (marker != null)
|
||||
MarkerLayer(
|
||||
@@ -911,6 +919,37 @@ class _PvWorkMapState extends State<PvWorkMap> {
|
||||
],
|
||||
),
|
||||
|
||||
if (widget.returnObstacleHoles.isNotEmpty) ...[
|
||||
PolygonLayer(
|
||||
polygons: [
|
||||
for (final hole in widget.returnObstacleHoles)
|
||||
if (hole.length >= 3)
|
||||
Polygon(
|
||||
points: hole,
|
||||
color: Colors.red.withValues(alpha: 0.25),
|
||||
borderColor: Colors.red,
|
||||
borderStrokeWidth: 2.5,
|
||||
isFilled: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
for (final hole in widget.returnObstacleHoles)
|
||||
if (hole.isNotEmpty)
|
||||
Marker(
|
||||
point: LatLng(
|
||||
hole.map((p) => p.latitude).reduce((a, b) => a + b) / hole.length,
|
||||
hole.map((p) => p.longitude).reduce((a, b) => a + b) / hole.length,
|
||||
),
|
||||
width: 28,
|
||||
height: 28,
|
||||
child: const Icon(Icons.block, color: Colors.red, size: 24),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
/// ===== 一键返航点:紫色虚线串联(末点连到准星)=====
|
||||
if (widget.returnPoints.isNotEmpty)
|
||||
PolylineLayer(
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,13 @@ class FakeMqtt implements MqttClient {
|
||||
}
|
||||
|
||||
class FakeTasks implements DeviceTaskRepository {
|
||||
@override
|
||||
Future<Either<Failure, Unit>> backToRestPoint({
|
||||
required String deviceId,
|
||||
required int orgId,
|
||||
required int siteId,
|
||||
}) async => const Right(unit);
|
||||
|
||||
List<DeviceTaskEntity> tasks = [entity()];
|
||||
Completer<Either<Failure, List<DeviceTaskEntity>>>? pending;
|
||||
String? error;
|
||||
|
||||
Reference in New Issue
Block a user