开始作业,
暂停作业, 停止作业, 回复作业, ---初步待使用
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
@@ -9,10 +11,12 @@ import 'package:maibu_satabot_v2/features/devices/domain/usecases/select_work_re
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/unbind_device_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/update_devicename_usecase.dart';
|
||||
|
||||
import '../../data/models/device_add_path_point_model.dart';
|
||||
import '../../data/models/device_work_area_param_model.dart';
|
||||
import '../../domain/usecases/delete_work_record_usecase.dart';
|
||||
import '../../domain/usecases/get_device_location_usecase.dart';
|
||||
import '../../domain/usecases/get_work_record_usecase.dart';
|
||||
import '../../domain/usecases/route_planning_usecase.dart';
|
||||
import 'devices_state.dart';
|
||||
|
||||
class DevicesCubit extends Cubit<DevicesState> {
|
||||
@@ -26,6 +30,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
final SelectWorkRecordUseCase _selectWorkRecordUseCase;
|
||||
final SaveWorkRecordUseCase _saveWorkRecordUseCase;
|
||||
final GeneratePathUseCase _generatePathUseCase;
|
||||
final RoutePlanningUseCase _routePlanningUseCase; //
|
||||
|
||||
DevicesCubit(
|
||||
this.repository,
|
||||
@@ -38,6 +43,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
this._selectWorkRecordUseCase,
|
||||
this._saveWorkRecordUseCase,
|
||||
this._generatePathUseCase,
|
||||
this._routePlanningUseCase
|
||||
) : super(const DevicesState());
|
||||
|
||||
Future<void> unbindDevice(String deviceId, String deviceName) async {
|
||||
@@ -239,4 +245,60 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
result.fold((failure) => emit(state.copyWith(errorMessage: failure.message)), (pathData) => emit(state.copyWith(generatedPath: pathData)));
|
||||
}
|
||||
// 开始路径规划
|
||||
Future<void> startRoutePlanning(Queue<DeviceAddPathPointModel> locationQueue) async {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
final result = await _routePlanningUseCase.startRoutePlanning(locationQueue);
|
||||
result.fold(
|
||||
(failure) => emit(state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: failure.message ?? '路径规划启动失败',
|
||||
)),
|
||||
(_) => emit(state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: '',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
// 暂停
|
||||
Future<void> pauseRoutePlanning() async {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
final result = await _routePlanningUseCase.pauseRPWork();
|
||||
result.fold(
|
||||
(failure) => emit(state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: failure.message ?? '暂停失败',
|
||||
)),
|
||||
(_) => emit(state.copyWith(isLoading: false)),
|
||||
);
|
||||
}
|
||||
|
||||
// 恢复
|
||||
Future<void> resumeRoutePlanning() async {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
final result = await _routePlanningUseCase.resumeRPWork();
|
||||
result.fold(
|
||||
(failure) => emit(state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: failure.message ?? '恢复失败',
|
||||
)),
|
||||
(_) => emit(state.copyWith(isLoading: false)),
|
||||
);
|
||||
}
|
||||
|
||||
// 停止
|
||||
Future<void> stopRoutePlanning() async {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
final result = await _routePlanningUseCase.stopRoutePlanning();
|
||||
result.fold(
|
||||
(failure) => emit(state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: failure.message ?? '停止失败',
|
||||
)),
|
||||
(_) => emit(state.copyWith(isLoading: false)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@ enum DeviceOperationType {
|
||||
updateName, // 修改设备名称
|
||||
}
|
||||
|
||||
enum AppState {
|
||||
none, //无作业状态
|
||||
routePlanning, //正在规划路径
|
||||
}
|
||||
|
||||
|
||||
|
||||
class DevicesState extends Equatable {
|
||||
final List<DeviceEntity> devices; // 名下所有设备列表
|
||||
@@ -20,6 +26,7 @@ class DevicesState extends Equatable {
|
||||
final DeviceOperationType operationType; // 标记当前操作类型
|
||||
final List<Map<String, dynamic>>? pathData;
|
||||
final List<DeviceAddPathPointModel>? generatedPath; // 新增字段
|
||||
final AppState appState;
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +41,7 @@ class DevicesState extends Equatable {
|
||||
this.operationType = DeviceOperationType.none, // 默认无操作
|
||||
this.pathData,
|
||||
this.generatedPath,
|
||||
this.appState = AppState.none,
|
||||
});
|
||||
|
||||
// 使用 copyWith 方便局部更新状态
|
||||
|
||||
Reference in New Issue
Block a user