告警中心的二级详情页面+信息中心的页面+对接机器人接口
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../domain/usecases/get_drone_station_list_usecase.dart';
|
||||
import '../../domain/usecases/get_video_stream_usecase.dart';
|
||||
import 'drone_station_event.dart';
|
||||
import 'drone_station_state.dart';
|
||||
|
||||
class DroneStationBloc extends Bloc<DroneStationEvent, DroneStationState> {
|
||||
final GetDroneStationListUseCase getDroneStationListUseCase;
|
||||
final GetUAVDetailUseCase getUAVDetailUseCase;
|
||||
final GetVideoStreamUseCase getVideoStreamUseCase;
|
||||
|
||||
DroneStationBloc(
|
||||
this.getDroneStationListUseCase,
|
||||
this.getUAVDetailUseCase,
|
||||
this.getVideoStreamUseCase,
|
||||
) : super(const DroneStationInitial()) {
|
||||
on<DroneStationLoadData>(_onLoadData);
|
||||
on<DroneStationRefresh>(_onRefresh);
|
||||
on<UAVDetailLoad>(_onUAVDetailLoad);
|
||||
on<VideoStreamLoad>(_onVideoStreamLoad);
|
||||
}
|
||||
|
||||
Future<void> _onLoadData(
|
||||
DroneStationLoadData event,
|
||||
Emitter<DroneStationState> emit,
|
||||
) async {
|
||||
emit(const DroneStationLoading());
|
||||
|
||||
final result = await getDroneStationListUseCase(event.siteId);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(DroneStationError(failure.message)),
|
||||
(stations) => emit(DroneStationLoaded(stations)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onRefresh(
|
||||
DroneStationRefresh event,
|
||||
Emitter<DroneStationState> emit,
|
||||
) async {
|
||||
if (state is DroneStationLoaded) {
|
||||
final result = await getDroneStationListUseCase(event.siteId);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(DroneStationError(failure.message)),
|
||||
(stations) => emit(DroneStationLoaded(stations)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onUAVDetailLoad(
|
||||
UAVDetailLoad event,
|
||||
Emitter<DroneStationState> emit,
|
||||
) async {
|
||||
emit(const UAVDetailLoading());
|
||||
|
||||
final result = await getUAVDetailUseCase(event.gatewaySn, event.deviceSn);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(UAVDetailError(failure.message)),
|
||||
(detail) => emit(UAVDetailLoaded(detail)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onVideoStreamLoad(
|
||||
VideoStreamLoad event,
|
||||
Emitter<DroneStationState> emit,
|
||||
) async {
|
||||
emit(const VideoStreamLoading());
|
||||
|
||||
final result = await getVideoStreamUseCase(
|
||||
sn: event.sn,
|
||||
cameraIndex: event.cameraIndex,
|
||||
cameraPosition: event.cameraPosition,
|
||||
);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(VideoStreamError(failure.message)),
|
||||
(videoStream) => emit(VideoStreamLoaded(videoStream)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class DroneStationEvent extends Equatable {
|
||||
const DroneStationEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class DroneStationLoadData extends DroneStationEvent {
|
||||
final int siteId;
|
||||
|
||||
const DroneStationLoadData(this.siteId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [siteId];
|
||||
}
|
||||
|
||||
class DroneStationRefresh extends DroneStationEvent {
|
||||
final int siteId;
|
||||
|
||||
const DroneStationRefresh(this.siteId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [siteId];
|
||||
}
|
||||
|
||||
class UAVDetailLoad extends DroneStationEvent {
|
||||
final String gatewaySn;
|
||||
final String deviceSn;
|
||||
|
||||
const UAVDetailLoad({required this.gatewaySn, required this.deviceSn});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [gatewaySn, deviceSn];
|
||||
}
|
||||
|
||||
class VideoStreamLoad extends DroneStationEvent {
|
||||
final String sn;
|
||||
final String cameraIndex;
|
||||
final String cameraPosition;
|
||||
|
||||
const VideoStreamLoad({
|
||||
required this.sn,
|
||||
required this.cameraIndex,
|
||||
required this.cameraPosition,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [sn, cameraIndex, cameraPosition];
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
|
||||
abstract class DroneStationState extends Equatable {
|
||||
const DroneStationState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class DroneStationInitial extends DroneStationState {
|
||||
const DroneStationInitial();
|
||||
}
|
||||
|
||||
class DroneStationLoading extends DroneStationState {
|
||||
const DroneStationLoading();
|
||||
}
|
||||
|
||||
class DroneStationLoaded extends DroneStationState {
|
||||
final List<DroneStationEntity> stations;
|
||||
|
||||
const DroneStationLoaded(this.stations);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [stations];
|
||||
}
|
||||
|
||||
class DroneStationError extends DroneStationState {
|
||||
final String message;
|
||||
|
||||
const DroneStationError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class UAVDetailLoading extends DroneStationState {
|
||||
const UAVDetailLoading();
|
||||
}
|
||||
|
||||
class UAVDetailLoaded extends DroneStationState {
|
||||
final UAVDetailEntity detail;
|
||||
|
||||
const UAVDetailLoaded(this.detail);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [detail];
|
||||
}
|
||||
|
||||
class UAVDetailError extends DroneStationState {
|
||||
final String message;
|
||||
|
||||
const UAVDetailError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class VideoStreamLoading extends DroneStationState {
|
||||
const VideoStreamLoading();
|
||||
}
|
||||
|
||||
class VideoStreamLoaded extends DroneStationState {
|
||||
final VideoStreamEntity videoStream;
|
||||
|
||||
const VideoStreamLoaded(this.videoStream);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [videoStream];
|
||||
}
|
||||
|
||||
class VideoStreamError extends DroneStationState {
|
||||
final String message;
|
||||
|
||||
const VideoStreamError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../../core/consts/http_api_consts.dart';
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import 'robot_list_event.dart';
|
||||
import 'robot_list_state.dart';
|
||||
|
||||
class RobotListBloc extends Bloc<RobotListEvent, RobotListState> {
|
||||
final Dio dio;
|
||||
|
||||
RobotListBloc(this.dio) : super(const RobotListInitial()) {
|
||||
on<RobotListLoadData>(_onLoadData);
|
||||
on<RobotListRefresh>(_onRefresh);
|
||||
on<RobotListChangeType>(_onChangeType);
|
||||
}
|
||||
|
||||
Future<void> _onLoadData(
|
||||
RobotListLoadData event,
|
||||
Emitter<RobotListState> emit,
|
||||
) async {
|
||||
if (event.siteId == null) {
|
||||
emit(const RobotListError('请先选择场站'));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(const RobotListLoading());
|
||||
|
||||
try {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getRobotList,
|
||||
queryParameters: {
|
||||
'siteId': event.siteId,
|
||||
'pageSize': 9999,
|
||||
'pageNum': 1,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
final robots = rows.map((item) => RobotDataModel.fromJson(item)).toList();
|
||||
|
||||
emit(RobotListLoaded(
|
||||
robots: robots,
|
||||
siteId: event.siteId,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(RobotListError(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onRefresh(
|
||||
RobotListRefresh event,
|
||||
Emitter<RobotListState> emit,
|
||||
) async {
|
||||
if (state is RobotListLoaded) {
|
||||
final currentState = state as RobotListLoaded;
|
||||
|
||||
if (currentState.siteId == null) {
|
||||
emit(const RobotListError('请先选择场站'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getRobotList,
|
||||
queryParameters: {
|
||||
'siteId': currentState.siteId,
|
||||
'pageSize': 9999,
|
||||
'pageNum': 1,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
final robots = rows.map((item) => RobotDataModel.fromJson(item)).toList();
|
||||
|
||||
emit(currentState.copyWith(robots: robots));
|
||||
} catch (e) {
|
||||
emit(RobotListError(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _onChangeType(
|
||||
RobotListChangeType event,
|
||||
Emitter<RobotListState> emit,
|
||||
) {
|
||||
if (state is RobotListLoaded) {
|
||||
final currentState = state as RobotListLoaded;
|
||||
emit(currentState.copyWith(selectedType: event.type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class RobotListEvent extends Equatable {
|
||||
const RobotListEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class RobotListLoadData extends RobotListEvent {
|
||||
final int? siteId;
|
||||
|
||||
const RobotListLoadData({this.siteId});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [siteId];
|
||||
}
|
||||
|
||||
class RobotListRefresh extends RobotListEvent {
|
||||
const RobotListRefresh();
|
||||
}
|
||||
|
||||
class RobotListChangeType extends RobotListEvent {
|
||||
final String? type;
|
||||
|
||||
const RobotListChangeType(this.type);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [type];
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
|
||||
abstract class RobotListState extends Equatable {
|
||||
const RobotListState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class RobotListInitial extends RobotListState {
|
||||
const RobotListInitial();
|
||||
}
|
||||
|
||||
class RobotListLoading extends RobotListState {
|
||||
const RobotListLoading();
|
||||
}
|
||||
|
||||
class RobotListLoaded extends RobotListState {
|
||||
final List<RobotDataModel> robots;
|
||||
final String? selectedType;
|
||||
final int? siteId;
|
||||
|
||||
const RobotListLoaded({
|
||||
required this.robots,
|
||||
this.selectedType,
|
||||
this.siteId,
|
||||
});
|
||||
|
||||
RobotListLoaded copyWith({
|
||||
List<RobotDataModel>? robots,
|
||||
String? selectedType,
|
||||
int? siteId,
|
||||
}) {
|
||||
return RobotListLoaded(
|
||||
robots: robots ?? this.robots,
|
||||
selectedType: selectedType ?? this.selectedType,
|
||||
siteId: siteId ?? this.siteId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [robots, selectedType, siteId];
|
||||
}
|
||||
|
||||
class RobotListError extends RobotListState {
|
||||
final String message;
|
||||
|
||||
const RobotListError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
Reference in New Issue
Block a user