103 lines
3.2 KiB
Dart
103 lines
3.2 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
|
|
|
import '../../data/models/device_add_path_point_model.dart';
|
|
|
|
enum DeviceOperationType {
|
|
none, // 无操作
|
|
unbind, // 解绑设备
|
|
updateName, // 修改设备名称
|
|
}
|
|
|
|
enum AppState {
|
|
none, //无作业状态
|
|
routePlanning, //正在规划路径
|
|
}
|
|
|
|
class DevicesState extends Equatable {
|
|
final List<DeviceEntity> devices; // 名下所有设备列表
|
|
final DeviceEntity? selectedDevice; // 当前主界面选中的/操作的设备
|
|
final bool isLoading; // 是否正在加载
|
|
final String? errorMessage; // 错误信息
|
|
final double? deviceLatitude; // 新增字段
|
|
final double? deviceLongitude; // 新增字段
|
|
final List<Map<String, dynamic>>? workRecords;
|
|
final DeviceOperationType operationType; // 标记当前操作类型
|
|
final List<Map<String, dynamic>>? pathData;
|
|
final List<DeviceAddPathPointModel>? generatedPath; // 新增字段
|
|
final AppState appState;
|
|
final bool isFinshWork;
|
|
final double? arriLatitude;
|
|
final double? arriLongitude;
|
|
|
|
const DevicesState({
|
|
this.devices = const [],
|
|
this.selectedDevice,
|
|
this.isLoading = false,
|
|
this.errorMessage,
|
|
this.deviceLatitude,
|
|
this.deviceLongitude,
|
|
this.workRecords,
|
|
this.operationType = DeviceOperationType.none, // 默认无操作
|
|
this.pathData,
|
|
this.generatedPath,
|
|
this.appState = AppState.none,
|
|
this.isFinshWork = false,
|
|
this.arriLatitude,
|
|
this.arriLongitude,
|
|
});
|
|
|
|
// 使用 copyWith 方便局部更新状态
|
|
DevicesState copyWith({
|
|
List<DeviceEntity>? devices,
|
|
DeviceEntity? selectedDevice,
|
|
bool? isLoading,
|
|
String? errorMessage,
|
|
double? deviceLatitude,
|
|
double? deviceLongitude,
|
|
List<Map<String, dynamic>>? workRecords,
|
|
DeviceOperationType? operationType,
|
|
List<Map<String, dynamic>>? pathData,
|
|
List<DeviceAddPathPointModel>? generatedPath,
|
|
AppState? appState,
|
|
bool? isFinshWork,
|
|
double? arriLatitude,
|
|
double? arriLongitude,
|
|
}) {
|
|
return DevicesState(
|
|
devices: devices ?? this.devices,
|
|
selectedDevice: selectedDevice ?? this.selectedDevice,
|
|
isLoading: isLoading ?? this.isLoading,
|
|
errorMessage: errorMessage, // 错误信息通常每次更新都要重新赋值或清空
|
|
deviceLatitude: deviceLatitude ?? this.deviceLatitude,
|
|
deviceLongitude: deviceLongitude ?? this.deviceLongitude,
|
|
pathData: pathData ?? this.pathData,
|
|
workRecords: workRecords ?? this.workRecords,
|
|
operationType: operationType ?? this.operationType, // 更新操作类型
|
|
generatedPath: generatedPath ?? this.generatedPath, // 更新生成的路径数据
|
|
appState: appState ?? this.appState, // 更新应用状态
|
|
isFinshWork: isFinshWork ?? this.isFinshWork,
|
|
arriLatitude: arriLatitude ?? this.arriLatitude,
|
|
arriLongitude: arriLongitude ?? this.arriLongitude,
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
devices,
|
|
selectedDevice,
|
|
isLoading,
|
|
errorMessage,
|
|
deviceLatitude,
|
|
deviceLongitude,
|
|
workRecords,
|
|
pathData,
|
|
operationType,
|
|
generatedPath,
|
|
appState,
|
|
isFinshWork,
|
|
arriLatitude,
|
|
arriLongitude,
|
|
];
|
|
}
|