2026-01-18 20:21:14 +08:00
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
|
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
2026-02-28 12:46:29 +08:00
|
|
|
|
|
|
|
|
import '../../data/models/device_add_path_point_model.dart';
|
2026-02-27 21:04:07 +08:00
|
|
|
enum DeviceOperationType {
|
|
|
|
|
none, // 无操作
|
|
|
|
|
unbind, // 解绑设备
|
|
|
|
|
updateName, // 修改设备名称
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 14:11:04 +08:00
|
|
|
enum AppState {
|
|
|
|
|
none, //无作业状态
|
|
|
|
|
routePlanning, //正在规划路径
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-01-18 20:21:14 +08:00
|
|
|
|
|
|
|
|
class DevicesState extends Equatable {
|
|
|
|
|
final List<DeviceEntity> devices; // 名下所有设备列表
|
|
|
|
|
final DeviceEntity? selectedDevice; // 当前主界面选中的/操作的设备
|
|
|
|
|
final bool isLoading; // 是否正在加载
|
|
|
|
|
final String? errorMessage; // 错误信息
|
2026-02-26 08:45:37 +08:00
|
|
|
final double? deviceLatitude; // 新增字段
|
|
|
|
|
final double? deviceLongitude; // 新增字段
|
2026-02-26 16:20:02 +08:00
|
|
|
final List<Map<String, dynamic>>? workRecords;
|
2026-02-27 21:04:07 +08:00
|
|
|
final DeviceOperationType operationType; // 标记当前操作类型
|
2026-02-27 15:33:59 +08:00
|
|
|
final List<Map<String, dynamic>>? pathData;
|
2026-02-28 12:46:29 +08:00
|
|
|
final List<DeviceAddPathPointModel>? generatedPath; // 新增字段
|
2026-03-02 14:11:04 +08:00
|
|
|
final AppState appState;
|
2026-02-28 12:46:29 +08:00
|
|
|
|
2026-02-27 15:33:59 +08:00
|
|
|
|
|
|
|
|
|
2026-01-18 20:21:14 +08:00
|
|
|
const DevicesState({
|
|
|
|
|
this.devices = const [],
|
|
|
|
|
this.selectedDevice,
|
|
|
|
|
this.isLoading = false,
|
|
|
|
|
this.errorMessage,
|
2026-02-26 08:45:37 +08:00
|
|
|
this.deviceLatitude,
|
|
|
|
|
this.deviceLongitude,
|
2026-02-27 21:04:07 +08:00
|
|
|
this.workRecords,
|
|
|
|
|
this.operationType = DeviceOperationType.none, // 默认无操作
|
2026-02-27 15:33:59 +08:00
|
|
|
this.pathData,
|
2026-02-28 12:46:29 +08:00
|
|
|
this.generatedPath,
|
2026-03-02 14:11:04 +08:00
|
|
|
this.appState = AppState.none,
|
2026-01-18 20:21:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 使用 copyWith 方便局部更新状态
|
|
|
|
|
DevicesState copyWith({
|
|
|
|
|
List<DeviceEntity>? devices,
|
|
|
|
|
DeviceEntity? selectedDevice,
|
|
|
|
|
bool? isLoading,
|
|
|
|
|
String? errorMessage,
|
2026-02-26 08:45:37 +08:00
|
|
|
double? deviceLatitude,
|
|
|
|
|
double? deviceLongitude,
|
2026-02-26 16:20:02 +08:00
|
|
|
List<Map<String, dynamic>>? workRecords,
|
2026-02-27 21:04:07 +08:00
|
|
|
DeviceOperationType? operationType,
|
2026-02-27 15:33:59 +08:00
|
|
|
List<Map<String, dynamic>>? pathData,
|
2026-02-28 12:46:29 +08:00
|
|
|
List<DeviceAddPathPointModel>? generatedPath,
|
2026-03-11 10:01:36 +08:00
|
|
|
AppState? appState,
|
2026-01-18 20:21:14 +08:00
|
|
|
}) {
|
|
|
|
|
return DevicesState(
|
|
|
|
|
devices: devices ?? this.devices,
|
|
|
|
|
selectedDevice: selectedDevice ?? this.selectedDevice,
|
|
|
|
|
isLoading: isLoading ?? this.isLoading,
|
|
|
|
|
errorMessage: errorMessage, // 错误信息通常每次更新都要重新赋值或清空
|
2026-02-26 08:45:37 +08:00
|
|
|
deviceLatitude: deviceLatitude ?? this.deviceLatitude,
|
|
|
|
|
deviceLongitude: deviceLongitude ?? this.deviceLongitude,
|
2026-02-27 15:33:59 +08:00
|
|
|
pathData: pathData ?? this.pathData,
|
2026-02-27 13:17:09 +08:00
|
|
|
workRecords: workRecords ?? this.workRecords,
|
2026-02-27 21:04:07 +08:00
|
|
|
operationType: operationType ?? this.operationType, // 更新操作类型
|
2026-02-28 17:06:14 +08:00
|
|
|
generatedPath: generatedPath ?? this.generatedPath, // 更新生成的路径数据
|
2026-03-11 10:01:36 +08:00
|
|
|
appState: appState ?? this.appState, // 更新应用状态
|
2026-01-18 20:21:14 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2026-02-26 08:45:37 +08:00
|
|
|
List<Object?> get props => [devices, selectedDevice, isLoading,
|
|
|
|
|
errorMessage,
|
|
|
|
|
deviceLatitude,
|
|
|
|
|
deviceLongitude,
|
2026-02-26 16:20:02 +08:00
|
|
|
workRecords,
|
2026-02-27 15:33:59 +08:00
|
|
|
pathData,
|
2026-02-28 17:06:14 +08:00
|
|
|
operationType,
|
|
|
|
|
generatedPath,
|
2026-03-11 10:01:36 +08:00
|
|
|
appState,
|
2026-02-26 08:45:37 +08:00
|
|
|
];
|
2026-01-18 20:21:14 +08:00
|
|
|
}
|