对接连续任务列表接口和连续任务下发,便捷操作中暂停任务的对接,底部导航tab项的设置根据用户角色显示和设置

This commit is contained in:
2026-11-11 16:51:21 +08:00
parent 47f518f94c
commit 985bcf4b55
54 changed files with 5017 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../domain/entities/work_history_record.dart';
import '../../domain/usecases/load_site_work_history_usecase.dart';
class WorkHistoryState {
const WorkHistoryState({
this.loading = false,
this.loaded = false,
this.total = 0,
this.records = const [],
this.error,
});
final bool loading;
final bool loaded;
final int total;
final List<WorkHistoryRecord> records;
final String? error;
}
/// 仅查询历史;不依赖任务池,也不下发或变更机器人任务。
class WorkHistoryCubit extends Cubit<WorkHistoryState> {
WorkHistoryCubit(this._load) : super(const WorkHistoryState());
final LoadSiteWorkHistoryUseCase _load;
(int, int)? _scope;
int _generation = 0;
Future<void> load({required int? siteId, required int? orgId}) async {
if (isClosed) return;
if (siteId == null || orgId == null || siteId <= 0 || orgId <= 0) {
++_generation;
_scope = null;
emit(const WorkHistoryState(error: '请先在首页选择有效场站'));
return;
}
final scope = (siteId, orgId);
if (_scope == scope && state.loading) return;
final keep = _scope == scope && state.loaded;
_scope = scope;
final generation = ++_generation;
emit(
WorkHistoryState(
loading: true,
loaded: keep,
records: keep ? state.records : const [],
total: keep ? state.total : 0,
),
);
try {
final result = await _load(siteId: siteId, orgId: orgId);
if (isClosed || generation != _generation) return;
result.fold(
(failure) => emit(
WorkHistoryState(
loaded: keep,
records: keep ? state.records : const [],
total: keep ? state.total : 0,
error: failure.message,
),
),
(page) => emit(
WorkHistoryState(
loaded: true,
total: page.total,
records: page.records,
),
),
);
} catch (error) {
if (!isClosed && generation == _generation) {
emit(
WorkHistoryState(
loaded: keep,
records: keep ? state.records : const [],
total: keep ? state.total : 0,
error: error.toString(),
),
);
}
}
}
@override
Future<void> close() {
++_generation;
return super.close();
}
}