对接连续任务列表接口和连续任务下发,便捷操作中暂停任务的对接,底部导航tab项的设置根据用户角色显示和设置
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../autonomous_work/domain/entities/return_plan_models.dart';
|
||||
import '../../../../autonomous_work/domain/usecases/load_site_return_plan_usecase.dart';
|
||||
|
||||
class ReturnPlanLibraryState {
|
||||
const ReturnPlanLibraryState({
|
||||
this.siteId,
|
||||
this.loading = false,
|
||||
this.loaded = false,
|
||||
this.plan,
|
||||
this.error,
|
||||
});
|
||||
final int? siteId;
|
||||
final bool loading;
|
||||
final bool loaded;
|
||||
final ReturnPlanDraft? plan;
|
||||
final String? error;
|
||||
}
|
||||
|
||||
class ReturnPlanLibraryCubit extends Cubit<ReturnPlanLibraryState> {
|
||||
ReturnPlanLibraryCubit(this._load) : super(const ReturnPlanLibraryState());
|
||||
final LoadSiteReturnPlanUseCase _load;
|
||||
int _generation = 0;
|
||||
(int, int)? _scope;
|
||||
|
||||
void clear() {
|
||||
++_generation;
|
||||
_scope = null;
|
||||
if (!isClosed) emit(const ReturnPlanLibraryState());
|
||||
}
|
||||
|
||||
Future<void> load({required int? siteId, required int? orgId}) async {
|
||||
if (isClosed) return;
|
||||
if (siteId == null || orgId == null || siteId <= 0 || orgId <= 0) {
|
||||
clear();
|
||||
emit(const ReturnPlanLibraryState(error: '请先在首页选择有效场站'));
|
||||
return;
|
||||
}
|
||||
final scope = (siteId, orgId);
|
||||
if (_scope == scope && state.loading) return;
|
||||
final keep = _scope == scope && state.loaded;
|
||||
final previous = keep ? state.plan : null;
|
||||
_scope = scope;
|
||||
final generation = ++_generation;
|
||||
emit(
|
||||
ReturnPlanLibraryState(
|
||||
siteId: siteId,
|
||||
loading: true,
|
||||
loaded: keep,
|
||||
plan: previous,
|
||||
),
|
||||
);
|
||||
debugPrint('[返航路线] 查询当前场站方案 siteId=$siteId, orgId=$orgId');
|
||||
final result = await _load(siteId: siteId, orgId: orgId);
|
||||
if (isClosed || generation != _generation) return;
|
||||
if (!result.isOk) {
|
||||
debugPrint('[返航路线] 查询失败:${result.error}');
|
||||
emit(
|
||||
ReturnPlanLibraryState(
|
||||
siteId: siteId,
|
||||
loaded: keep,
|
||||
plan: previous,
|
||||
error: result.error,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final plan = result.data;
|
||||
debugPrint(
|
||||
'[返航路线] 加载完成 id=${plan?.id}, 返航点=${plan?.restPoints.length ?? 0}, 障碍物=${plan?.obstacles.length ?? 0}',
|
||||
);
|
||||
emit(ReturnPlanLibraryState(siteId: siteId, loaded: true, plan: plan));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
++_generation;
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user