完善自主作业下发、暂停恢复和轨迹保留
This commit is contained in:
@@ -14,6 +14,8 @@ import 'package:maibu_satabot_v2/features/autonomous_work/data/site_device_realt
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/autonomous_work/domain/entities/work_session_models.dart';
|
||||
import 'package:maibu_satabot_v2/features/autonomous_work/domain/repositories/autonomous_work_gateway.dart';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/domain/entities/device_control_mode.dart';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/domain/usecases/device_control_mode_usecases.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';
|
||||
@@ -485,6 +487,7 @@ class _RobotAutonomousWorkPageV2State extends State<RobotAutonomousWorkPageV2> {
|
||||
// ===== 底部操作栏动作(全部走 gateway,状态由真实任务回流驱动)=====
|
||||
|
||||
Future<void> _startWork() async {
|
||||
if (_busy) return;
|
||||
final route = _route;
|
||||
if (route == null) {
|
||||
CapsuleToast.show(
|
||||
@@ -556,10 +559,27 @@ class _RobotAutonomousWorkPageV2State extends State<RobotAutonomousWorkPageV2> {
|
||||
return;
|
||||
}
|
||||
|
||||
final deviceId = _deviceId;
|
||||
final modeSent = await showWorkConfirmDialog(
|
||||
context,
|
||||
title: _l10n.translate('autonomous_work.dispatch_mode_title'),
|
||||
desc: _l10n.translate('autonomous_work.dispatch_mode_description'),
|
||||
checks: const [],
|
||||
confirmLabel: _l10n.translate('autonomous_work.dispatch_mode_confirm'),
|
||||
onConfirm: () async {
|
||||
final result = await sl<ChangeDeviceControlModeUseCase>()(
|
||||
deviceId,
|
||||
ControlModeTarget.autonomous,
|
||||
);
|
||||
return result.fold((failure) => failure.message, (_) => null);
|
||||
},
|
||||
);
|
||||
if (modeSent != true || !mounted) return;
|
||||
|
||||
// ③ 下发(复用已有任务或新建)
|
||||
final result = await _gateway.startWork(
|
||||
WorkStartRequest(
|
||||
deviceId: _deviceId,
|
||||
deviceId: deviceId,
|
||||
route: route,
|
||||
reuseTaskId: reuse?.taskId,
|
||||
),
|
||||
@@ -1025,6 +1045,22 @@ class _RobotAutonomousWorkPageV2State extends State<RobotAutonomousWorkPageV2> {
|
||||
return _buildPage(context);
|
||||
}
|
||||
|
||||
void _recordTaskGeometry({
|
||||
List<LatLng>? recordedPoints,
|
||||
List<LatLng>? plannedRoute,
|
||||
}) {
|
||||
final task = _session;
|
||||
final gateway = _gateway;
|
||||
if (task == null || gateway is! WorkTaskGeometrySource) return;
|
||||
final geometrySource = gateway as WorkTaskGeometrySource;
|
||||
geometrySource.recordTaskGeometry(
|
||||
deviceId: _deviceId,
|
||||
taskId: task.taskId,
|
||||
recordedPoints: recordedPoints,
|
||||
plannedRoute: plannedRoute,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPage(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF26331F),
|
||||
@@ -1042,9 +1078,15 @@ class _RobotAutonomousWorkPageV2State extends State<RobotAutonomousWorkPageV2> {
|
||||
expectedTaskId: _session?.taskId,
|
||||
traceDiagnosticsEnabled: true,
|
||||
recordLocationTrace: false,
|
||||
savedRoute: _session?.plannedRoute ?? const <LatLng>[],
|
||||
onTaskTraceChanged: (points) =>
|
||||
_recordTaskGeometry(recordedPoints: points),
|
||||
onTaskRouteChanged: (points) =>
|
||||
_recordTaskGeometry(plannedRoute: points),
|
||||
taskTrace: WorkTraceInput(
|
||||
taskId: _session?.taskId,
|
||||
completedPoints: _session?.completedPoints ?? const <LatLng>[],
|
||||
recordedPoints: _session?.recordedPoints ?? const <LatLng>[],
|
||||
recording: _session?.canRecordTrace ?? false,
|
||||
visible:
|
||||
_phase == WorkRunState.running ||
|
||||
@@ -1754,39 +1796,6 @@ class _RobotAutonomousWorkPageV2State extends State<RobotAutonomousWorkPageV2> {
|
||||
),
|
||||
),
|
||||
),
|
||||
// 底部按钮(固定,不被滚动区顶走)
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
px,
|
||||
m.tiny ? 4 : 8,
|
||||
px,
|
||||
m.tiny ? 4 : (compact ? 12 : 14),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () =>
|
||||
_pushPortrait(RobotSensorPageV2(robot: widget.robot)),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: m.tiny ? 26 : (compact ? 34 : 38),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: kWtSoftBlue,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
_l10n.translate('autonomous_work.view_sensors'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: m.fsx(12, 9),
|
||||
fontWeight: FontWeight.w800,
|
||||
color: kWtBlue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
@@ -13,9 +13,11 @@ Future<bool?> showWorkConfirmDialog(
|
||||
required List<String> checks,
|
||||
required String confirmLabel,
|
||||
bool danger = false,
|
||||
Future<String?> Function()? onConfirm,
|
||||
}) {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: onConfirm == null,
|
||||
barrierColor: const Color(0x8C0B1B2B),
|
||||
builder: (dialogContext) => _WorkConfirmDialog(
|
||||
title: title,
|
||||
@@ -23,17 +25,19 @@ Future<bool?> showWorkConfirmDialog(
|
||||
checks: checks,
|
||||
confirmLabel: confirmLabel,
|
||||
danger: danger,
|
||||
onConfirm: onConfirm,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _WorkConfirmDialog extends StatelessWidget {
|
||||
class _WorkConfirmDialog extends StatefulWidget {
|
||||
const _WorkConfirmDialog({
|
||||
required this.title,
|
||||
required this.desc,
|
||||
required this.checks,
|
||||
required this.confirmLabel,
|
||||
required this.danger,
|
||||
required this.onConfirm,
|
||||
});
|
||||
|
||||
final String title;
|
||||
@@ -41,6 +45,44 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
final List<String> checks;
|
||||
final String confirmLabel;
|
||||
final bool danger;
|
||||
final Future<String?> Function()? onConfirm;
|
||||
|
||||
@override
|
||||
State<_WorkConfirmDialog> createState() => _WorkConfirmDialogState();
|
||||
}
|
||||
|
||||
class _WorkConfirmDialogState extends State<_WorkConfirmDialog> {
|
||||
bool _submitting = false;
|
||||
String? _error;
|
||||
|
||||
Future<void> _confirm() async {
|
||||
if (_submitting) return;
|
||||
final action = widget.onConfirm;
|
||||
if (action == null) {
|
||||
Navigator.of(context).pop(true);
|
||||
return;
|
||||
}
|
||||
final l10n = AppLocalizations.of(context);
|
||||
setState(() {
|
||||
_submitting = true;
|
||||
_error = null;
|
||||
});
|
||||
String? error;
|
||||
try {
|
||||
error = await action();
|
||||
} catch (_) {
|
||||
error = l10n.translate('autonomous_work.dispatch_mode_failed');
|
||||
}
|
||||
if (!mounted || ModalRoute.of(context)?.isCurrent != true) return;
|
||||
if (error == null) {
|
||||
Navigator.of(context).pop(true);
|
||||
} else {
|
||||
setState(() {
|
||||
_submitting = false;
|
||||
_error = error;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray2 = Color(0xFF5C6B84);
|
||||
@@ -54,7 +96,7 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final accent = danger ? _danger : _blue;
|
||||
final accent = widget.danger ? _danger : _blue;
|
||||
return Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 80, vertical: 24),
|
||||
@@ -82,7 +124,7 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
widget.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w800,
|
||||
@@ -91,7 +133,9 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => Navigator.of(context).pop(false),
|
||||
onTap: _submitting
|
||||
? null
|
||||
: () => Navigator.of(context).pop(false),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Container(
|
||||
width: 32,
|
||||
@@ -117,7 +161,7 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
desc,
|
||||
widget.desc,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
height: 1.6,
|
||||
@@ -125,19 +169,23 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
for (final check in checks) ...[
|
||||
for (final check in widget.checks) ...[
|
||||
_checkRow(check, l10n),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
l10n.translate('autonomous_work.confirmation_demo_note'),
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.6,
|
||||
color: Color(0xFFA8B3C5),
|
||||
if (widget.checks.isNotEmpty) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
l10n.translate('autonomous_work.confirmation_demo_note'),
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.6,
|
||||
color: Color(0xFFA8B3C5),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (_error case final error?)
|
||||
Text(error, style: const TextStyle(color: _danger)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -149,16 +197,20 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
Expanded(
|
||||
child: _button(
|
||||
label: l10n.translate('common.back'),
|
||||
onTap: () => Navigator.of(context).pop(false),
|
||||
onTap: _submitting
|
||||
? null
|
||||
: () => Navigator.of(context).pop(false),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _button(
|
||||
label: confirmLabel,
|
||||
label: _submitting
|
||||
? l10n.translate('autonomous_work.dispatch_mode_sending')
|
||||
: widget.confirmLabel,
|
||||
filled: true,
|
||||
color: accent,
|
||||
onTap: () => Navigator.of(context).pop(true),
|
||||
onTap: _submitting ? null : _confirm,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -208,7 +260,7 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
|
||||
Widget _button({
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
required VoidCallback? onTap,
|
||||
bool filled = false,
|
||||
Color color = _blue,
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user