自主任务接口接入和bug修复和工作记录页面
This commit is contained in:
41
lib/features/autonomous_work/data/v2_work_store.dart
Normal file
41
lib/features/autonomous_work/data/v2_work_store.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// 新版独立命名空间,不读取或覆盖旧路径规划的缓存。
|
||||
class V2WorkStore {
|
||||
V2WorkStore(this.owner);
|
||||
|
||||
final String owner;
|
||||
Future<void> _writes = Future<void>.value();
|
||||
|
||||
String _key(String name) => 'v2_work.${Uri.encodeComponent(owner)}.$name';
|
||||
|
||||
Future<Map<String, dynamic>?> read(String name) async {
|
||||
await _writes;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final raw = prefs.getString(_key(name));
|
||||
if (raw == null) return null;
|
||||
try {
|
||||
final decoded = jsonDecode(raw);
|
||||
return decoded is Map ? Map<String, dynamic>.from(decoded) : null;
|
||||
} on FormatException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> write(String name, Map<String, dynamic>? value) {
|
||||
// 调用时即拍快照,避免异步写入前列表又被页面清空。
|
||||
final encoded = value == null ? null : jsonEncode(value);
|
||||
final write = _writes.then((_) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (encoded == null) {
|
||||
await prefs.remove(_key(name));
|
||||
} else {
|
||||
await prefs.setString(_key(name), encoded);
|
||||
}
|
||||
});
|
||||
_writes = write.catchError((Object _) {});
|
||||
return write;
|
||||
}
|
||||
}
|
||||
924
lib/features/autonomous_work/data/v2_work_task_tracker.dart
Normal file
924
lib/features/autonomous_work/data/v2_work_task_tracker.dart
Normal file
@@ -0,0 +1,924 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import '../../../core/logging/work_trace_diagnostics.dart';
|
||||
|
||||
import '../../../core/network/mqtt/data/infrastructure/mqtt_client_impl.dart';
|
||||
import '../../../core/network/mqtt/domain/interfaces/mqtt_client.dart';
|
||||
import '../../../core/network/mqtt/domain/models/mqtt_config.dart';
|
||||
import '../../../core/network/mqtt/domain/models/mqtt_message.dart';
|
||||
import '../../devices/domain/entities/device_task_entity.dart';
|
||||
import '../../devices/domain/repositories/device_task_repository.dart';
|
||||
import '../../devices/domain/usecases/create_device_task_usecase.dart';
|
||||
import '../domain/entities/work_session_models.dart';
|
||||
import 'v2_work_store.dart';
|
||||
|
||||
/// 新版专用任务状态。独立 MQTT 连接和缓存,不修改旧版 Cubit、订阅或完成标记。
|
||||
class V2WorkTaskTracker {
|
||||
V2WorkTaskTracker({
|
||||
required this.repository,
|
||||
required this.createTask,
|
||||
required this.resolveScope,
|
||||
required this.userId,
|
||||
required this.store,
|
||||
MqttClient? mqtt,
|
||||
WorkTraceDiagnostics? diagnostics,
|
||||
}) : mqtt = mqtt ?? MqttClientImpl(clientName: 'v2WorkTaskClient'),
|
||||
diagnostics = diagnostics ?? WorkTraceDiagnostics();
|
||||
|
||||
final DeviceTaskRepository repository;
|
||||
final CreateDeviceTaskUseCase createTask;
|
||||
final Future<WorkScope> Function(String deviceId) resolveScope;
|
||||
final String Function() userId;
|
||||
final V2WorkStore store;
|
||||
final MqttClient mqtt;
|
||||
final WorkTraceDiagnostics diagnostics;
|
||||
Timer? _traceSummaryTimer;
|
||||
final _topicReceived = <String, int>{};
|
||||
final _arriveAccepted = <String, int>{};
|
||||
final _lastTopicAt = <String, DateTime>{};
|
||||
|
||||
final _updates =
|
||||
StreamController<(String, WorkTaskSnapshot?, bool)>.broadcast(sync: true);
|
||||
final _active = <String, Map<String, WorkTaskSnapshot>>{};
|
||||
final _current = <String, WorkTaskSnapshot>{};
|
||||
final _history = <String, WorkTaskSnapshot>{};
|
||||
final _watchers = <String, int>{};
|
||||
final _topics = <String>{};
|
||||
final _pendingPool = <String, DateTime>{};
|
||||
StreamSubscription<MqttMessage>? _messages;
|
||||
Future<void> _mqttWork = Future<void>.value();
|
||||
Future<void>? _restored;
|
||||
int _revision = 0;
|
||||
|
||||
String _id(WorkTaskSnapshot task) => '${task.deviceId}/${task.taskId}';
|
||||
WorkTaskSnapshot? current(String deviceId) => _current[deviceId];
|
||||
|
||||
Stream<WorkTaskSnapshot?> watch(String deviceId, {bool allTasks = false}) {
|
||||
return Stream<WorkTaskSnapshot?>.multi((controller) {
|
||||
_watchers[deviceId] = (_watchers[deviceId] ?? 0) + 1;
|
||||
diagnostics.log('页面监听', {
|
||||
'deviceId': deviceId,
|
||||
'watchers': _watchers[deviceId],
|
||||
'allTasks': allTasks,
|
||||
});
|
||||
final subscription = _updates.stream
|
||||
.where((event) => event.$1 == deviceId && (allTasks || event.$3))
|
||||
.map((event) => event.$2)
|
||||
.listen(controller.add, onError: controller.addError);
|
||||
controller.add(_current[deviceId]);
|
||||
_scheduleMqtt();
|
||||
controller.onCancel = () async {
|
||||
await subscription.cancel();
|
||||
final count = (_watchers[deviceId] ?? 1) - 1;
|
||||
if (count == 0) {
|
||||
_watchers.remove(deviceId);
|
||||
} else {
|
||||
_watchers[deviceId] = count;
|
||||
}
|
||||
diagnostics.log('页面离开', {'deviceId': deviceId, 'watchers': count});
|
||||
_scheduleMqtt();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _restore() => _restored ??= () async {
|
||||
final data = await store.read('tasks');
|
||||
for (final raw in (data?['history'] as List? ?? const [])) {
|
||||
final task = _decode(raw);
|
||||
if (task != null) _history[_id(task)] = task;
|
||||
}
|
||||
for (final raw in (data?['current'] as List? ?? const [])) {
|
||||
final task = _decode(raw);
|
||||
if (task != null) {
|
||||
_current.putIfAbsent(task.deviceId, () => task);
|
||||
final createdAt = DateTime.tryParse(task.createdAt ?? '');
|
||||
if (task.rawStatus == 'NEW' && createdAt != null) {
|
||||
_pendingPool[_id(task)] = createdAt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
||||
Future<WorkResult<List<WorkTaskSnapshot>>> load(String deviceId) async {
|
||||
try {
|
||||
await _restore();
|
||||
final scope = await resolveScope(deviceId);
|
||||
if (scope.siteId == null) {
|
||||
diagnostics.log('任务加载失败', {
|
||||
'deviceId': deviceId,
|
||||
'reason': '未选择场站,无法取得真实taskId并订阅',
|
||||
});
|
||||
return const WorkResult.fail('未选择场站');
|
||||
}
|
||||
final revision = _revision;
|
||||
final result = await repository.getDeviceTaskPool(
|
||||
userId: userId(),
|
||||
siteId: scope.siteId!,
|
||||
orgId: scope.orgId ?? 0,
|
||||
);
|
||||
return await result.fold(
|
||||
(failure) async {
|
||||
diagnostics.log('任务加载失败', {
|
||||
'deviceId': deviceId,
|
||||
'reason': failure.message,
|
||||
});
|
||||
return WorkResult.fail(failure.message);
|
||||
},
|
||||
(entities) async {
|
||||
// 请求期间若收到了推送,以更新的 MQTT 状态为准,避免慢响应复活已完成任务。
|
||||
final active = <String, WorkTaskSnapshot>{};
|
||||
for (final entity in entities.where((e) => e.deviceId == deviceId)) {
|
||||
final snapshot = _fromEntity(entity);
|
||||
if (snapshot == null) {
|
||||
diagnostics.log('任务池过滤', {
|
||||
'deviceId': deviceId,
|
||||
'taskId': entity.id,
|
||||
'status': entity.taskStatus,
|
||||
'reason': '无法识别任务状态',
|
||||
});
|
||||
continue;
|
||||
}
|
||||
final key = _id(snapshot);
|
||||
_pendingPool.remove(key);
|
||||
if (_history.containsKey(key)) continue;
|
||||
if (snapshot.state == WorkRunState.finished) {
|
||||
final existing =
|
||||
_active[deviceId]?[snapshot.taskId] ?? _current[deviceId];
|
||||
_history[key] = snapshot.copyWith(
|
||||
routeName: existing?.taskId == snapshot.taskId
|
||||
? existing?.routeName
|
||||
: null,
|
||||
completedPoints: existing?.taskId == snapshot.taskId
|
||||
? existing?.completedPoints
|
||||
: null,
|
||||
);
|
||||
diagnostics.log('结束任务池确认', {
|
||||
'deviceId': deviceId,
|
||||
'taskId': snapshot.taskId,
|
||||
'status': snapshot.rawStatus,
|
||||
'source': 'task_pool',
|
||||
'selected': _current[deviceId]?.taskId == snapshot.taskId,
|
||||
'note': '任务池返回结束态;此记录不代表收到了MQTT结束topic',
|
||||
});
|
||||
continue;
|
||||
}
|
||||
final previous =
|
||||
_active[deviceId]?[snapshot.taskId] ?? _current[deviceId];
|
||||
active[snapshot.taskId] = revision == _revision
|
||||
? _preserveStartedExecution(
|
||||
snapshot.copyWith(
|
||||
completedPoints: previous?.taskId == snapshot.taskId
|
||||
? previous?.completedPoints
|
||||
: null,
|
||||
routeName: previous?.taskId == snapshot.taskId
|
||||
? previous?.routeName
|
||||
: null,
|
||||
),
|
||||
previous?.taskId == snapshot.taskId ? previous : null,
|
||||
)
|
||||
: (_active[deviceId]?[snapshot.taskId] ?? snapshot);
|
||||
}
|
||||
if (revision != _revision) {
|
||||
for (final task
|
||||
in _active[deviceId]?.values ?? <WorkTaskSnapshot>[]) {
|
||||
if (!_history.containsKey(_id(task))) active[task.taskId] = task;
|
||||
}
|
||||
}
|
||||
final previous = _current[deviceId];
|
||||
// 新建任务可能尚未进入池,短暂空响应不能丢掉已经确认的 taskId。
|
||||
if (previous != null &&
|
||||
!_history.containsKey(_id(previous)) &&
|
||||
!active.containsKey(previous.taskId)) {
|
||||
final pendingAt = _pendingPool[_id(previous)];
|
||||
if (pendingAt != null &&
|
||||
DateTime.now().difference(pendingAt) <
|
||||
const Duration(seconds: 30)) {
|
||||
active[previous.taskId] = previous;
|
||||
}
|
||||
}
|
||||
_active[deviceId] = active;
|
||||
diagnostics.log('任务池', {
|
||||
'deviceId': deviceId,
|
||||
'poolRows': entities.length,
|
||||
'matchingDeviceRows': entities
|
||||
.where((e) => e.deviceId == deviceId)
|
||||
.length,
|
||||
'activeTasks': [
|
||||
for (final t in active.values)
|
||||
{
|
||||
'taskId': t.taskId,
|
||||
'status': t.rawStatus,
|
||||
'points': t.completedPoints.length,
|
||||
},
|
||||
],
|
||||
});
|
||||
WorkTaskSnapshot? selected = active[previous?.taskId];
|
||||
if (selected == null && active.isNotEmpty) {
|
||||
selected = active.values.firstWhere(
|
||||
(t) => t.state == WorkRunState.running,
|
||||
orElse: () => active.values.first,
|
||||
);
|
||||
}
|
||||
if (selected != null) _publish(selected, select: true);
|
||||
// 空池不复用旧 taskId;完成快照只供结束态展示。
|
||||
if (selected == null &&
|
||||
previous != null &&
|
||||
previous.state != WorkRunState.finished) {
|
||||
final terminal = _history[_id(previous)];
|
||||
if (terminal != null) {
|
||||
_publish(terminal, select: true, source: 'task_pool');
|
||||
} else {
|
||||
_current.remove(deviceId);
|
||||
_updates.add((deviceId, null, true));
|
||||
}
|
||||
}
|
||||
await _save();
|
||||
_scheduleMqtt();
|
||||
return WorkResult.ok(active.values.toList());
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
diagnostics.log('任务加载失败', {'deviceId': deviceId, 'reason': '$e'});
|
||||
return WorkResult.fail('任务加载失败:$e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<WorkResult<WorkTaskSnapshot>> start(WorkStartRequest request) async {
|
||||
try {
|
||||
await _restore();
|
||||
if (request.reuseTaskId != null) {
|
||||
final task = _active[request.deviceId]?[request.reuseTaskId];
|
||||
if (task == null) return const WorkResult.fail('任务已失效,请刷新任务队列');
|
||||
return select(task.copyWith(executionStarted: true));
|
||||
}
|
||||
final routeId = int.tryParse(request.route.id);
|
||||
final scope = await resolveScope(request.deviceId);
|
||||
final siteId = request.siteId ?? scope.siteId;
|
||||
if (routeId == null || siteId == null) {
|
||||
return const WorkResult.fail('路线或场站无效');
|
||||
}
|
||||
final result = await createTask.execute(
|
||||
deviceId: request.deviceId,
|
||||
routeId: routeId,
|
||||
siteId: siteId,
|
||||
orgId: request.orgId ?? scope.orgId ?? 0,
|
||||
);
|
||||
return await result.fold(
|
||||
(failure) async {
|
||||
// 创建响应丢失时先查池,不自动再创建;多条匹配任务交给用户选择。
|
||||
final loaded = await load(request.deviceId);
|
||||
final matches = (loaded.data ?? <WorkTaskSnapshot>[])
|
||||
.where((task) => task.routeId == request.route.id)
|
||||
.toList();
|
||||
if (matches.length == 1) return select(matches.single);
|
||||
return WorkResult.fail(failure.message);
|
||||
},
|
||||
(id) async {
|
||||
final task = WorkTaskSnapshot(
|
||||
taskId: '$id',
|
||||
deviceId: request.deviceId,
|
||||
state: WorkRunState.queued,
|
||||
routeId: request.route.id,
|
||||
routeName: request.route.name,
|
||||
rawStatus: 'NEW',
|
||||
executionStarted: true,
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
extras: {
|
||||
'siteId': siteId,
|
||||
'orgId': request.orgId ?? scope.orgId ?? 0,
|
||||
},
|
||||
);
|
||||
_publish(task, select: true);
|
||||
_pendingPool[_id(task)] = DateTime.now();
|
||||
await _save();
|
||||
_scheduleMqtt();
|
||||
return WorkResult.ok(task);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
return WorkResult.fail('任务下发失败:$e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<WorkResult<WorkTaskSnapshot>> select(WorkTaskSnapshot task) async {
|
||||
if (task.state == WorkRunState.finished ||
|
||||
_history.containsKey(_id(task))) {
|
||||
return const WorkResult.fail('该任务已结束,请刷新任务队列');
|
||||
}
|
||||
_publish(task, select: true);
|
||||
await _save();
|
||||
_scheduleMqtt();
|
||||
return WorkResult.ok(task);
|
||||
}
|
||||
|
||||
Future<WorkResult<WorkTaskSnapshot>> command(
|
||||
String deviceId,
|
||||
WorkTaskSnapshot task,
|
||||
String operation, {
|
||||
bool forceCancel = true,
|
||||
}) async {
|
||||
try {
|
||||
if (task.deviceId != deviceId || _history.containsKey(_id(task))) {
|
||||
return const WorkResult.fail('任务已结束或设备不匹配,请刷新后重试');
|
||||
}
|
||||
if (operation == 'cancel' &&
|
||||
!forceCancel &&
|
||||
task.state != WorkRunState.queued &&
|
||||
task.state != WorkRunState.failed) {
|
||||
return const WorkResult.fail('该任务已开始执行,请使用停止作业');
|
||||
}
|
||||
if (task.rawStatus == 'CANCELING' && operation != 'cancel') {
|
||||
return const WorkResult.fail('任务正在停止,请等待设备确认');
|
||||
}
|
||||
final id = int.tryParse(task.taskId);
|
||||
final scope = await resolveScope(deviceId);
|
||||
final siteId = (task.extras['siteId'] as int?) ?? scope.siteId;
|
||||
final orgId = (task.extras['orgId'] as int?) ?? scope.orgId ?? 0;
|
||||
if (id == null || siteId == null) return const WorkResult.fail('任务或场站无效');
|
||||
String? error;
|
||||
if (operation == 'pause') {
|
||||
final result = await repository.pauseTask(
|
||||
deviceId: deviceId,
|
||||
taskId: id,
|
||||
orgId: orgId,
|
||||
siteId: siteId,
|
||||
);
|
||||
result.fold((f) => error = f.message, (ok) {
|
||||
if (!ok) error = '暂停失败';
|
||||
});
|
||||
} else if (operation == 'resume') {
|
||||
final result = await repository.recoveryTask(
|
||||
deviceId: deviceId,
|
||||
taskId: id,
|
||||
orgId: orgId,
|
||||
siteId: siteId,
|
||||
);
|
||||
result.fold((f) => error = f.message, (_) {});
|
||||
} else {
|
||||
final result = await repository.cancelTask(
|
||||
deviceId: deviceId,
|
||||
taskId: id,
|
||||
orgId: orgId,
|
||||
siteId: siteId,
|
||||
forceCancel: forceCancel,
|
||||
);
|
||||
result.fold((f) => error = f.message, (ok) {
|
||||
if (!ok) error = '取消失败';
|
||||
});
|
||||
}
|
||||
if (error != null) return WorkResult.fail(error!);
|
||||
// API 等待过程中可能先收到 FINISH,不能再被本地乐观态覆盖。
|
||||
final latest =
|
||||
_history[_id(task)] ?? _active[deviceId]?[task.taskId] ?? task;
|
||||
if (latest.state == WorkRunState.finished) return WorkResult.ok(latest);
|
||||
final updated = latest.copyWith(
|
||||
state: operation == 'pause'
|
||||
? WorkRunState.paused
|
||||
: operation == 'resume'
|
||||
? WorkRunState.running
|
||||
: WorkRunState.finished,
|
||||
rawStatus: operation == 'pause'
|
||||
? 'PAUSE'
|
||||
: operation == 'resume'
|
||||
? 'EXECUTING'
|
||||
: 'CANCELED',
|
||||
);
|
||||
_publish(
|
||||
updated,
|
||||
select: _current[deviceId]?.taskId == task.taskId,
|
||||
source: 'http_$operation',
|
||||
);
|
||||
await _save();
|
||||
_scheduleMqtt();
|
||||
return WorkResult.ok(updated);
|
||||
} catch (e) {
|
||||
return WorkResult.fail('任务操作失败:$e');
|
||||
}
|
||||
}
|
||||
|
||||
void _publish(
|
||||
WorkTaskSnapshot task, {
|
||||
bool select = false,
|
||||
String source = 'snapshot',
|
||||
String? topic,
|
||||
}) {
|
||||
if ((task.state == WorkRunState.running ||
|
||||
task.state == WorkRunState.paused) &&
|
||||
!task.executionStarted) {
|
||||
task = task.copyWith(executionStarted: true);
|
||||
}
|
||||
_revision++;
|
||||
final tasks = _active.putIfAbsent(task.deviceId, () => {});
|
||||
if (task.state == WorkRunState.finished) {
|
||||
tasks.remove(task.taskId);
|
||||
_history[_id(task)] = task;
|
||||
} else {
|
||||
tasks[task.taskId] = task;
|
||||
}
|
||||
if (select || _current[task.deviceId]?.taskId == task.taskId) {
|
||||
_current[task.deviceId] = task;
|
||||
}
|
||||
if (task.state == WorkRunState.finished) {
|
||||
diagnostics.log('结束状态落地', {
|
||||
'deviceId': task.deviceId,
|
||||
'taskId': task.taskId,
|
||||
'status': task.rawStatus,
|
||||
'source': source,
|
||||
'topic': topic,
|
||||
'points': task.completedPoints.length,
|
||||
'selected': _current[task.deviceId]?.taskId == task.taskId,
|
||||
'removedFromActive': !tasks.containsKey(task.taskId),
|
||||
'inHistory': _history.containsKey(_id(task)),
|
||||
'note': source.startsWith('http_')
|
||||
? '本地HTTP操作结果,不代表已收到设备结束topic'
|
||||
: source == 'task_pool'
|
||||
? '通过任务池查询确认结束'
|
||||
: '结束快照已写入本地状态,将通知页面',
|
||||
});
|
||||
}
|
||||
diagnostics.log(
|
||||
'任务快照',
|
||||
{
|
||||
'deviceId': task.deviceId,
|
||||
'taskId': task.taskId,
|
||||
'status': task.rawStatus,
|
||||
'state': task.state.name,
|
||||
'executionStarted': task.executionStarted,
|
||||
'canRecordTrace': task.canRecordTrace,
|
||||
'points': task.completedPoints.length,
|
||||
'selected': _current[task.deviceId]?.taskId == task.taskId,
|
||||
},
|
||||
sampleKey:
|
||||
'snapshot/${_id(task)}/${task.state.name}/${task.completedPoints.length < 2 ? task.completedPoints.length : "2+"}',
|
||||
);
|
||||
_updates.add((
|
||||
task.deviceId,
|
||||
task,
|
||||
_current[task.deviceId]?.taskId == task.taskId,
|
||||
));
|
||||
}
|
||||
|
||||
WorkTaskSnapshot _preserveStartedExecution(
|
||||
WorkTaskSnapshot incoming,
|
||||
WorkTaskSnapshot? previous,
|
||||
) {
|
||||
final started =
|
||||
incoming.executionStarted || (previous?.executionStarted ?? false);
|
||||
if (started &&
|
||||
incoming.state == WorkRunState.queued &&
|
||||
previous != null &&
|
||||
previous.state != WorkRunState.queued &&
|
||||
previous.state != WorkRunState.idle) {
|
||||
diagnostics.log('状态合并', {
|
||||
'deviceId': incoming.deviceId,
|
||||
'taskId': incoming.taskId,
|
||||
'receivedStatus': incoming.rawStatus,
|
||||
'keptStatus': previous.rawStatus,
|
||||
'reason': '任务已确认开始,忽略延迟NEW回退,保留暂停/执行状态',
|
||||
});
|
||||
return incoming.copyWith(
|
||||
state: previous.state,
|
||||
rawStatus: previous.rawStatus,
|
||||
executionStarted: true,
|
||||
);
|
||||
}
|
||||
return incoming.copyWith(executionStarted: started);
|
||||
}
|
||||
|
||||
void _scheduleMqtt() {
|
||||
_mqttWork = _mqttWork
|
||||
.then((_) async {
|
||||
final wanted = <String>{};
|
||||
for (final device in _watchers.keys) {
|
||||
for (final task
|
||||
in _active[device]?.values ?? <WorkTaskSnapshot>[]) {
|
||||
wanted.addAll([
|
||||
'task/${task.taskId}/status',
|
||||
'task/${task.taskId}/arrive',
|
||||
]);
|
||||
}
|
||||
}
|
||||
if (wanted.isEmpty) {
|
||||
if (_watchers.isNotEmpty) {
|
||||
diagnostics.log('订阅等待', {
|
||||
'devices': _watchers.keys.toList(),
|
||||
'reason': '当前没有可订阅的活跃taskId,请查看任务池及任务加载失败日志',
|
||||
}, sampleKey: 'waiting-for-task');
|
||||
}
|
||||
_traceSummaryTimer?.cancel();
|
||||
_traceSummaryTimer = null;
|
||||
if (_topics.isNotEmpty) {
|
||||
diagnostics.log('停止订阅', {
|
||||
'reason': '无活跃任务或页面监听',
|
||||
'topics': _topics.toList(),
|
||||
});
|
||||
}
|
||||
for (final topic in _topics.toList()) {
|
||||
await mqtt.unsubscribe(topic);
|
||||
}
|
||||
_topics.clear();
|
||||
_topicReceived.clear();
|
||||
_arriveAccepted.clear();
|
||||
_lastTopicAt.clear();
|
||||
diagnostics.clear();
|
||||
await _messages?.cancel();
|
||||
_messages = null;
|
||||
await mqtt.disconnect();
|
||||
return;
|
||||
}
|
||||
if (!setEquals(wanted, _topics) || !mqtt.isConnected) {
|
||||
diagnostics.log('订阅登记', {
|
||||
'connected': mqtt.isConnected,
|
||||
'topics': wanted.toList(),
|
||||
'messageStreamAvailable': mqtt.messageStream != null,
|
||||
'note': '实际订阅确认请同时查看 v2WorkTaskClient 的订阅确认成功日志',
|
||||
});
|
||||
}
|
||||
_traceSummaryTimer ??= Timer.periodic(
|
||||
const Duration(seconds: 10),
|
||||
(_) => _logTraceSummary(),
|
||||
);
|
||||
_messages ??= mqtt.messageStream?.listen(_onMessage);
|
||||
for (final topic in _topics.difference(wanted).toList()) {
|
||||
await mqtt.unsubscribe(topic);
|
||||
_topics.remove(topic);
|
||||
_topicReceived.remove(topic);
|
||||
_arriveAccepted.remove(topic);
|
||||
_lastTopicAt.remove(topic);
|
||||
}
|
||||
for (final topic in wanted.difference(_topics)) {
|
||||
await mqtt.subscribe(topic);
|
||||
_topics.add(topic);
|
||||
}
|
||||
if (!mqtt.isConnected) {
|
||||
await mqtt.connect(
|
||||
MqttConfig.taskMessage().copyWith(clientId: 'v2_work_task'),
|
||||
);
|
||||
}
|
||||
})
|
||||
.catchError((Object error) {
|
||||
diagnostics.log('连接异常', {
|
||||
'error': '$error',
|
||||
'connected': mqtt.isConnected,
|
||||
'topics': _topics.toList(),
|
||||
});
|
||||
debugPrint('[V2WorkTask] MQTT订阅失败,连接层将重试: $error');
|
||||
});
|
||||
}
|
||||
|
||||
void _logTraceSummary() {
|
||||
for (final device in _watchers.keys) {
|
||||
for (final task in _active[device]?.values ?? <WorkTaskSnapshot>[]) {
|
||||
final topic = 'task/${task.taskId}/arrive';
|
||||
final received = _topicReceived[topic] ?? 0;
|
||||
final accepted = _arriveAccepted[topic] ?? 0;
|
||||
diagnostics.log('接收摘要', {
|
||||
'deviceId': device,
|
||||
'taskId': task.taskId,
|
||||
'topic': topic,
|
||||
'connected': mqtt.isConnected,
|
||||
'registered': _topics.contains(topic),
|
||||
'listening': _messages != null,
|
||||
'statusTopic': 'task/${task.taskId}/status',
|
||||
'statusReceived': _topicReceived['task/${task.taskId}/status'] ?? 0,
|
||||
'status': task.rawStatus,
|
||||
'state': task.state.name,
|
||||
'executionStarted': task.executionStarted,
|
||||
'canRecordTrace': task.canRecordTrace,
|
||||
'received': received,
|
||||
'accepted': accepted,
|
||||
'points': task.completedPoints.length,
|
||||
'lastArriveAt': _lastTopicAt[topic]?.toIso8601String(),
|
||||
'secondsSinceLastArrive': _lastTopicAt[topic] == null
|
||||
? null
|
||||
: DateTime.now().difference(_lastTopicAt[topic]!).inSeconds,
|
||||
'selected': _current[device]?.taskId == task.taskId,
|
||||
'hint': received == 0
|
||||
? '当前订阅周期内未收到此到达点 topic;先检查订阅确认、任务ID和服务端推送'
|
||||
: accepted == 0
|
||||
? '收到过到达点消息但未追加轨迹,请查看过滤原因'
|
||||
: task.completedPoints.length < 2
|
||||
? '已收到到达点,地图会接入车辆最新定位,请核对地图画线日志'
|
||||
: '轨迹已有点,请核对页面和地图日志',
|
||||
});
|
||||
diagnostics.log('结束确认等待', {
|
||||
'deviceId': device,
|
||||
'taskId': task.taskId,
|
||||
'status': task.rawStatus,
|
||||
'connected': mqtt.isConnected,
|
||||
'statusTopic': 'task/${task.taskId}/status',
|
||||
'arriveTopic': topic,
|
||||
'statusReceived': _topicReceived['task/${task.taskId}/status'] ?? 0,
|
||||
'arriveReceived': received,
|
||||
'lastStatusAt': _lastTopicAt['task/${task.taskId}/status']
|
||||
?.toIso8601String(),
|
||||
'lastArriveAt': _lastTopicAt[topic]?.toIso8601String(),
|
||||
'note': '任务仍在活跃列表,尚未确认结束;消息长期不更新需核对连接和服务端状态,不能据此直接判定完成或卡死',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _onMessage(MqttMessage message) {
|
||||
diagnostics.log(
|
||||
'MQTT收到',
|
||||
{'topic': message.topic, 'payload': message.payload},
|
||||
sampleKey: message.topic.endsWith('/status')
|
||||
? null
|
||||
: 'raw/${message.topic}',
|
||||
);
|
||||
final parts = message.topic.split('/');
|
||||
if (parts.length != 3 ||
|
||||
parts.first != 'task' ||
|
||||
!_topics.contains(message.topic)) {
|
||||
diagnostics.log('过滤', {
|
||||
'topic': message.topic,
|
||||
'reason': 'topic格式不符或不在当前订阅列表',
|
||||
}, sampleKey: 'topic/${message.topic}');
|
||||
return;
|
||||
}
|
||||
_topicReceived.update(message.topic, (v) => v + 1, ifAbsent: () => 1);
|
||||
_lastTopicAt[message.topic] = DateTime.now();
|
||||
String? terminalSource;
|
||||
void rejected(String reason, [Map<String, Object?> fields = const {}]) {
|
||||
diagnostics.log('过滤', {
|
||||
'topic': message.topic,
|
||||
'reason': reason,
|
||||
...fields,
|
||||
}, sampleKey: 'reject/${message.topic}/$reason');
|
||||
if (terminalSource != null) {
|
||||
diagnostics.log('结束消息过滤', {
|
||||
'topic': message.topic,
|
||||
'topicTaskId': parts[1],
|
||||
'source': terminalSource,
|
||||
'reason': reason,
|
||||
...fields,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final data = jsonDecode(message.payload) as Map<String, dynamic>;
|
||||
final rawStatus = data['status']?.toString().toUpperCase() ?? '';
|
||||
if (parts[2] == 'status' &&
|
||||
stateFromStatus(rawStatus) == WorkRunState.finished) {
|
||||
terminalSource = 'mqtt_status';
|
||||
} else if (parts[2] == 'arrive' &&
|
||||
data['type'] == 'device_task_arrive_point' &&
|
||||
data['entity'] == null) {
|
||||
terminalSource = 'mqtt_arrive_empty';
|
||||
}
|
||||
if (terminalSource != null) {
|
||||
diagnostics.log('结束消息收到', {
|
||||
'topic': message.topic,
|
||||
'topicTaskId': parts[1],
|
||||
'taskId': data['taskId'],
|
||||
'deviceId': data['deviceId'],
|
||||
'source': terminalSource,
|
||||
'status': rawStatus,
|
||||
'entityPresent': data.containsKey('entity'),
|
||||
'payload': message.payload,
|
||||
'note': '原始结束信号已收到,是否接受还要看后续过滤和结束状态落地日志',
|
||||
});
|
||||
}
|
||||
WorkTaskSnapshot? task;
|
||||
for (final device in _watchers.keys) {
|
||||
final candidate = _active[device]?[parts[1]];
|
||||
if (candidate != null) {
|
||||
task = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (task == null) {
|
||||
rejected(
|
||||
_history.values.any((t) => t.taskId == parts[1])
|
||||
? '任务已结束,忽略重复或迟到消息'
|
||||
: '未找到此topic对应的活跃任务',
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (data['taskId'] != null && '${data['taskId']}' != task.taskId) {
|
||||
rejected('消息taskId与topic任务不一致', {
|
||||
'expectedTaskId': task.taskId,
|
||||
'receivedTaskId': data['taskId'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
final device = data['deviceId']?.toString() ?? '';
|
||||
if (device.isNotEmpty && device != task.deviceId) {
|
||||
rejected('deviceId不匹配', {
|
||||
'expectedDeviceId': task.deviceId,
|
||||
'receivedDeviceId': device,
|
||||
});
|
||||
return;
|
||||
}
|
||||
WorkTaskSnapshot? updated;
|
||||
if (parts[2] == 'status') {
|
||||
final raw = data['status']?.toString().toUpperCase() ?? '';
|
||||
final state = stateFromStatus(raw);
|
||||
if (state == null) {
|
||||
rejected('无法识别任务状态', {'status': raw});
|
||||
return;
|
||||
}
|
||||
diagnostics.log('状态收到', {
|
||||
'topic': message.topic,
|
||||
'deviceId': task.deviceId,
|
||||
'taskId': task.taskId,
|
||||
'before': task.rawStatus,
|
||||
'after': raw,
|
||||
});
|
||||
updated = _preserveStartedExecution(
|
||||
task.copyWith(state: state, rawStatus: raw),
|
||||
task,
|
||||
);
|
||||
} else if (parts[2] == 'arrive') {
|
||||
if (data['type'] != 'device_task_arrive_point') {
|
||||
rejected('到达点type不匹配', {'type': data['type']});
|
||||
return;
|
||||
}
|
||||
final location = data['entity'];
|
||||
if (location == null) {
|
||||
diagnostics.log('空点结束', {
|
||||
'topic': message.topic,
|
||||
'deviceId': task.deviceId,
|
||||
'taskId': task.taskId,
|
||||
'note': 'entity为空,按原有协议处理为任务结束',
|
||||
});
|
||||
// 与旧版约定一致:空到达点表示任务结束。
|
||||
updated = task.copyWith(
|
||||
state: WorkRunState.finished,
|
||||
rawStatus: 'FINISH',
|
||||
);
|
||||
} else if (location is! Map) {
|
||||
rejected('entity不是坐标对象');
|
||||
return;
|
||||
} else if (task.state != WorkRunState.running &&
|
||||
task.state != WorkRunState.queued) {
|
||||
rejected('任务已暂停或中断,不追加到达点', {
|
||||
'status': task.rawStatus,
|
||||
'state': task.state.name,
|
||||
'note': 'NEW延迟不拦截有效到达点;暂停和中断仍冻结轨迹',
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
final lat = double.tryParse('${location['lat']}');
|
||||
final lng = double.tryParse('${location['lng'] ?? location['lon']}');
|
||||
if (lat == null ||
|
||||
lng == null ||
|
||||
!lat.isFinite ||
|
||||
!lng.isFinite ||
|
||||
lat == 0 ||
|
||||
lng == 0 ||
|
||||
lat.abs() > 90 ||
|
||||
lng.abs() > 180) {
|
||||
rejected('坐标为空、非数值、零或超出范围', {
|
||||
'lat': location['lat'],
|
||||
'lng': location['lng'] ?? location['lon'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
final point = LatLng(lat, lng);
|
||||
if (task.completedPoints.isNotEmpty &&
|
||||
task.completedPoints.last == point) {
|
||||
rejected('与上一轨迹点重复', {'lat': lat, 'lng': lng});
|
||||
return;
|
||||
}
|
||||
updated = task.copyWith(
|
||||
completedPoints: [...task.completedPoints, point],
|
||||
executionStarted: true,
|
||||
);
|
||||
_arriveAccepted.update(
|
||||
message.topic,
|
||||
(v) => v + 1,
|
||||
ifAbsent: () => 1,
|
||||
);
|
||||
diagnostics.log(
|
||||
'轨迹追加',
|
||||
{
|
||||
'topic': message.topic,
|
||||
'deviceId': task.deviceId,
|
||||
'taskId': task.taskId,
|
||||
'lat': lat,
|
||||
'lng': lng,
|
||||
'points': updated.completedPoints.length,
|
||||
'selected': _current[task.deviceId]?.taskId == task.taskId,
|
||||
},
|
||||
sampleKey:
|
||||
'accept/${message.topic}/${updated.completedPoints.length < 2 ? "1" : "2+"}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (updated == null) return;
|
||||
_publish(
|
||||
updated,
|
||||
source: terminalSource ?? 'mqtt_update',
|
||||
topic: message.topic,
|
||||
);
|
||||
unawaited(
|
||||
_save().catchError((Object error) {
|
||||
debugPrint('[V2WorkTask] 缓存失败: $error');
|
||||
}),
|
||||
);
|
||||
_scheduleMqtt();
|
||||
} catch (e) {
|
||||
diagnostics.log('解析失败', {
|
||||
'topic': message.topic,
|
||||
'error': '$e',
|
||||
}, sampleKey: 'parse/${message.topic}');
|
||||
debugPrint('[V2WorkTask] 忽略无效任务消息: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<WorkTaskSnapshot>> history(String deviceId) async {
|
||||
await _restore();
|
||||
return _history.values
|
||||
.where((t) => t.deviceId == deviceId)
|
||||
.toList()
|
||||
.reversed
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> _save() => store
|
||||
.write('tasks', {
|
||||
'current': [
|
||||
for (final task in _current.values.where(
|
||||
(t) => t.state != WorkRunState.finished,
|
||||
))
|
||||
_encode(task),
|
||||
],
|
||||
'history': [for (final task in _history.values) _encode(task)],
|
||||
})
|
||||
.catchError((Object error) {
|
||||
debugPrint('[V2WorkTask] 缓存失败,不影响任务订阅: $error');
|
||||
});
|
||||
|
||||
static Map<String, dynamic> _encode(WorkTaskSnapshot task) => {
|
||||
'taskId': task.taskId,
|
||||
'deviceId': task.deviceId,
|
||||
'state': task.state.name,
|
||||
'rawStatus': task.rawStatus,
|
||||
'executionStarted': task.executionStarted,
|
||||
'routeId': task.routeId,
|
||||
'routeName': task.routeName,
|
||||
'createdAt': task.createdAt,
|
||||
'extras': task.extras,
|
||||
'completedPoints': [
|
||||
for (final p in task.completedPoints)
|
||||
{'lat': p.latitude, 'lng': p.longitude},
|
||||
],
|
||||
};
|
||||
|
||||
static WorkTaskSnapshot? _decode(dynamic raw) {
|
||||
if (raw is! Map || raw['taskId'] == null || raw['deviceId'] == null) {
|
||||
return null;
|
||||
}
|
||||
return WorkTaskSnapshot(
|
||||
taskId: '${raw['taskId']}',
|
||||
deviceId: '${raw['deviceId']}',
|
||||
state: stateFromStatus('${raw['rawStatus']}') ?? WorkRunState.queued,
|
||||
executionStarted:
|
||||
raw['executionStarted'] == true ||
|
||||
raw['rawStatus'] == 'EXECUTING' ||
|
||||
raw['rawStatus'] == 'PAUSE' ||
|
||||
(raw['completedPoints'] is List &&
|
||||
(raw['completedPoints'] as List).isNotEmpty),
|
||||
rawStatus: '${raw['rawStatus']}',
|
||||
routeId: raw['routeId'] as String?,
|
||||
routeName: raw['routeName'] as String?,
|
||||
createdAt: raw['createdAt'] as String?,
|
||||
extras: Map<String, dynamic>.from(raw['extras'] as Map? ?? {}),
|
||||
completedPoints: [
|
||||
for (final p in raw['completedPoints'] as List? ?? [])
|
||||
LatLng((p['lat'] as num).toDouble(), (p['lng'] as num).toDouble()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static WorkRunState? stateFromStatus(String status) => switch (status) {
|
||||
'NEW' => WorkRunState.queued,
|
||||
'EXECUTING' => WorkRunState.running,
|
||||
'PAUSE' => WorkRunState.paused,
|
||||
'FAILED' || 'CANCELING' => WorkRunState.failed,
|
||||
'FINISH' || 'CANCELED' || 'CANCELLED' => WorkRunState.finished,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
static WorkTaskSnapshot? _fromEntity(DeviceTaskEntity task) {
|
||||
final state = stateFromStatus(task.taskStatus);
|
||||
if (state == null) return null;
|
||||
return WorkTaskSnapshot(
|
||||
taskId: '${task.id}',
|
||||
deviceId: task.deviceId,
|
||||
state: state,
|
||||
executionStarted:
|
||||
state == WorkRunState.running || state == WorkRunState.paused,
|
||||
rawStatus: task.taskStatus,
|
||||
routeId: task.routeId?.toString(),
|
||||
createdAt: task.createTime,
|
||||
extras: {'siteId': task.siteId, 'orgId': task.orgId},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,13 @@ extension WorkRunStateX on WorkRunState {
|
||||
this == WorkRunState.failed ? WorkRunState.paused : this;
|
||||
|
||||
String get label => switch (this) {
|
||||
WorkRunState.idle => '准备',
|
||||
WorkRunState.queued => '待执行',
|
||||
WorkRunState.running => '执行中',
|
||||
WorkRunState.paused => '暂停/中断',
|
||||
WorkRunState.finished => '已结束',
|
||||
WorkRunState.failed => '异常中断',
|
||||
};
|
||||
WorkRunState.idle => '准备',
|
||||
WorkRunState.queued => '待执行',
|
||||
WorkRunState.running => '执行中',
|
||||
WorkRunState.paused => '暂停/中断',
|
||||
WorkRunState.finished => '已结束',
|
||||
WorkRunState.failed => '异常中断',
|
||||
};
|
||||
}
|
||||
|
||||
/// 路线库中的一条可执行路线(对应路径规划列表里的一条作业记录)
|
||||
@@ -111,6 +111,8 @@ class WorkTaskSnapshot {
|
||||
this.coveredArea,
|
||||
this.plannedArea,
|
||||
this.extras = const <String, dynamic>{},
|
||||
this.completedPoints = const <LatLng>[],
|
||||
this.executionStarted = false,
|
||||
});
|
||||
|
||||
final String taskId;
|
||||
@@ -129,6 +131,16 @@ class WorkTaskSnapshot {
|
||||
final double? plannedArea;
|
||||
final Map<String, dynamic> extras;
|
||||
|
||||
/// 当前任务的 MQTT 到达点,独立于设备定位轨迹。
|
||||
final List<LatLng> completedPoints;
|
||||
|
||||
/// 已确认开始过本任务(开始流程成功、执行状态或有效到达点)。
|
||||
/// 独立于后台原始状态,允许 NEW 推送延迟;暂停和结束仍由 state 控制。
|
||||
final bool executionStarted;
|
||||
bool get canRecordTrace =>
|
||||
state == WorkRunState.running ||
|
||||
state == WorkRunState.queued && executionStarted;
|
||||
|
||||
bool get isActive =>
|
||||
state == WorkRunState.queued ||
|
||||
state == WorkRunState.running ||
|
||||
@@ -140,6 +152,8 @@ class WorkTaskSnapshot {
|
||||
String? routeId,
|
||||
String? routeName,
|
||||
double? progress,
|
||||
List<LatLng>? completedPoints,
|
||||
bool? executionStarted,
|
||||
}) {
|
||||
return WorkTaskSnapshot(
|
||||
taskId: taskId,
|
||||
@@ -153,6 +167,8 @@ class WorkTaskSnapshot {
|
||||
coveredArea: coveredArea,
|
||||
plannedArea: plannedArea,
|
||||
extras: extras,
|
||||
completedPoints: completedPoints ?? this.completedPoints,
|
||||
executionStarted: executionStarted ?? this.executionStarted,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
/// 作业页面决定开始/暂停/结束,地图只消费这个只读输入。
|
||||
class WorkTraceInput {
|
||||
const WorkTraceInput({
|
||||
required this.taskId,
|
||||
required this.recording,
|
||||
required this.visible,
|
||||
this.completedPoints = const [],
|
||||
});
|
||||
final String? taskId;
|
||||
final bool recording;
|
||||
final bool visible;
|
||||
final List<LatLng> completedPoints;
|
||||
}
|
||||
|
||||
/// 新版作业绿线:首个到达点前累计定位,之后保留到达点并接一段实时车位。
|
||||
/// 不写任务历史、不下发指令,也不依赖旧版 TracePoint 的可变状态。
|
||||
class WorkTraceRecorder {
|
||||
WorkTraceRecorder({this.maxGpsPoints = 600, this.minimumStepMeters = 0.3})
|
||||
: assert(maxGpsPoints >= 2),
|
||||
assert(minimumStepMeters >= 0);
|
||||
final int maxGpsPoints;
|
||||
final double minimumStepMeters;
|
||||
final _distance = const Distance(roundResult: false);
|
||||
String? _deviceId;
|
||||
String? _taskId;
|
||||
bool _visible = false;
|
||||
bool _recording = false;
|
||||
final _gpsPoints = <LatLng>[];
|
||||
List<LatLng> _completed = const [];
|
||||
LatLng? _tail;
|
||||
|
||||
bool get hasCompletedPoints => _completed.isNotEmpty;
|
||||
List<LatLng> get points {
|
||||
if (!_visible) return const [];
|
||||
if (_completed.isEmpty) return List.unmodifiable(_gpsPoints);
|
||||
return List.unmodifiable([
|
||||
..._completed,
|
||||
if (_tail != null && _tail != _completed.last) _tail!,
|
||||
]);
|
||||
}
|
||||
|
||||
void synchronize({required String deviceId, required WorkTraceInput input}) {
|
||||
if (_deviceId != deviceId || _taskId != input.taskId) {
|
||||
reset();
|
||||
_deviceId = deviceId;
|
||||
_taskId = input.taskId;
|
||||
}
|
||||
_visible =
|
||||
input.visible &&
|
||||
deviceId.isNotEmpty &&
|
||||
(input.taskId?.isNotEmpty ?? false);
|
||||
_recording = _visible && input.recording;
|
||||
if (!_visible) {
|
||||
_gpsPoints.clear();
|
||||
_completed = const [];
|
||||
_tail = null;
|
||||
return;
|
||||
}
|
||||
final completed = <LatLng>[];
|
||||
for (final point in input.completedPoints) {
|
||||
if (_valid(point) && (completed.isEmpty || completed.last != point)) {
|
||||
completed.add(point);
|
||||
}
|
||||
}
|
||||
if (_completed.isEmpty && completed.isNotEmpty) _gpsPoints.clear();
|
||||
_completed = List.unmodifiable(completed);
|
||||
}
|
||||
|
||||
bool addPosition(LatLng point) {
|
||||
if (!_recording || !_valid(point)) return false;
|
||||
if (_completed.isNotEmpty) {
|
||||
if (_tail == point) return false;
|
||||
_tail = point;
|
||||
return true;
|
||||
}
|
||||
if (_gpsPoints.isNotEmpty &&
|
||||
_distance(_gpsPoints.last, point) < minimumStepMeters) {
|
||||
return false;
|
||||
}
|
||||
_gpsPoints.add(point);
|
||||
_tail = point;
|
||||
if (_gpsPoints.length > maxGpsPoints) {
|
||||
_gpsPoints.removeRange(0, _gpsPoints.length - maxGpsPoints);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _valid(LatLng point) =>
|
||||
point.latitude.isFinite &&
|
||||
point.longitude.isFinite &&
|
||||
point.latitude != 0 &&
|
||||
point.longitude != 0 &&
|
||||
point.latitude.abs() <= 90 &&
|
||||
point.longitude.abs() <= 180;
|
||||
|
||||
void reset() {
|
||||
_deviceId = null;
|
||||
_taskId = null;
|
||||
_visible = false;
|
||||
_recording = false;
|
||||
_gpsPoints.clear();
|
||||
_completed = const [];
|
||||
_tail = null;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
/// 视频加载状态
|
||||
enum WebRTCLoadState { loading, playing, error }
|
||||
|
||||
@@ -424,17 +426,28 @@ class _WebRTCLocalPlayerState extends State<WebRTCLocalPlayer> {
|
||||
color: Colors.white38,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'视频加载失败,请检查设备是否在线或重试',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
Text(
|
||||
AppLocalizations.of(context).translate(
|
||||
'remote_control.video_load_failed',
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
]
|
||||
: [
|
||||
const CircularProgressIndicator(color: Colors.white),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'视频加载中...',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.video_loading'),
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
// 用例层
|
||||
export 'get_device_status_data_usecase.dart';
|
||||
export 'update_device_alias_usecase.dart';
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
import '../../../../devices/domain/entities/device_task_entity.dart';
|
||||
import '../../../../devices/domain/usecases/get_device_task_pool_usecase.dart';
|
||||
|
||||
enum WorkHomeTaskStatus { idle, loading, ready, failure, noUser, noSite }
|
||||
|
||||
String workTaskStatus(DeviceTaskEntity task) =>
|
||||
task.taskStatus.trim().toUpperCase();
|
||||
|
||||
class WorkHomeTaskState extends Equatable {
|
||||
const WorkHomeTaskState({
|
||||
this.status = WorkHomeTaskStatus.idle,
|
||||
this.tasks = const [],
|
||||
this.error,
|
||||
});
|
||||
|
||||
final WorkHomeTaskStatus status;
|
||||
final List<DeviceTaskEntity> tasks;
|
||||
final String? error;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, tasks, error];
|
||||
|
||||
int get runningCount =>
|
||||
tasks.where((t) => workTaskStatus(t) == 'EXECUTING').length;
|
||||
int get pendingCount => tasks.where((t) => workTaskStatus(t) == 'NEW').length;
|
||||
}
|
||||
|
||||
/// 场站首页复用任务池查询,不复用自主作业中心的单设备筛选与任务缓存。
|
||||
class WorkHomeTaskCubit extends Cubit<WorkHomeTaskState> {
|
||||
WorkHomeTaskCubit(this._getPool) : super(const WorkHomeTaskState());
|
||||
|
||||
final GetDeviceTaskPoolUseCase _getPool;
|
||||
int _request = 0;
|
||||
(String, int, int)? _scope;
|
||||
Future<void>? _inFlight;
|
||||
|
||||
void clear() {
|
||||
++_request;
|
||||
_scope = null;
|
||||
_inFlight = null;
|
||||
if (!isClosed) emit(const WorkHomeTaskState());
|
||||
}
|
||||
|
||||
Future<void> load({
|
||||
required String? userId,
|
||||
required int? siteId,
|
||||
required int? orgId,
|
||||
}) {
|
||||
if (isClosed) return Future<void>.value();
|
||||
if (userId == null || userId.trim().isEmpty) {
|
||||
clear();
|
||||
emit(const WorkHomeTaskState(status: WorkHomeTaskStatus.noUser));
|
||||
return Future<void>.value();
|
||||
}
|
||||
if (siteId == null || siteId <= 0 || orgId == null || orgId <= 0) {
|
||||
clear();
|
||||
emit(const WorkHomeTaskState(status: WorkHomeTaskStatus.noSite));
|
||||
return Future<void>.value();
|
||||
}
|
||||
final scope = (userId, siteId, orgId);
|
||||
if (_scope == scope && _inFlight != null) return _inFlight!;
|
||||
final keepContent =
|
||||
_scope == scope && state.status == WorkHomeTaskStatus.ready;
|
||||
final request = ++_request;
|
||||
_scope = scope;
|
||||
// 同一场站保留已显示的数据;首次加载和切换范围才显示加载态。
|
||||
// ready 状态与任务使用值比较,相同响应不会通知界面重建。
|
||||
if (!keepContent) {
|
||||
emit(const WorkHomeTaskState(status: WorkHomeTaskStatus.loading));
|
||||
}
|
||||
return _inFlight = _fetch(scope, request);
|
||||
}
|
||||
|
||||
Future<void> _fetch((String, int, int) scope, int request) async {
|
||||
try {
|
||||
debugPrint('[作业首页] 查询任务池 siteId=${scope.$2}, orgId=${scope.$3}');
|
||||
final result = await _getPool(
|
||||
GetDeviceTaskPoolParams(
|
||||
userId: scope.$1,
|
||||
siteId: scope.$2,
|
||||
orgId: scope.$3,
|
||||
),
|
||||
);
|
||||
if (isClosed || request != _request) return;
|
||||
result.fold(
|
||||
(failure) {
|
||||
debugPrint('[作业首页] 任务池失败:${failure.message}');
|
||||
_loadFailed(failure.message);
|
||||
},
|
||||
(rows) {
|
||||
final tasks = <(String, int), DeviceTaskEntity>{};
|
||||
for (final task in rows) {
|
||||
if (task.siteId != null && task.siteId != scope.$2) continue;
|
||||
if (task.orgId != null && task.orgId != scope.$3) continue;
|
||||
if (const {
|
||||
'FINISH',
|
||||
'CANCELED',
|
||||
'CANCELLED',
|
||||
}.contains(workTaskStatus(task))) {
|
||||
continue;
|
||||
}
|
||||
tasks[(task.deviceId, task.id)] = task;
|
||||
}
|
||||
const priority = {
|
||||
'EXECUTING': 0,
|
||||
'PAUSE': 1,
|
||||
'FAILED': 2,
|
||||
'CANCELING': 3,
|
||||
'NEW': 4,
|
||||
};
|
||||
final sorted = tasks.values.toList()
|
||||
..sort((a, b) {
|
||||
final order = (priority[workTaskStatus(a)] ?? 5).compareTo(
|
||||
priority[workTaskStatus(b)] ?? 5,
|
||||
);
|
||||
if (order != 0) return order;
|
||||
final idOrder = b.id.compareTo(a.id);
|
||||
return idOrder == 0 ? a.deviceId.compareTo(b.deviceId) : idOrder;
|
||||
});
|
||||
debugPrint('[作业首页] 返回 ${rows.length} 条,当前场站活跃任务 ${sorted.length} 条');
|
||||
emit(
|
||||
WorkHomeTaskState(
|
||||
status: WorkHomeTaskStatus.ready,
|
||||
tasks: List.unmodifiable(sorted),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
if (!isClosed && request == _request) {
|
||||
debugPrint('[作业首页] 任务池异常:$error');
|
||||
_loadFailed('$error');
|
||||
}
|
||||
} finally {
|
||||
if (request == _request) _inFlight = null;
|
||||
}
|
||||
}
|
||||
|
||||
void _loadFailed(String message) {
|
||||
// 后台刷新失败仍展示上次成功的数据,并单独标出刷新错误。
|
||||
emit(
|
||||
WorkHomeTaskState(
|
||||
status: state.status == WorkHomeTaskStatus.ready
|
||||
? WorkHomeTaskStatus.ready
|
||||
: WorkHomeTaskStatus.failure,
|
||||
tasks: state.status == WorkHomeTaskStatus.ready
|
||||
? state.tasks
|
||||
: const [],
|
||||
error: message,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
++_request;
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
@@ -1,337 +1,110 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/geoserver_suzhou_layer.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/regions/domain/entities/region_draft.dart';
|
||||
import 'package:maibu_satabot_v2/features/regions/presentation/cubit/region_list_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/regions/presentation/widgets/region_list_panel.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/pages/route_editor_page_v2.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/widgets/autonomous/work_ui.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/work/presentation/widgets/work_phone_ui.dart';
|
||||
|
||||
/// 作业区域管理(W03)——作业首页「区域管理」入口进入。
|
||||
///
|
||||
/// 竖屏单页:区域卡片列表(缩略图 + 面积 + 边界点数),
|
||||
/// 右上「新建」、「编辑」都进入横屏「地图与区域编辑」去画边界。
|
||||
///
|
||||
/// 本页为演示页:区域数据是写死的示例,不读写真实地块;
|
||||
/// 只有「进入编辑器」是真实跳转,其余动作只做界面反馈。
|
||||
/// 区域管理使用真实场站分区列表;新增和修改都进入同一地图编辑器。
|
||||
class WorkAreaPageV2 extends StatefulWidget {
|
||||
const WorkAreaPageV2({super.key});
|
||||
|
||||
static Route<void> route() =>
|
||||
MaterialPageRoute<void>(builder: (_) => const WorkAreaPageV2());
|
||||
|
||||
@override
|
||||
State<WorkAreaPageV2> createState() => _WorkAreaPageV2State();
|
||||
}
|
||||
|
||||
/// 一条演示区域
|
||||
class _DemoArea {
|
||||
const _DemoArea({
|
||||
required this.name,
|
||||
required this.kind,
|
||||
required this.area,
|
||||
required this.points,
|
||||
required this.robot,
|
||||
required this.enabled,
|
||||
});
|
||||
|
||||
final String name;
|
||||
|
||||
/// 作业区 / 禁行区 / 障碍区
|
||||
final String kind;
|
||||
final String area;
|
||||
final int points;
|
||||
final String robot;
|
||||
final bool enabled;
|
||||
}
|
||||
|
||||
class _WorkAreaPageV2State extends State<WorkAreaPageV2> {
|
||||
static const Color _navy = kWtNavy;
|
||||
static const Color _gray = kWtGray;
|
||||
static const Color _border = kWtBorder;
|
||||
static const Color _green = Color(0xFF00B42A);
|
||||
static const Color _red = Color(0xFFF0483E);
|
||||
static const Color _orange = Color(0xFFEE9A2E);
|
||||
late final RegionListCubit _regions = sl<RegionListCubit>();
|
||||
final List<StreamSubscription<dynamic>> _subscriptions = [];
|
||||
bool _opening = false;
|
||||
|
||||
static const List<String> _filters = <String>['全部区域', '作业区', '禁行区', '障碍区'];
|
||||
int _filter = 0;
|
||||
Object get _scope => (
|
||||
sl<AppUserCubit>().state.user?.userId ?? '',
|
||||
sl<SiteCubit>().state.selectedSite?.id ?? 0,
|
||||
);
|
||||
|
||||
static const List<_DemoArea> _areas = <_DemoArea>[
|
||||
_DemoArea(
|
||||
name: 'A 区 · 主草坪',
|
||||
kind: '作业区',
|
||||
area: '3 240 m²',
|
||||
points: 12,
|
||||
robot: '山东01号机',
|
||||
enabled: true,
|
||||
),
|
||||
_DemoArea(
|
||||
name: 'B 区 · 东侧草坪',
|
||||
kind: '作业区',
|
||||
area: '2 860 m²',
|
||||
points: 9,
|
||||
robot: '山东02号机',
|
||||
enabled: true,
|
||||
),
|
||||
_DemoArea(
|
||||
name: 'C 区 · 苗圃',
|
||||
kind: '作业区',
|
||||
area: '640 m²',
|
||||
points: 14,
|
||||
robot: '山东01号机',
|
||||
enabled: false,
|
||||
),
|
||||
_DemoArea(
|
||||
name: '水池禁行区',
|
||||
kind: '禁行区',
|
||||
area: '186 m²',
|
||||
points: 6,
|
||||
robot: '全部设备',
|
||||
enabled: true,
|
||||
),
|
||||
_DemoArea(
|
||||
name: '工具房障碍',
|
||||
kind: '障碍区',
|
||||
area: '42 m²',
|
||||
points: 4,
|
||||
robot: '全部设备',
|
||||
enabled: true,
|
||||
),
|
||||
];
|
||||
|
||||
void _toast(String text) => CapsuleToast.show(text, showCheck: false);
|
||||
|
||||
LatLng get _center {
|
||||
final site = sl<SiteCubit>().state.selectedSite;
|
||||
return stationLayerCenter(site?.siteMapName) ??
|
||||
const LatLng(31.083296, 120.840355);
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_subscriptions.add(
|
||||
sl<SiteCubit>().stream
|
||||
.map((s) => s.selectedSite?.id)
|
||||
.distinct()
|
||||
.listen((_) => _reload()),
|
||||
);
|
||||
_subscriptions.add(
|
||||
sl<AppUserCubit>().stream
|
||||
.map((s) => s.user?.userId)
|
||||
.distinct()
|
||||
.listen((_) => _reload()),
|
||||
);
|
||||
unawaited(_reload());
|
||||
}
|
||||
|
||||
List<_DemoArea> get _visible {
|
||||
if (_filter == 0) return _areas;
|
||||
final String kind = _filters[_filter];
|
||||
return _areas.where((a) => a.kind == kind).toList();
|
||||
}
|
||||
Future<void> _reload({bool force = false}) => _regions.load(
|
||||
siteId: sl<SiteCubit>().state.selectedSite?.id,
|
||||
ownerId: sl<AppUserCubit>().state.user?.userId,
|
||||
force: force,
|
||||
);
|
||||
|
||||
/// 进入横屏「地图与区域编辑」画边界;返回后把方向还给竖屏
|
||||
Future<void> _openEditor() async {
|
||||
await Navigator.of(context).push(RouteEditorPageV2.route(deviceSn: ''));
|
||||
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
}
|
||||
|
||||
Color _kindColor(String kind) {
|
||||
switch (kind) {
|
||||
case '禁行区':
|
||||
return _red;
|
||||
case '障碍区':
|
||||
return _orange;
|
||||
default:
|
||||
return _green;
|
||||
Future<void> _openEditor([RegionDraft? region]) async {
|
||||
if (_opening || _scope != _regions.scopeKey) return;
|
||||
setState(() => _opening = true);
|
||||
try {
|
||||
await Navigator.of(context).push(
|
||||
RouteEditorPageV2.route(initialRegion: region, startRegionEditor: true),
|
||||
);
|
||||
} finally {
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
]);
|
||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
if (mounted) {
|
||||
setState(() => _opening = false);
|
||||
await _reload(force: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final areas = _visible;
|
||||
return WorkPhoneScaffold(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
WorkPhoneTopBar(
|
||||
title: '区域管理',
|
||||
onBack: () => Navigator.of(context).maybePop(),
|
||||
trailing: WorkSquareButton(
|
||||
icon: Icons.add_rounded,
|
||||
label: '新建',
|
||||
primary: true,
|
||||
onTap: _openEditor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const WorkPageHeading(
|
||||
title: '作业区域管理',
|
||||
subtitle: '在地图和区域编辑里画出作业区、禁行区与障碍区',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
WorkFilterRow(
|
||||
items: _filters,
|
||||
index: _filter,
|
||||
onChanged: (i) => setState(() => _filter = i),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: areas.isEmpty
|
||||
? _buildEmpty()
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
itemCount: areas.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, i) => _buildAreaCard(areas[i]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
void dispose() {
|
||||
for (final subscription in _subscriptions) {
|
||||
unawaited(subscription.cancel());
|
||||
}
|
||||
unawaited(_regions.close());
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _buildEmpty() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.layers_outlined, size: 26, color: kWtMuted),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'该类型下还没有区域',
|
||||
style: TextStyle(fontSize: 12.5, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 区域卡 =====
|
||||
Widget _buildAreaCard(_DemoArea a) {
|
||||
final Color kindColor = _kindColor(a.kind);
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _border),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 左侧缩略图:作业区叠区域块,禁行/障碍只留底图
|
||||
SizedBox(
|
||||
width: 92,
|
||||
child: WorkMapThumb(
|
||||
center: _center,
|
||||
width: 92,
|
||||
height: 70,
|
||||
radius: 10,
|
||||
zoom: 17.8,
|
||||
showAreas: a.kind == '作业区',
|
||||
showRoute: a.kind == '作业区',
|
||||
showRobot: false,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
a.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 7,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: kindColor.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
a.kind,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: kindColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
'${a.area} · ${a.points} 个边界点',
|
||||
style: const TextStyle(fontSize: 11.5, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
'适用:${a.robot}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 11, color: kWtHint),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
if (!a.enabled)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 7,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: kWtLocked,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: const Text(
|
||||
'已停用',
|
||||
style: TextStyle(fontSize: 9.5, color: kWtMuted),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
_smallAction('查看', () => _toast('区域详情接口未接入(演示)')),
|
||||
const SizedBox(width: 8),
|
||||
_smallAction('编辑', _openEditor, primary: true),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _smallAction(String text, VoidCallback onTap, {bool primary = false}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: primary ? kWtSoftBlue : kWtSegBg,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
border: Border.all(color: primary ? kWtBlue : _border),
|
||||
@override
|
||||
Widget build(BuildContext context) => WorkPhoneScaffold(
|
||||
child: Column(
|
||||
children: [
|
||||
WorkPhoneTopBar(
|
||||
title: AppLocalizations.of(context).translate('work_v2.area.title'),
|
||||
onBack: () => Navigator.of(context).maybePop(),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: primary ? kWtBlue : kWtGray2,
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: AbsorbPointer(
|
||||
absorbing: _opening,
|
||||
child: RegionListPanel(
|
||||
cubit: _regions,
|
||||
currentScope: () => _scope,
|
||||
onCreate: () => _openEditor(),
|
||||
onEdit: _openEditor,
|
||||
onSelect: _openEditor,
|
||||
onRefresh: _reload,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,9 @@ import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/geoserver_suzhou_layer.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/app_base_map_layer.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/pages/route_editor_page_v2.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
|
||||
@@ -42,19 +44,32 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
static const Color _forbid = Color(0xFFFF5C5C);
|
||||
static const Color _routeLine = Color(0xFF00E5C0);
|
||||
|
||||
static const String _esriUrl =
|
||||
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
|
||||
|
||||
/// 图层筛选:0 全部 / 1 作业区 / 2 机器人 / 3 禁行区 / 4 路线
|
||||
static const List<String> _layers = <String>[
|
||||
'全部图层',
|
||||
'作业区',
|
||||
'机器人',
|
||||
'禁行区',
|
||||
'路线',
|
||||
static const List<String> _layerKeys = <String>[
|
||||
'all',
|
||||
'area',
|
||||
'robot',
|
||||
'forbidden',
|
||||
'route',
|
||||
];
|
||||
int _layer = 0;
|
||||
|
||||
/// 图层代码 -> 当前语言文案
|
||||
String _layerLabel(AppLocalizations l10n, String key) {
|
||||
switch (key) {
|
||||
case 'all':
|
||||
return l10n.translate('work_v2.map.layer_all');
|
||||
case 'area':
|
||||
return l10n.translate('work_v2.map.layer_area');
|
||||
case 'robot':
|
||||
return l10n.translate('work_v2.map.layer_robot');
|
||||
case 'forbidden':
|
||||
return l10n.translate('work_v2.map.layer_forbidden');
|
||||
default:
|
||||
return l10n.translate('work_v2.map.layer_route');
|
||||
}
|
||||
}
|
||||
|
||||
late final LatLng _center = _resolveCenter();
|
||||
late final _DemoGeometry _geo = _DemoGeometry(_center);
|
||||
|
||||
@@ -128,6 +143,7 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
|
||||
// ===== 顶栏 =====
|
||||
Widget _buildTopBar() {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
return Row(
|
||||
children: [
|
||||
_squareButton(
|
||||
@@ -136,9 +152,9 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
onTap: () => Navigator.of(context).maybePop(),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Text(
|
||||
'作业地图',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
l10n.translate('work_v2.map.title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
@@ -148,7 +164,7 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
_squareButton(
|
||||
Icons.description_outlined,
|
||||
size: 18,
|
||||
onTap: () => _toast('作业记录入口未接入(演示)'),
|
||||
onTap: () => _toast(l10n.translate('work_v2.map.toast_record_todo')),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -177,25 +193,26 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
|
||||
// ===== 标题区 =====
|
||||
Widget _buildHeader() {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Expanded(
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'作业地图',
|
||||
style: TextStyle(
|
||||
l10n.translate('work_v2.map.title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
'机器人、区域和任务在同一张场站地图上',
|
||||
style: TextStyle(fontSize: 12, color: _gray),
|
||||
l10n.translate('work_v2.map.subtitle'),
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -207,9 +224,9 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
color: _greenBg,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: const Text(
|
||||
'3台在线',
|
||||
style: TextStyle(
|
||||
child: Text(
|
||||
l10n.translate('work_v2.map.online_count').replaceAll('%s', '3'),
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _green,
|
||||
@@ -222,11 +239,12 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
|
||||
// ===== 图层筛选 =====
|
||||
Widget _buildLayerChips() {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
return SizedBox(
|
||||
height: 32,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: _layers.length,
|
||||
itemCount: _layerKeys.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(width: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final selected = _layer == index;
|
||||
@@ -245,7 +263,7 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
_layers[index],
|
||||
_layerLabel(l10n, _layerKeys[index]),
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
@@ -292,9 +310,11 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
color: Colors.white.withValues(alpha: 0.92),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Text(
|
||||
'正射影像 · 山东场站',
|
||||
style: TextStyle(
|
||||
child: Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('work_v2.map.basemap_label'),
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
@@ -310,7 +330,11 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
children: [
|
||||
_mapFloatButton(
|
||||
Icons.layers_outlined,
|
||||
onTap: () => _toast('图层设置与顶部筛选联动(演示)'),
|
||||
onTap: () => _toast(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('work_v2.map.toast_layer_todo'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_mapFloatButton(Icons.place_outlined, onTap: _resetView),
|
||||
@@ -365,12 +389,8 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
),
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate: _esriUrl,
|
||||
userAgentPackageName: 'com.maibu.maibu_satabot_v2',
|
||||
minZoom: 0,
|
||||
maxZoom: 19,
|
||||
),
|
||||
// 底图:中文=ESRI,非中文=Google(不可达自动回退 ESRI)
|
||||
const AppBaseMapLayer(maxZoom: 22),
|
||||
// 地块边界(白色细线,跟随作业区一起显隐)
|
||||
if (_showAreas)
|
||||
PolylineLayer(
|
||||
@@ -457,10 +477,13 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
/// 定位按钮:把视图拉回场站中心(本页不接实时定位推送)
|
||||
void _resetView() {
|
||||
_map.move(_center, 18);
|
||||
_toast('已回到场站中心(演示)');
|
||||
_toast(
|
||||
AppLocalizations.of(context).translate('work_v2.map.toast_center_reset'),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTaskCard() {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 14, 12),
|
||||
decoration: BoxDecoration(
|
||||
@@ -480,12 +503,12 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Expanded(
|
||||
Expanded(
|
||||
child: Text(
|
||||
'A区 · 自主割草',
|
||||
l10n.translate('work_v2.demo_task_zone_a'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
@@ -510,22 +533,30 @@ class _WorkMapPageV2State extends State<WorkMapPageV2> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(
|
||||
'设备:山东01号机 · 任务执行中',
|
||||
Text(
|
||||
l10n
|
||||
.translate('work_v2.map.task_device')
|
||||
.replaceAll('%s', l10n.translate('work_v2.demo_robot_1')),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 12, color: _gray),
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
_cardButton('管理区域', primary: false, onTap: _openAreaEditor),
|
||||
_cardButton(
|
||||
l10n.translate('work_v2.map.manage_area'),
|
||||
primary: false,
|
||||
onTap: _openAreaEditor,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _cardButton(
|
||||
'进入作业中心',
|
||||
l10n.translate('work_v2.enter_work_center'),
|
||||
primary: true,
|
||||
onTap: () => _toast('作业中心需从设备详情进入(演示)'),
|
||||
onTap: () => _toast(
|
||||
l10n.translate('work_v2.map.toast_work_center_todo'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/widgets/autonomous/work_ui.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/work/presentation/pages/work_plan_create_page_v2.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/work/presentation/pages/work_report_page_v2.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/work/presentation/widgets/work_phone_ui.dart';
|
||||
|
||||
/// 任务列表与计划(W07)——作业首页「作业计划」入口进入。
|
||||
/// 任务列表与计划(W07)——作业首页「下发作业计划」入口进入。
|
||||
///
|
||||
/// 竖屏单页:按日期分组的时间线,每张卡是一段作业计划,
|
||||
/// 顶部筛选用状态过滤,右上日历与「+ 新建计划」为演示入口。
|
||||
@@ -52,11 +54,16 @@ class _DemoDay {
|
||||
const _DemoDay({
|
||||
required this.label,
|
||||
required this.date,
|
||||
required this.weekday,
|
||||
required this.plans,
|
||||
});
|
||||
|
||||
/// today / tomorrow / yesterday
|
||||
final String label;
|
||||
|
||||
/// 月-日,星期通过 weekday 的代码取文案
|
||||
final String date;
|
||||
final String weekday;
|
||||
final List<_DemoPlan> plans;
|
||||
}
|
||||
|
||||
@@ -68,77 +75,80 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
static const Color _orange = Color(0xFFEE9A2E);
|
||||
static const Color _red = Color(0xFFF0483E);
|
||||
|
||||
static const List<String> _filters = <String>['全部', '执行中', '待执行', '已完成'];
|
||||
/// 筛选顺序:全部 / 执行中 / 待执行 / 已完成
|
||||
int _filter = 0;
|
||||
|
||||
static const List<_DemoDay> _days = <_DemoDay>[
|
||||
_DemoDay(
|
||||
label: '今天',
|
||||
date: '10-27 周二',
|
||||
label: 'today',
|
||||
date: '10-27',
|
||||
weekday: 'tue',
|
||||
plans: <_DemoPlan>[
|
||||
_DemoPlan(
|
||||
time: '08:00',
|
||||
title: 'A区 · 自主割草',
|
||||
zone: 'A 区 · 主草坪',
|
||||
robot: '山东01号机',
|
||||
routeName: 'A区路线01',
|
||||
title: 'work_v2.demo_task_zone_a',
|
||||
zone: 'work_v2.area.demo_zone_a',
|
||||
robot: 'work_v2.demo_robot_1',
|
||||
routeName: 'work_v2.demo_route_a1',
|
||||
status: _PlanStatus.running,
|
||||
progress: 0.68,
|
||||
),
|
||||
_DemoPlan(
|
||||
time: '14:30',
|
||||
title: 'C区 · 苗圃修剪',
|
||||
zone: 'C 区 · 苗圃',
|
||||
robot: '山东02号机',
|
||||
routeName: 'C区覆盖01',
|
||||
title: 'work_v2.demo_task_c_trim',
|
||||
zone: 'work_v2.area.demo_zone_c',
|
||||
robot: 'work_v2.demo_robot_2',
|
||||
routeName: 'work_v2.route_lib.demo_route_c_cov',
|
||||
status: _PlanStatus.pending,
|
||||
progress: 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
_DemoDay(
|
||||
label: '明天',
|
||||
date: '10-28 周三',
|
||||
label: 'tomorrow',
|
||||
date: '10-28',
|
||||
weekday: 'wed',
|
||||
plans: <_DemoPlan>[
|
||||
_DemoPlan(
|
||||
time: '08:00',
|
||||
title: 'B区 · 清晨割草',
|
||||
zone: 'B 区 · 东侧草坪',
|
||||
robot: '山东02号机',
|
||||
routeName: 'B区路线01',
|
||||
title: 'work_v2.demo_zone_b_task',
|
||||
zone: 'work_v2.area.demo_zone_b',
|
||||
robot: 'work_v2.demo_robot_2',
|
||||
routeName: 'work_v2.demo_route_b1',
|
||||
status: _PlanStatus.pending,
|
||||
progress: 0,
|
||||
),
|
||||
_DemoPlan(
|
||||
time: '16:00',
|
||||
title: '全场 · 沿边修整',
|
||||
zone: '全场',
|
||||
robot: '山东03号机',
|
||||
routeName: 'B区沿边01',
|
||||
title: 'work_v2.demo_task_all_edge',
|
||||
zone: 'work_v2.area.demo_zone_all',
|
||||
robot: 'work_v2.demo_robot_3',
|
||||
routeName: 'work_v2.route_lib.demo_route_b_edge',
|
||||
status: _PlanStatus.pending,
|
||||
progress: 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
_DemoDay(
|
||||
label: '昨天',
|
||||
date: '10-26 周一',
|
||||
label: 'yesterday',
|
||||
date: '10-26',
|
||||
weekday: 'mon',
|
||||
plans: <_DemoPlan>[
|
||||
_DemoPlan(
|
||||
time: '08:00',
|
||||
title: 'B区 · 清晨割草',
|
||||
zone: 'B 区 · 东侧草坪',
|
||||
robot: '山东02号机',
|
||||
routeName: 'B区路线01',
|
||||
title: 'work_v2.demo_zone_b_task',
|
||||
zone: 'work_v2.area.demo_zone_b',
|
||||
robot: 'work_v2.demo_robot_2',
|
||||
routeName: 'work_v2.demo_route_b1',
|
||||
status: _PlanStatus.done,
|
||||
progress: 1,
|
||||
),
|
||||
_DemoPlan(
|
||||
time: '09:10',
|
||||
title: 'C区 · 雨后补割',
|
||||
zone: 'C 区 · 苗圃',
|
||||
robot: '山东01号机',
|
||||
routeName: 'C区覆盖01',
|
||||
title: 'work_v2.demo_task_c_retry',
|
||||
zone: 'work_v2.area.demo_zone_c',
|
||||
robot: 'work_v2.demo_robot_1',
|
||||
routeName: 'work_v2.route_lib.demo_route_c_cov',
|
||||
status: _PlanStatus.aborted,
|
||||
progress: 0.42,
|
||||
),
|
||||
@@ -146,6 +156,14 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
),
|
||||
];
|
||||
|
||||
/// 顶部筛选文案(顺序:全部 / 执行中 / 待执行 / 已完成)
|
||||
List<String> _filterLabels(AppLocalizations l10n) => <String>[
|
||||
l10n.translate('work_v2.plan.filter_all'),
|
||||
l10n.translate('work_v2.plan.status_running'),
|
||||
l10n.translate('work_v2.plan.status_pending'),
|
||||
l10n.translate('work_v2.plan.status_done'),
|
||||
];
|
||||
|
||||
void _toast(String text) => CapsuleToast.show(text, showCheck: false);
|
||||
|
||||
/// 当前筛选下的分组(分组内无匹配则整组隐藏)
|
||||
@@ -160,7 +178,14 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
for (final day in _days) {
|
||||
final plans = day.plans.where((p) => p.status == want).toList();
|
||||
if (plans.isNotEmpty) {
|
||||
out.add(_DemoDay(label: day.label, date: day.date, plans: plans));
|
||||
out.add(
|
||||
_DemoDay(
|
||||
label: day.label,
|
||||
date: day.date,
|
||||
weekday: day.weekday,
|
||||
plans: plans,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
@@ -168,58 +193,63 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final days = _visible;
|
||||
return WorkPhoneScaffold(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
WorkPhoneTopBar(
|
||||
title: '作业计划',
|
||||
title: l10n.translate('work_v2.plan.title'),
|
||||
onBack: () => Navigator.of(context).maybePop(),
|
||||
trailing: Row(
|
||||
children: [
|
||||
WorkSquareButton(
|
||||
icon: Icons.calendar_month_outlined,
|
||||
size: 17,
|
||||
onTap: () => _toast('日历视图接口未接入(演示)'),
|
||||
onTap: () =>
|
||||
_toast(l10n.translate('work_v2.plan.toast_calendar_todo')),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
WorkSquareButton(
|
||||
icon: Icons.add_rounded,
|
||||
label: '新建',
|
||||
label: l10n.translate('work_v2.plan.new'),
|
||||
primary: true,
|
||||
onTap: () => _toast('任务编排接口未接入(演示)'),
|
||||
onTap: () =>
|
||||
Navigator.of(
|
||||
context,
|
||||
).push(WorkPlanCreatePageV2.route()),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const WorkPageHeading(
|
||||
title: '任务列表与计划',
|
||||
subtitle: '按日期排布作业任务,执行中的任务会实时推进进度',
|
||||
WorkPageHeading(
|
||||
title: l10n.translate('work_v2.plan.page_title'),
|
||||
subtitle: l10n.translate('work_v2.plan.page_subtitle'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
WorkFilterRow(
|
||||
items: _filters,
|
||||
items: _filterLabels(l10n),
|
||||
index: _filter,
|
||||
onChanged: (i) => setState(() => _filter = i),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: days.isEmpty
|
||||
? _buildEmpty()
|
||||
? _buildEmpty(l10n)
|
||||
: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
children: [
|
||||
for (final day in days) ...[
|
||||
_buildDayHeader(day),
|
||||
_buildDayHeader(l10n, day),
|
||||
const SizedBox(height: 8),
|
||||
for (var i = 0; i < day.plans.length; i++)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: i == day.plans.length - 1 ? 0 : 10,
|
||||
),
|
||||
child: _buildPlanCard(day.plans[i]),
|
||||
child: _buildPlanCard(l10n, day.plans[i]),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
],
|
||||
@@ -231,7 +261,7 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmpty() {
|
||||
Widget _buildEmpty(AppLocalizations l10n) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -250,9 +280,9 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'暂无该状态的作业计划',
|
||||
style: TextStyle(fontSize: 12.5, color: _gray),
|
||||
Text(
|
||||
l10n.translate('work_v2.plan.empty'),
|
||||
style: const TextStyle(fontSize: 12.5, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -260,8 +290,8 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
}
|
||||
|
||||
// ===== 日期分组头 =====
|
||||
Widget _buildDayHeader(_DemoDay day) {
|
||||
final bool today = day.label == '今天';
|
||||
Widget _buildDayHeader(AppLocalizations l10n, _DemoDay day) {
|
||||
final bool today = day.label == 'today';
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
@@ -274,7 +304,7 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
Text(
|
||||
day.label,
|
||||
l10n.translate('work_v2.plan.day_${day.label}'),
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
@@ -282,10 +312,15 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(day.date, style: const TextStyle(fontSize: 11, color: _gray)),
|
||||
Text(
|
||||
'${day.date} ${l10n.translate('work_v2.plan.weekday_${day.weekday}')}',
|
||||
style: const TextStyle(fontSize: 11, color: _gray),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'${day.plans.length} 个任务',
|
||||
l10n
|
||||
.translate('work_v2.plan.task_count')
|
||||
.replaceAll('%s', '${day.plans.length}'),
|
||||
style: const TextStyle(fontSize: 10.5, color: kWtHint),
|
||||
),
|
||||
],
|
||||
@@ -293,12 +328,28 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
}
|
||||
|
||||
// ===== 计划卡 =====
|
||||
Widget _buildPlanCard(_DemoPlan p) {
|
||||
Widget _buildPlanCard(AppLocalizations l10n, _DemoPlan p) {
|
||||
final (Color color, Color bg, String label) = switch (p.status) {
|
||||
_PlanStatus.running => (kWtBlue, kWtSoftBlue, '执行中'),
|
||||
_PlanStatus.pending => (_orange, kWtWarnBg, '待执行'),
|
||||
_PlanStatus.done => (_green, kWtGreenBg, '已完成'),
|
||||
_PlanStatus.aborted => (_red, const Color(0xFFFDECEB), '已中止'),
|
||||
_PlanStatus.running => (
|
||||
kWtBlue,
|
||||
kWtSoftBlue,
|
||||
l10n.translate('work_v2.plan.status_running'),
|
||||
),
|
||||
_PlanStatus.pending => (
|
||||
_orange,
|
||||
kWtWarnBg,
|
||||
l10n.translate('work_v2.plan.status_pending'),
|
||||
),
|
||||
_PlanStatus.done => (
|
||||
_green,
|
||||
kWtGreenBg,
|
||||
l10n.translate('work_v2.plan.status_done'),
|
||||
),
|
||||
_PlanStatus.aborted => (
|
||||
_red,
|
||||
const Color(0xFFFDECEB),
|
||||
l10n.translate('work_v2.plan.status_aborted'),
|
||||
),
|
||||
};
|
||||
|
||||
return Container(
|
||||
@@ -336,9 +387,9 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 1),
|
||||
const Text(
|
||||
'开始',
|
||||
style: TextStyle(fontSize: 8.5, color: kWtHint),
|
||||
Text(
|
||||
l10n.translate('work_v2.plan.start'),
|
||||
style: const TextStyle(fontSize: 8.5, color: kWtHint),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -352,7 +403,7 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
p.title,
|
||||
l10n.translate(p.title),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
@@ -385,7 +436,7 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${p.zone} · ${p.robot}',
|
||||
'${l10n.translate(p.zone)} · ${l10n.translate(p.robot)}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 11, color: _gray),
|
||||
@@ -417,7 +468,7 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
const SizedBox(width: 3),
|
||||
Expanded(
|
||||
child: Text(
|
||||
p.routeName,
|
||||
l10n.translate(p.routeName),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 10.5, color: kWtHint),
|
||||
@@ -440,24 +491,32 @@ class _WorkPlanPageV2State extends State<WorkPlanPageV2> {
|
||||
// 已结束的计划:直接看这一票的单次作业报告
|
||||
Navigator.of(
|
||||
context,
|
||||
).push(WorkReportPageV2.route(taskName: p.title));
|
||||
).push(
|
||||
WorkReportPageV2.route(
|
||||
taskName: l10n.translate(p.title),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
_toast('计划详情接口未接入(演示)');
|
||||
_toast(l10n.translate('work_v2.plan.toast_detail_todo'));
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const Row(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'详情',
|
||||
style: TextStyle(
|
||||
l10n.translate('work_v2.plan.detail'),
|
||||
style: const TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: kWtBlue,
|
||||
),
|
||||
),
|
||||
Icon(Icons.chevron_right_rounded, size: 15, color: kWtBlue),
|
||||
const Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
size: 15,
|
||||
color: kWtBlue,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/widgets/autonomous/work_ui.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/work/presentation/pages/work_report_page_v2.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/work/presentation/widgets/work_phone_ui.dart';
|
||||
@@ -48,13 +49,13 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
static const Color _green = Color(0xFF00B42A);
|
||||
static const Color _abort = Color(0xFFF0483E);
|
||||
|
||||
static const List<String> _filters = <String>['全部', '已完成', '已中止', '本周'];
|
||||
/// 筛选顺序:全部 / 已完成 / 已中止 / 本周
|
||||
int _filter = 0;
|
||||
|
||||
static const List<_DemoRecord> _records = <_DemoRecord>[
|
||||
_DemoRecord(
|
||||
title: 'B区 · 清晨割草',
|
||||
robot: '山东02号机',
|
||||
title: 'work_v2.demo_zone_b_task',
|
||||
robot: 'work_v2.demo_robot_2',
|
||||
date: '2026-10-26 08:00',
|
||||
area: '2 860 m²',
|
||||
duration: '2 h 42 min',
|
||||
@@ -62,8 +63,8 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
coverage: '98.6%',
|
||||
),
|
||||
_DemoRecord(
|
||||
title: 'A区 · 定点巡检',
|
||||
robot: '山东01号机',
|
||||
title: 'work_v2.demo_task_a_inspect',
|
||||
robot: 'work_v2.demo_robot_1',
|
||||
date: '2026-10-25 16:20',
|
||||
area: '1 240 m²',
|
||||
duration: '1 h 05 min',
|
||||
@@ -71,8 +72,8 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
coverage: '97.2%',
|
||||
),
|
||||
_DemoRecord(
|
||||
title: 'C区 · 雨后补割',
|
||||
robot: '山东01号机',
|
||||
title: 'work_v2.demo_task_c_retry',
|
||||
robot: 'work_v2.demo_robot_1',
|
||||
date: '2026-10-25 09:10',
|
||||
area: '640 m²',
|
||||
duration: '0 h 38 min',
|
||||
@@ -80,8 +81,8 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
coverage: '42.5%',
|
||||
),
|
||||
_DemoRecord(
|
||||
title: 'A区 · 自主割草',
|
||||
robot: '山东02号机',
|
||||
title: 'work_v2.demo_task_zone_a',
|
||||
robot: 'work_v2.demo_robot_2',
|
||||
date: '2026-10-24 14:00',
|
||||
area: '3 120 m²',
|
||||
duration: '3 h 12 min',
|
||||
@@ -89,8 +90,8 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
coverage: '99.1%',
|
||||
),
|
||||
_DemoRecord(
|
||||
title: 'D区 · 边界修整',
|
||||
robot: '山东03号机',
|
||||
title: 'work_v2.demo_task_d_edge',
|
||||
robot: 'work_v2.demo_robot_3',
|
||||
date: '2026-10-23 10:30',
|
||||
area: '980 m²',
|
||||
duration: '1 h 12 min',
|
||||
@@ -99,6 +100,14 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
),
|
||||
];
|
||||
|
||||
/// 顶部筛选文案(顺序:全部 / 已完成 / 已中止 / 本周)
|
||||
List<String> _filterLabels(AppLocalizations l10n) => <String>[
|
||||
l10n.translate('work_v2.record.filter_all'),
|
||||
l10n.translate('work_v2.record.filter_done'),
|
||||
l10n.translate('work_v2.record.filter_aborted'),
|
||||
l10n.translate('work_v2.record.filter_week'),
|
||||
];
|
||||
|
||||
void _toast(String text) => CapsuleToast.show(text, showCheck: false);
|
||||
|
||||
/// 当前筛选下要显示的记录
|
||||
@@ -117,47 +126,54 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
}
|
||||
|
||||
void _openReport(_DemoRecord r) {
|
||||
Navigator.of(context).push(WorkReportPageV2.route(taskName: r.title));
|
||||
Navigator.of(context).push(
|
||||
WorkReportPageV2.route(
|
||||
taskName: AppLocalizations.of(context).translate(r.title),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final records = _visible;
|
||||
return WorkPhoneScaffold(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
WorkPhoneTopBar(
|
||||
title: '作业记录',
|
||||
title: l10n.translate('work_v2.record.title'),
|
||||
onBack: () => Navigator.of(context).maybePop(),
|
||||
trailing: WorkSquareButton(
|
||||
icon: Icons.file_download_outlined,
|
||||
size: 17,
|
||||
onTap: () => _toast('批量导出接口未接入(演示)'),
|
||||
onTap: () =>
|
||||
_toast(l10n.translate('work_v2.record.toast_export_todo')),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const WorkPageHeading(
|
||||
title: '作业记录',
|
||||
subtitle: '按月归档每一次作业,点开可查看单次作业报告',
|
||||
WorkPageHeading(
|
||||
title: l10n.translate('work_v2.record.title'),
|
||||
subtitle: l10n.translate('work_v2.record.page_subtitle'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildSummary(),
|
||||
_buildSummary(l10n),
|
||||
const SizedBox(height: 12),
|
||||
WorkFilterRow(
|
||||
items: _filters,
|
||||
items: _filterLabels(l10n),
|
||||
index: _filter,
|
||||
onChanged: (i) => setState(() => _filter = i),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: records.isEmpty
|
||||
? _buildEmpty()
|
||||
? _buildEmpty(l10n)
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
itemCount: records.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, i) => _buildRecordCard(records[i]),
|
||||
itemBuilder: (context, i) =>
|
||||
_buildRecordCard(l10n, records[i]),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -166,7 +182,7 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
}
|
||||
|
||||
// ===== 本月汇总 =====
|
||||
Widget _buildSummary() {
|
||||
Widget _buildSummary(AppLocalizations l10n) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 14, 12),
|
||||
decoration: BoxDecoration(
|
||||
@@ -189,9 +205,9 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'本月作业',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
l10n.translate('work_v2.record.summary_title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
@@ -217,10 +233,19 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: const [
|
||||
_SummaryCell(value: '18', label: '作业次数'),
|
||||
_SummaryCell(value: '4.6', label: '累计面积(亩)'),
|
||||
_SummaryCell(value: '21.3', label: '作业时长(h)'),
|
||||
children: [
|
||||
_SummaryCell(
|
||||
value: '18',
|
||||
label: l10n.translate('work_v2.record.summary_count'),
|
||||
),
|
||||
_SummaryCell(
|
||||
value: '4.6',
|
||||
label: l10n.translate('work_v2.record.summary_area'),
|
||||
),
|
||||
_SummaryCell(
|
||||
value: '21.3',
|
||||
label: l10n.translate('work_v2.record.summary_hours'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -228,7 +253,7 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmpty() {
|
||||
Widget _buildEmpty(AppLocalizations l10n) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -247,9 +272,9 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'该筛选下暂无作业记录',
|
||||
style: TextStyle(fontSize: 12.5, color: _gray),
|
||||
Text(
|
||||
l10n.translate('work_v2.record.empty'),
|
||||
style: const TextStyle(fontSize: 12.5, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -257,7 +282,7 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
}
|
||||
|
||||
// ===== 记录卡 =====
|
||||
Widget _buildRecordCard(_DemoRecord r) {
|
||||
Widget _buildRecordCard(AppLocalizations l10n, _DemoRecord r) {
|
||||
final Color statusColor = r.done ? _green : _abort;
|
||||
final Color statusBg = r.done
|
||||
? const Color(0xFFE8F8EC)
|
||||
@@ -280,7 +305,7 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
r.title,
|
||||
l10n.translate(r.title),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
@@ -301,7 +326,9 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
r.done ? '已完成' : '已中止',
|
||||
r.done
|
||||
? l10n.translate('work_v2.plan.status_done')
|
||||
: l10n.translate('work_v2.plan.status_aborted'),
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
@@ -313,7 +340,7 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
'${r.robot} · ${r.date}',
|
||||
'${l10n.translate(r.robot)} · ${r.date}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 11.5, color: _gray),
|
||||
@@ -336,9 +363,9 @@ class _WorkRecordPageV2State extends State<WorkRecordPageV2> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
const Text(
|
||||
'报告',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
l10n.translate('work_v2.record.report'),
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: kWtBlue,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/geoserver_suzhou_layer.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/widgets/autonomous/work_ui.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
@@ -14,12 +15,12 @@ import 'package:maibu_satabot_v2/features/v2/work/presentation/widgets/work_phon
|
||||
/// 本页为演示页:所有数字都是写死的示例值,不查询真实作业记录,
|
||||
/// 也不做 PDF 导出(点了只提示「导出接口未接入」)。
|
||||
class WorkReportPageV2 extends StatelessWidget {
|
||||
const WorkReportPageV2({super.key, this.taskName = 'B区 · 清晨割草'});
|
||||
const WorkReportPageV2({super.key, this.taskName});
|
||||
|
||||
/// 从记录列表带进来的任务名,仅用于标题展示
|
||||
final String taskName;
|
||||
/// 从记录列表带进来的任务名,仅用于标题展示;为空时用当前语言的演示任务名
|
||||
final String? taskName;
|
||||
|
||||
static Route<void> route({String taskName = 'B区 · 清晨割草'}) {
|
||||
static Route<void> route({String? taskName}) {
|
||||
return MaterialPageRoute<void>(
|
||||
builder: (_) => WorkReportPageV2(taskName: taskName),
|
||||
);
|
||||
@@ -41,17 +42,19 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
return WorkPhoneScaffold(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
WorkPhoneTopBar(
|
||||
title: '作业报告',
|
||||
title: l10n.translate('work_v2.report.title'),
|
||||
onBack: () => Navigator.of(context).maybePop(),
|
||||
trailing: WorkSquareButton(
|
||||
icon: Icons.ios_share_rounded,
|
||||
size: 17,
|
||||
onTap: () => _toast('分享接口未接入(演示)'),
|
||||
onTap: () =>
|
||||
_toast(l10n.translate('work_v2.report.toast_share_todo')),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -59,17 +62,17 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
children: [
|
||||
_buildHeader(),
|
||||
_buildHeader(l10n),
|
||||
const SizedBox(height: 12),
|
||||
_buildMapCard(),
|
||||
_buildMapCard(l10n),
|
||||
const SizedBox(height: 12),
|
||||
_buildMetrics(),
|
||||
_buildMetrics(l10n),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoCard(),
|
||||
_buildInfoCard(l10n),
|
||||
const SizedBox(height: 12),
|
||||
_buildEventCard(),
|
||||
_buildEventCard(l10n),
|
||||
const SizedBox(height: 14),
|
||||
_buildActions(context),
|
||||
_buildActions(context, l10n),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -79,7 +82,7 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
}
|
||||
|
||||
// ===== 标题区:任务名 + 完成状态 =====
|
||||
Widget _buildHeader() {
|
||||
Widget _buildHeader(AppLocalizations l10n) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -87,7 +90,7 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
taskName,
|
||||
taskName ?? l10n.translate('work_v2.demo_zone_b_task'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
@@ -104,9 +107,9 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
color: _greenBg,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: const Text(
|
||||
'已完成',
|
||||
style: TextStyle(
|
||||
child: Text(
|
||||
l10n.translate('work_v2.plan.status_done'),
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _green,
|
||||
@@ -116,23 +119,25 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
const Text(
|
||||
'2026-10-26 08:00 — 10:42 · 山东02号机',
|
||||
style: TextStyle(fontSize: 12, color: _gray),
|
||||
Text(
|
||||
l10n
|
||||
.translate('work_v2.report.time_subtitle')
|
||||
.replaceAll('%s', l10n.translate('work_v2.demo_robot_2')),
|
||||
style: const TextStyle(fontSize: 12, color: _gray),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 轨迹缩略图 =====
|
||||
Widget _buildMapCard() {
|
||||
Widget _buildMapCard(AppLocalizations l10n) {
|
||||
return Stack(
|
||||
children: [
|
||||
WorkMapThumb(
|
||||
center: _center,
|
||||
height: 158,
|
||||
radius: 16,
|
||||
badgeText: '实际作业轨迹',
|
||||
badgeText: l10n.translate('work_v2.report.trace_badge'),
|
||||
showAreas: true,
|
||||
showRoute: true,
|
||||
showRobot: false,
|
||||
@@ -146,14 +151,14 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
color: Colors.white.withValues(alpha: 0.94),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Row(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.timeline_rounded, size: 13, color: kWtBlue),
|
||||
SizedBox(width: 4),
|
||||
const Icon(Icons.timeline_rounded, size: 13, color: kWtBlue),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'轨迹回放',
|
||||
style: TextStyle(
|
||||
l10n.translate('work_v2.report.trace_replay'),
|
||||
style: const TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: kWtNavy,
|
||||
@@ -168,12 +173,12 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
}
|
||||
|
||||
// ===== 4 个关键指标(2×2:竖屏宽度放不下四列) =====
|
||||
Widget _buildMetrics() {
|
||||
const metrics = <(String, String, String)>[
|
||||
('作业面积', '2 860', 'm²'),
|
||||
('作业时长', '2 h 42', 'min'),
|
||||
('覆盖率', '98.6', '%'),
|
||||
('耗电', '34', '%'),
|
||||
Widget _buildMetrics(AppLocalizations l10n) {
|
||||
final metrics = <(String, String, String)>[
|
||||
(l10n.translate('work_v2.report.metric_area'), '2 860', 'm²'),
|
||||
(l10n.translate('work_v2.report.metric_duration'), '2 h 42', 'min'),
|
||||
(l10n.translate('work_v2.report.metric_coverage'), '98.6', '%'),
|
||||
(l10n.translate('work_v2.report.metric_power'), '34', '%'),
|
||||
];
|
||||
return Column(
|
||||
children: [
|
||||
@@ -242,13 +247,24 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
}
|
||||
|
||||
// ===== 作业信息 =====
|
||||
Widget _buildInfoCard() {
|
||||
const rows = <(String, String)>[
|
||||
('作业区域', 'B区 · 东侧草坪'),
|
||||
('作业路线', 'B区路线01 · 往复式'),
|
||||
('执行设备', '山东02号机'),
|
||||
('开始时间', '2026-10-26 08:00'),
|
||||
('结束时间', '2026-10-26 10:42'),
|
||||
Widget _buildInfoCard(AppLocalizations l10n) {
|
||||
final rows = <(String, String)>[
|
||||
(
|
||||
l10n.translate('work_v2.report.info_zone'),
|
||||
l10n.translate('work_v2.area.demo_zone_b'),
|
||||
),
|
||||
(
|
||||
l10n.translate('work_v2.report.info_route'),
|
||||
l10n
|
||||
.translate('work_v2.report.demo_route_pattern')
|
||||
.replaceAll('%s', l10n.translate('work_v2.demo_route_b1')),
|
||||
),
|
||||
(
|
||||
l10n.translate('work_v2.report.info_device'),
|
||||
l10n.translate('work_v2.demo_robot_2'),
|
||||
),
|
||||
(l10n.translate('work_v2.report.info_start'), '2026-10-26 08:00'),
|
||||
(l10n.translate('work_v2.report.info_end'), '2026-10-26 10:42'),
|
||||
];
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 14, 6),
|
||||
@@ -260,9 +276,9 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'作业信息',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
l10n.translate('work_v2.report.info_title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
@@ -302,12 +318,30 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
}
|
||||
|
||||
// ===== 过程节点 =====
|
||||
Widget _buildEventCard() {
|
||||
const events = <(String, String, String)>[
|
||||
('08:00', '任务下发成功', '设备已接受任务并原地自检'),
|
||||
('08:06', '进入 B 区开始作业', '沿 B区路线01 往复推进'),
|
||||
('09:58', '中途补充割草高度', '人工干预:割草高度 45 → 50 mm'),
|
||||
('10:42', '作业完成并返航', '回到充电桩,剩余电量 66%'),
|
||||
Widget _buildEventCard(AppLocalizations l10n) {
|
||||
final events = <(String, String, String)>[
|
||||
(
|
||||
'08:00',
|
||||
l10n.translate('work_v2.report.event1_title'),
|
||||
l10n.translate('work_v2.report.event1_desc'),
|
||||
),
|
||||
(
|
||||
'08:06',
|
||||
l10n.translate('work_v2.report.event2_title'),
|
||||
l10n
|
||||
.translate('work_v2.report.event2_desc')
|
||||
.replaceAll('%s', l10n.translate('work_v2.demo_route_b1')),
|
||||
),
|
||||
(
|
||||
'09:58',
|
||||
l10n.translate('work_v2.report.event3_title'),
|
||||
l10n.translate('work_v2.report.event3_desc'),
|
||||
),
|
||||
(
|
||||
'10:42',
|
||||
l10n.translate('work_v2.report.event4_title'),
|
||||
l10n.translate('work_v2.report.event4_desc'),
|
||||
),
|
||||
];
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 14, 12),
|
||||
@@ -319,9 +353,9 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'过程记录',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
l10n.translate('work_v2.report.event_title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
@@ -422,7 +456,7 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
}
|
||||
|
||||
// ===== 底部动作 =====
|
||||
Widget _buildActions(BuildContext context) {
|
||||
Widget _buildActions(BuildContext context, AppLocalizations l10n) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -437,9 +471,9 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: _border),
|
||||
),
|
||||
child: const Text(
|
||||
'返回记录',
|
||||
style: TextStyle(
|
||||
child: Text(
|
||||
l10n.translate('work_v2.report.back_to_records'),
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
@@ -451,7 +485,8 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => _toast('报告导出接口未接入(演示)'),
|
||||
onTap: () =>
|
||||
_toast(l10n.translate('work_v2.report.toast_export_todo')),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
height: 46,
|
||||
@@ -462,9 +497,9 @@ class WorkReportPageV2 extends StatelessWidget {
|
||||
),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: const Text(
|
||||
'导出报告',
|
||||
style: TextStyle(
|
||||
child: Text(
|
||||
l10n.translate('work_v2.report.export'),
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
|
||||
@@ -3,7 +3,14 @@ import 'package:flutter/services.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.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/home/presentation/widgets/map/geoserver_suzhou_layer.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/bloc/robot_list_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/bloc/robot_list_event.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/bloc/robot_list_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/pages/robot_autonomous_work_page_v2.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/pages/route_editor_page_v2.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/widgets/autonomous/work_ui.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
@@ -11,11 +18,12 @@ import 'package:maibu_satabot_v2/features/v2/work/presentation/widgets/work_phon
|
||||
|
||||
/// 路线库(W05)——作业首页「路线库」入口进入。
|
||||
///
|
||||
/// 竖屏单页:按作业区归档的覆盖路线,卡片上直给长度 / 预估时长 / 间距,
|
||||
/// 「新建路线」「编辑」都进入横屏「地图与区域编辑」绘制。
|
||||
/// 竖屏单页:展示**当前选中场站下的所有路线**,数据不写死,
|
||||
/// 与自主作业中心右侧抽屉「路线库」同源,都走 [AutonomousWorkGateway.loadRoutes]
|
||||
/// (A 环境即作业记录 selectBySiteId,B 环境由对应实现决定)。
|
||||
///
|
||||
/// 本页为演示页:路线是写死的示例,不读真实路线数据;
|
||||
/// 「应用到任务」只做界面反馈,不写全局任务状态。
|
||||
/// 点选一条路线 → 进入横屏「自主作业中心」,进页即选中该路线并画线;
|
||||
/// 「新建路线」「编辑」进入横屏「地图与区域编辑」绘制。
|
||||
class WorkRouteLibraryPageV2 extends StatefulWidget {
|
||||
const WorkRouteLibraryPageV2({super.key});
|
||||
|
||||
@@ -26,95 +34,81 @@ class WorkRouteLibraryPageV2 extends StatefulWidget {
|
||||
State<WorkRouteLibraryPageV2> createState() => _WorkRouteLibraryPageV2State();
|
||||
}
|
||||
|
||||
/// 一条演示路线
|
||||
class _DemoRoute {
|
||||
const _DemoRoute({
|
||||
required this.name,
|
||||
required this.kind,
|
||||
required this.zone,
|
||||
required this.length,
|
||||
required this.duration,
|
||||
required this.spacing,
|
||||
required this.used,
|
||||
});
|
||||
|
||||
final String name;
|
||||
|
||||
/// 覆盖 / 返航 / 沿边
|
||||
final String kind;
|
||||
final String zone;
|
||||
final String length;
|
||||
final String duration;
|
||||
final String spacing;
|
||||
|
||||
/// 最近使用时间,空表示未使用
|
||||
final String used;
|
||||
}
|
||||
|
||||
class _WorkRouteLibraryPageV2State extends State<WorkRouteLibraryPageV2> {
|
||||
static const Color _navy = kWtNavy;
|
||||
static const Color _gray = kWtGray;
|
||||
static const Color _border = kWtBorder;
|
||||
static const Color _cyan = Color(0xFF00B8A8);
|
||||
static const Color _orange = Color(0xFFEE9A2E);
|
||||
|
||||
static const List<String> _filters = <String>['全部路线', '覆盖路线', '返航路线', '沿边路线'];
|
||||
static const List<String> _filterKeys = <String>[
|
||||
'all',
|
||||
'return',
|
||||
// 暂时注释:页面只保留「全部路线 + 返航路线」两个分栏,需要时恢复
|
||||
// 'coverage',
|
||||
// 'custom',
|
||||
];
|
||||
int _filter = 0;
|
||||
|
||||
static const List<_DemoRoute> _routes = <_DemoRoute>[
|
||||
_DemoRoute(
|
||||
name: 'A区路线01',
|
||||
kind: '覆盖路线',
|
||||
zone: 'A 区 · 主草坪',
|
||||
length: '486 m',
|
||||
duration: '42 min',
|
||||
spacing: '0.9 m',
|
||||
used: '今天 08:12',
|
||||
),
|
||||
_DemoRoute(
|
||||
name: 'B区路线01',
|
||||
kind: '覆盖路线',
|
||||
zone: 'B 区 · 东侧草坪',
|
||||
length: '392 m',
|
||||
duration: '35 min',
|
||||
spacing: '0.9 m',
|
||||
used: '今天 08:00',
|
||||
),
|
||||
_DemoRoute(
|
||||
name: 'B区沿边01',
|
||||
kind: '沿边路线',
|
||||
zone: 'B 区 · 东侧草坪',
|
||||
length: '164 m',
|
||||
duration: '14 min',
|
||||
spacing: '0.6 m',
|
||||
used: '昨天 16:40',
|
||||
),
|
||||
_DemoRoute(
|
||||
name: 'C区覆盖01',
|
||||
kind: '覆盖路线',
|
||||
zone: 'C 区 · 苗圃',
|
||||
length: '128 m',
|
||||
duration: '11 min',
|
||||
spacing: '0.7 m',
|
||||
used: '',
|
||||
),
|
||||
_DemoRoute(
|
||||
name: '全场返航路线',
|
||||
kind: '返航路线',
|
||||
zone: '全场',
|
||||
length: '96 m',
|
||||
duration: '9 min',
|
||||
spacing: '—',
|
||||
used: '今天 10:42',
|
||||
),
|
||||
];
|
||||
late final AutonomousWorkGateway _gateway = sl<AutonomousWorkGateway>();
|
||||
|
||||
/// 路线颜色(覆盖青绿 / 返航橙 / 沿边蓝)
|
||||
static const Map<String, Color> _kindColors = <String, Color>{
|
||||
'覆盖路线': _cyan,
|
||||
'返航路线': _orange,
|
||||
'沿边路线': kWtBlue,
|
||||
};
|
||||
List<WorkRouteOption> _routes = const <WorkRouteOption>[];
|
||||
bool _loading = true;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
/// 拉取当前场站下的所有路线:与自主作业抽屉面板同一链路
|
||||
/// (resolveScope → siteId → loadRoutes),页面不直接依赖任何接口。
|
||||
Future<void> _load() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
final scope = await _gateway.resolveScope(deviceId: '');
|
||||
final siteId = scope.siteId;
|
||||
if (!mounted) return;
|
||||
if (siteId == null) {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_error = AppLocalizations.of(
|
||||
context,
|
||||
).translate('work_v2.route_lib.no_site');
|
||||
});
|
||||
return;
|
||||
}
|
||||
final result = await _gateway.loadRoutes(siteId: siteId);
|
||||
if (!mounted) return;
|
||||
final routes = result.data ?? const <WorkRouteOption>[];
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_routes = routes;
|
||||
_error = routes.isEmpty
|
||||
? (result.error ??
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('work_v2.route_lib.empty_site'))
|
||||
: null;
|
||||
});
|
||||
}
|
||||
|
||||
/// 路线类型代码 -> 当前语言文案
|
||||
String _kindLabel(AppLocalizations l10n, String key) {
|
||||
switch (key) {
|
||||
case 'all':
|
||||
return l10n.translate('work_v2.route_lib.filter_all');
|
||||
case 'return':
|
||||
return l10n.translate('work_v2.route_lib.kind_return');
|
||||
case 'coverage':
|
||||
// 卡片角标仍在用覆盖/自定义文案,只是筛选分栏暂时注释
|
||||
return l10n.translate('work_v2.route_lib.kind_coverage');
|
||||
default:
|
||||
return l10n.translate('work_v2.route_lib.kind_custom');
|
||||
}
|
||||
}
|
||||
|
||||
void _toast(String text) => CapsuleToast.show(text, showCheck: false);
|
||||
|
||||
@@ -124,64 +118,127 @@ class _WorkRouteLibraryPageV2State extends State<WorkRouteLibraryPageV2> {
|
||||
const LatLng(31.083296, 120.840355);
|
||||
}
|
||||
|
||||
List<_DemoRoute> get _visible {
|
||||
/// 按分栏过滤:返航为预留项(作业记录接口暂无返航类型数据,选中显示空态);
|
||||
/// 覆盖/自定义模式过滤逻辑保留,恢复 _filterKeys 对应分栏即可重新生效
|
||||
List<WorkRouteOption> get _visible {
|
||||
if (_filter == 0) return _routes;
|
||||
final String kind = _filters[_filter];
|
||||
return _routes.where((r) => r.kind == kind).toList();
|
||||
final String kind = _filterKeys[_filter];
|
||||
if (kind == 'return') return const <WorkRouteOption>[];
|
||||
final bool wantCoverage = kind == 'coverage';
|
||||
return _routes.where((r) => r.coverageMode == wantCoverage).toList();
|
||||
}
|
||||
|
||||
/// 进入横屏「地图与区域编辑」画路线;返回后把方向还给竖屏
|
||||
/// 进入横屏「地图与区域编辑」画路线;返回后把方向还给竖屏并刷新列表
|
||||
Future<void> _openEditor() async {
|
||||
await Navigator.of(context).push(RouteEditorPageV2.route(deviceSn: ''));
|
||||
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
if (mounted) _load();
|
||||
}
|
||||
|
||||
/// 选中一条路线 → 进入横屏自主作业中心,进页即选中该路线并画线。
|
||||
///
|
||||
/// 设备取 RobotListBloc 已加载的真实设备(与作业首页「自主作业」入口同口径);
|
||||
/// 尚未加载过就先拉一次列表,本次提示稍后再进(不拿占位设备凑数)。
|
||||
Future<void> _useRoute(WorkRouteOption route) async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final bloc = sl<RobotListBloc>();
|
||||
final state = bloc.state;
|
||||
if (state is! RobotListLoaded || state.robots.isEmpty) {
|
||||
bloc.add(
|
||||
RobotListLoadData(siteId: sl<SiteCubit>().state.selectedSite?.id),
|
||||
);
|
||||
_toast(l10n.translate('work_v2.toast_loading_devices'));
|
||||
return;
|
||||
}
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => RobotAutonomousWorkPageV2(
|
||||
robot: state.robots.first,
|
||||
initialRoute: route,
|
||||
),
|
||||
),
|
||||
);
|
||||
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
// 作业中心里可能新建/更换过路线,返回后刷新
|
||||
if (mounted) _load();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final routes = _visible;
|
||||
return WorkPhoneScaffold(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
WorkPhoneTopBar(
|
||||
title: '路线库',
|
||||
title: l10n.translate('work_v2.route_lib.title'),
|
||||
onBack: () => Navigator.of(context).maybePop(),
|
||||
trailing: WorkSquareButton(
|
||||
icon: Icons.add_rounded,
|
||||
label: '新建',
|
||||
label: l10n.translate('work_v2.route_lib.new'),
|
||||
primary: true,
|
||||
onTap: _openEditor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const WorkPageHeading(
|
||||
title: '路线库',
|
||||
subtitle: '按作业区归档覆盖路线,可直接应用到新的作业任务',
|
||||
WorkPageHeading(
|
||||
title: l10n.translate('work_v2.route_lib.title'),
|
||||
subtitle: l10n.translate('work_v2.route_lib.page_subtitle'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
WorkFilterRow(
|
||||
items: _filters,
|
||||
items: _filterKeys.map((k) => _kindLabel(l10n, k)).toList(),
|
||||
index: _filter,
|
||||
onChanged: (i) => setState(() => _filter = i),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: routes.isEmpty
|
||||
? _buildEmpty()
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
itemCount: routes.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, i) => _buildRouteCard(routes[i]),
|
||||
),
|
||||
),
|
||||
Expanded(child: _buildBody(l10n, routes)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmpty() {
|
||||
Widget _buildBody(AppLocalizations l10n, List<WorkRouteOption> routes) {
|
||||
if (_loading) {
|
||||
return const Center(child: CircularProgressIndicator(strokeWidth: 2));
|
||||
}
|
||||
final error = _error;
|
||||
if (error != null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
error,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 12.5, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_smallAction(
|
||||
l10n.translate('work_v2.route_lib.reload'),
|
||||
_load,
|
||||
primary: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
if (routes.isEmpty) return _buildEmpty(l10n);
|
||||
return RefreshIndicator(
|
||||
onRefresh: _load,
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
itemCount: routes.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, i) => _buildRouteCard(l10n, routes[i]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmpty(AppLocalizations l10n) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -200,9 +257,9 @@ class _WorkRouteLibraryPageV2State extends State<WorkRouteLibraryPageV2> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'该类型下还没有路线',
|
||||
style: TextStyle(fontSize: 12.5, color: _gray),
|
||||
Text(
|
||||
l10n.translate('work_v2.route_lib.empty'),
|
||||
style: const TextStyle(fontSize: 12.5, color: _gray),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -210,136 +267,145 @@ class _WorkRouteLibraryPageV2State extends State<WorkRouteLibraryPageV2> {
|
||||
}
|
||||
|
||||
// ===== 路线卡 =====
|
||||
Widget _buildRouteCard(_DemoRoute r) {
|
||||
final Color kindColor = _kindColors[r.kind] ?? kWtBlue;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
Widget _buildRouteCard(AppLocalizations l10n, WorkRouteOption r) {
|
||||
final bool coverage = r.coverageMode;
|
||||
final Color kindColor = coverage ? _cyan : kWtBlue;
|
||||
final String kindLabel = _kindLabel(
|
||||
l10n,
|
||||
coverage ? 'coverage' : 'custom',
|
||||
);
|
||||
final subtitle = r.metaText ?? r.planModeLabel ?? '路线 #${r.id}';
|
||||
final imageUrl = r.imageUrl;
|
||||
final String enterLabel = l10n.translate('work_v2.enter_work_center');
|
||||
return Material(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: InkWell(
|
||||
// 点选路线 → 进入自主作业中心(进页即选中并画线)
|
||||
onTap: () => _useRoute(r),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// 顶部缩略图:叠一层路线示意
|
||||
Stack(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
WorkMapThumb(
|
||||
center: _center,
|
||||
height: 96,
|
||||
radius: 16,
|
||||
zoom: 17.6,
|
||||
showAreas: r.kind != '返航路线',
|
||||
showRoute: true,
|
||||
showRobot: false,
|
||||
),
|
||||
Positioned(
|
||||
left: 10,
|
||||
top: 10,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 3,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: kindColor,
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
),
|
||||
child: Text(
|
||||
r.kind,
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
// 顶部缩略图:优先作业截图(同自主作业抽屉列表项),无图回退场站底图
|
||||
Stack(
|
||||
children: [
|
||||
if (imageUrl != null && imageUrl.isNotEmpty)
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Image.network(
|
||||
imageUrl,
|
||||
height: 96,
|
||||
fit: BoxFit.cover,
|
||||
width: double.infinity,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) => _mapThumb(),
|
||||
),
|
||||
)
|
||||
else
|
||||
_mapThumb(),
|
||||
Positioned(
|
||||
left: 10,
|
||||
top: 10,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 3,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: kindColor,
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
),
|
||||
child: Text(
|
||||
kindLabel,
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(13, 10, 13, 11),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
r.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 11.5, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
enterLabel,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: kWtHint,
|
||||
),
|
||||
),
|
||||
),
|
||||
_smallAction(
|
||||
l10n.translate('work_v2.route_lib.edit'),
|
||||
_openEditor,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_smallAction(
|
||||
enterLabel,
|
||||
() => _useRoute(r),
|
||||
primary: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(13, 10, 13, 11),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
r.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (r.used.isNotEmpty)
|
||||
Text(
|
||||
'最近 ${r.used}',
|
||||
style: const TextStyle(fontSize: 10, color: kWtHint),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
r.zone,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 11.5, color: _gray),
|
||||
),
|
||||
const SizedBox(height: 9),
|
||||
Row(
|
||||
children: [
|
||||
_metaItem(Icons.straighten_rounded, r.length),
|
||||
const SizedBox(width: 14),
|
||||
_metaItem(Icons.schedule_rounded, r.duration),
|
||||
const SizedBox(width: 14),
|
||||
_metaItem(Icons.space_bar_rounded, r.spacing),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
const Spacer(),
|
||||
_smallAction('编辑', _openEditor),
|
||||
const SizedBox(width: 8),
|
||||
_smallAction(
|
||||
'应用到任务',
|
||||
() => _toast('任务编排接口未接入(演示)'),
|
||||
primary: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _metaItem(IconData icon, String text) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 12.5, color: kWtHint),
|
||||
const SizedBox(width: 3),
|
||||
Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: kWtGray2,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
/// 无作业截图时的占位缩略图:只展示场站底图,不画演示路线
|
||||
Widget _mapThumb() => WorkMapThumb(
|
||||
center: _center,
|
||||
height: 96,
|
||||
radius: 16,
|
||||
showRoute: false,
|
||||
showRobot: false,
|
||||
);
|
||||
|
||||
Widget _smallAction(String text, VoidCallback onTap, {bool primary = false}) {
|
||||
Widget _smallAction(
|
||||
String text,
|
||||
VoidCallback onTap, {
|
||||
bool primary = false,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/widgets/autonomous/work_ui.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/app_base_map_layer.dart';
|
||||
|
||||
/// 竖屏作业页通用外壳与小组件(W02/W03/W05/W07/W09/W10 共用)。
|
||||
/// 色板直接复用横屏作业中心的 [work_ui.dart],保证两套页面观感一致。
|
||||
@@ -344,13 +345,8 @@ class WorkMapThumb extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate:
|
||||
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
|
||||
userAgentPackageName: 'com.maibu.maibu_satabot_v2',
|
||||
minZoom: 0,
|
||||
maxZoom: 19,
|
||||
),
|
||||
// 底图:中文=ESRI,非中文=Google(不可达自动回退 ESRI)
|
||||
const AppBaseMapLayer(maxZoom: 22),
|
||||
if (showAreas) ...[
|
||||
PolygonLayer(
|
||||
polygons: [
|
||||
|
||||
Reference in New Issue
Block a user