页面UI替换1远程遥控和各项弹窗和作业主页面和子页面+路径规划的主页面重构等

This commit is contained in:
2026-10-28 14:38:24 +08:00
parent 8a41113c92
commit eb8dec2868
64 changed files with 25316 additions and 1174 deletions

View File

@@ -0,0 +1,240 @@
import 'package:latlong2/latlong.dart';
/// 跨环境统一的作业运行态:UI 只认这一套枚举。
/// 各环境自己的任务状态码(NEW/EXECUTING/PAUSE/… 或别的后端字段)
/// 由各自的 gateway 实现映射到这里,页面不感知原始状态码。
enum WorkRunState {
idle, // 准备:没有任何任务
queued, // 已下发,等待设备接单
running, // 执行中
paused, // 暂停 / 中断
finished, // 正常结束或被终止
failed, // 异常失败
}
extension WorkRunStateX on WorkRunState {
bool get hasTask => this != WorkRunState.idle;
bool get isRunning => this == WorkRunState.running;
bool get isPaused => this == WorkRunState.paused;
bool get isQueued => this == WorkRunState.queued;
bool get isFinished => this == WorkRunState.finished;
/// 顶部 5 段阶段胶囊的分组:failed 归到「暂停/中断」
WorkRunState get chipGroup =>
this == WorkRunState.failed ? WorkRunState.paused : this;
String get label => switch (this) {
WorkRunState.idle => '准备',
WorkRunState.queued => '待执行',
WorkRunState.running => '执行中',
WorkRunState.paused => '暂停/中断',
WorkRunState.finished => '已结束',
WorkRunState.failed => '异常中断',
};
}
/// 路线库中的一条可执行路线(对应路径规划列表里的一条作业记录)
class WorkRouteOption {
const WorkRouteOption({
required this.id,
required this.name,
this.pathPoints = const <LatLng>[],
this.outerPoints = const <LatLng>[],
this.planModeLabel,
this.imageUrl,
this.metaText,
this.coverageMode = true,
this.extras = const <String, dynamic>{},
});
/// 统一用字符串:A 环境是 int routeId,B 环境可能是 uuid / 名称
final String id;
final String name;
final List<LatLng> pathPoints;
final List<LatLng> outerPoints;
final String? planModeLabel;
final String? imageUrl;
final String? metaText;
/// 是否「覆盖模式」(A 环境 planModel == 0)。
/// 与路径规划页一致:覆盖模式画 outer 灰色半透明边界框,自定义模式不画。
final bool coverageMode;
/// 环境专有字段放这里,页面不解析
final Map<String, dynamic> extras;
bool get hasGeometry => pathPoints.isNotEmpty || outerPoints.isNotEmpty;
List<LatLng> get previewPoints =>
pathPoints.isNotEmpty ? pathPoints : outerPoints;
/// 预览时要画的边界框:只有覆盖模式才画(与路径规划选中路线的行为一致)
List<LatLng> get previewOuter =>
coverageMode ? outerPoints : const <LatLng>[];
/// 补齐几何时用:列表接口只给元数据,详情接口才给 path/outer。
WorkRouteOption copyWith({
String? id,
String? name,
List<LatLng>? pathPoints,
List<LatLng>? outerPoints,
String? planModeLabel,
String? imageUrl,
String? metaText,
bool? coverageMode,
Map<String, dynamic>? extras,
}) {
return WorkRouteOption(
id: id ?? this.id,
name: name ?? this.name,
pathPoints: pathPoints ?? this.pathPoints,
outerPoints: outerPoints ?? this.outerPoints,
planModeLabel: planModeLabel ?? this.planModeLabel,
imageUrl: imageUrl ?? this.imageUrl,
metaText: metaText ?? this.metaText,
coverageMode: coverageMode ?? this.coverageMode,
extras: extras ?? this.extras,
);
}
}
/// 任务快照:跨环境统一的只读视图
class WorkTaskSnapshot {
const WorkTaskSnapshot({
required this.taskId,
required this.deviceId,
required this.state,
this.routeId,
this.routeName,
this.rawStatus = '',
this.createdAt,
this.progress,
this.coveredArea,
this.plannedArea,
this.extras = const <String, dynamic>{},
});
final String taskId;
final String deviceId;
final WorkRunState state;
final String? routeId;
final String? routeName;
/// 环境原始状态码,仅用于展示/排障
final String rawStatus;
final String? createdAt;
/// 0~1;null 表示该环境不提供进度(页面显示不确定进度条)
final double? progress;
final double? coveredArea;
final double? plannedArea;
final Map<String, dynamic> extras;
bool get isActive =>
state == WorkRunState.queued ||
state == WorkRunState.running ||
state == WorkRunState.paused;
WorkTaskSnapshot copyWith({
WorkRunState? state,
String? rawStatus,
String? routeId,
String? routeName,
double? progress,
}) {
return WorkTaskSnapshot(
taskId: taskId,
deviceId: deviceId,
state: state ?? this.state,
routeId: routeId ?? this.routeId,
routeName: routeName ?? this.routeName,
rawStatus: rawStatus ?? this.rawStatus,
createdAt: createdAt,
progress: progress ?? this.progress,
coveredArea: coveredArea,
plannedArea: plannedArea,
extras: extras,
);
}
}
/// 环境能力声明:页面据此隐藏/禁用入口,而不是假设「所有环境功能一样」
class WorkSceneCapabilities {
const WorkSceneCapabilities({
this.routeLibrary = true,
this.taskQueue = true,
this.pause = true,
this.resume = true,
this.stop = true,
this.cancelQueued = true,
this.schedule = false,
this.routeEditing = false,
this.progress = false,
this.multiActiveTaskResolve = false,
});
final bool routeLibrary;
final bool taskQueue;
final bool pause;
final bool resume;
final bool stop;
final bool cancelQueued;
final bool schedule;
final bool routeEditing;
/// 是否下发真实进度(false 时页面不臆造百分比)
final bool progress;
/// 是否可能出现「多个活跃任务需要用户选择」
final bool multiActiveTaskResolve;
static const WorkSceneCapabilities none = WorkSceneCapabilities(
routeLibrary: false,
taskQueue: false,
pause: false,
resume: false,
stop: false,
cancelQueued: false,
);
}
/// 作业作用域:场站/组织等环境相关的上下文
class WorkScope {
const WorkScope({this.siteId, this.orgId});
final int? siteId;
final int? orgId;
bool get hasSite => siteId != null;
}
/// 下发作业的入参
class WorkStartRequest {
const WorkStartRequest({
required this.deviceId,
required this.route,
this.siteId,
this.orgId,
this.reuseTaskId,
this.extras = const <String, dynamic>{},
});
final String deviceId;
final WorkRouteOption route;
final int? siteId;
final int? orgId;
/// 复用设备上已存在的活跃任务(不再重复 createDeviceTask)
final String? reuseTaskId;
final Map<String, dynamic> extras;
}
/// 统一返回:不把 Either/Failure 泄漏给 UI,任何环境实现都能套
class WorkResult<T> {
const WorkResult.ok(T this.data) : error = null;
const WorkResult.fail(String this.error) : data = null;
final T? data;
final String? error;
bool get isOk => error == null;
}