一次大的提交
This commit is contained in:
@@ -1,70 +1,232 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_count_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/usecases/get_alarm_count_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/usecases/get_alarm_list_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 告警中心 Cubit
|
||||
const int _pageSize = 50;
|
||||
const int _countPageSize = 500;
|
||||
|
||||
class AlarmCubit extends Cubit<AlarmState> {
|
||||
AlarmCubit({
|
||||
required GetAlarmListUseCase getAlarmListUseCase,
|
||||
required GetAlarmCountUseCase getAlarmCountUseCase,
|
||||
}) : _getAlarmListUseCase = getAlarmListUseCase,
|
||||
_getAlarmCountUseCase = getAlarmCountUseCase,
|
||||
super(AlarmInitial());
|
||||
}) : _getAlarmListUseCase = getAlarmListUseCase,
|
||||
super(AlarmInitial());
|
||||
|
||||
final GetAlarmListUseCase _getAlarmListUseCase;
|
||||
final GetAlarmCountUseCase _getAlarmCountUseCase;
|
||||
int _loadRequestId = 0;
|
||||
|
||||
int? get _siteId {
|
||||
try {
|
||||
return GetIt.I<SiteCubit>().state.selectedSite?.id;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 加载告警数据
|
||||
Future<void> loadAlarms({AlarmFilterTab? filter}) async {
|
||||
// 如果不是初始加载,保留旧数据
|
||||
final isInitialLoad = state is AlarmInitial;
|
||||
if (isInitialLoad) {
|
||||
emit(AlarmLoading());
|
||||
}
|
||||
|
||||
try {
|
||||
// 并行获取告警列表和统计
|
||||
final alarmsResult = await _getAlarmListUseCase(filter: filter);
|
||||
final countResult = await _getAlarmCountUseCase();
|
||||
final siteId = _siteId;
|
||||
final requestId = ++_loadRequestId;
|
||||
|
||||
final alarms = alarmsResult.fold(
|
||||
try {
|
||||
final alarmsResult = await _getAlarmListUseCase(
|
||||
siteId: siteId,
|
||||
page: 1,
|
||||
pageSize: _pageSize,
|
||||
);
|
||||
|
||||
final allAlarms = alarmsResult.fold(
|
||||
(failure) => <AlarmEntity>[],
|
||||
(alarms) => alarms,
|
||||
);
|
||||
|
||||
final count = countResult.fold(
|
||||
(failure) => null,
|
||||
(count) => count,
|
||||
final selectedFilter = filter ?? AlarmFilterTab.all;
|
||||
final filteredAlarms = _filterAlarms(allAlarms, selectedFilter);
|
||||
|
||||
emit(
|
||||
AlarmLoaded(
|
||||
allAlarms: allAlarms,
|
||||
alarms: filteredAlarms,
|
||||
count: const AlarmCountEntity(
|
||||
unprocessed: 0,
|
||||
processing: 0,
|
||||
confirmed: 0,
|
||||
todayNew: 0,
|
||||
),
|
||||
selectedFilter: selectedFilter,
|
||||
currentPage: 1,
|
||||
hasMore: allAlarms.length >= _pageSize,
|
||||
isCountLoading: true,
|
||||
),
|
||||
);
|
||||
|
||||
if (count == null) {
|
||||
emit(const AlarmError('获取告警统计失败'));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(AlarmLoaded(
|
||||
alarms: alarms,
|
||||
count: count,
|
||||
selectedFilter: filter ?? AlarmFilterTab.all,
|
||||
));
|
||||
_loadAndCalculateCounts(siteId, requestId);
|
||||
} catch (e) {
|
||||
emit(AlarmError('加载告警数据失败: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// 切换筛选标签
|
||||
Future<void> changeFilter(AlarmFilterTab filter) async {
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
emit(currentState.copyWith(selectedFilter: filter));
|
||||
await loadAlarms(filter: filter);
|
||||
Future<void> _loadAndCalculateCounts(
|
||||
int? siteId,
|
||||
int requestId,
|
||||
) async {
|
||||
try {
|
||||
final result = await _getAlarmListUseCase(
|
||||
siteId: siteId,
|
||||
page: 1,
|
||||
pageSize: _countPageSize,
|
||||
);
|
||||
|
||||
if (requestId != _loadRequestId) return;
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
if (requestId != _loadRequestId) return;
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
emit(currentState.copyWith(
|
||||
isCountLoading: false,
|
||||
count: const AlarmCountEntity(
|
||||
unprocessed: 0,
|
||||
processing: 0,
|
||||
confirmed: 0,
|
||||
todayNew: 0,
|
||||
),
|
||||
));
|
||||
}
|
||||
},
|
||||
(alarms) {
|
||||
if (requestId != _loadRequestId) return;
|
||||
final count = _calculateCounts(alarms);
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
emit(currentState.copyWith(
|
||||
isCountLoading: false,
|
||||
count: count,
|
||||
));
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
if (requestId != _loadRequestId) return;
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
emit(currentState.copyWith(
|
||||
isCountLoading: false,
|
||||
count: const AlarmCountEntity(
|
||||
unprocessed: 0,
|
||||
processing: 0,
|
||||
confirmed: 0,
|
||||
todayNew: 0,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AlarmCountEntity _calculateCounts(List<AlarmEntity> alarms) {
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
|
||||
int unprocessed = 0;
|
||||
int confirmed = 0;
|
||||
int todayNew = 0;
|
||||
|
||||
for (final alarm in alarms) {
|
||||
if (alarm.status == AlarmStatus.pending) {
|
||||
unprocessed++;
|
||||
}
|
||||
if (alarm.status == AlarmStatus.closed) {
|
||||
confirmed++;
|
||||
}
|
||||
|
||||
try {
|
||||
final alarmTime = DateTime.parse(alarm.time);
|
||||
final alarmDate = DateTime(
|
||||
alarmTime.year,
|
||||
alarmTime.month,
|
||||
alarmTime.day,
|
||||
);
|
||||
if (alarmDate == today) {
|
||||
todayNew++;
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
return AlarmCountEntity(
|
||||
unprocessed: unprocessed,
|
||||
processing: 0,
|
||||
confirmed: confirmed,
|
||||
todayNew: todayNew,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> loadMore() async {
|
||||
final currentState = state;
|
||||
if (currentState is! AlarmLoaded) return;
|
||||
if (currentState.isLoadingMore || !currentState.hasMore) return;
|
||||
|
||||
emit(currentState.copyWith(isLoadingMore: true));
|
||||
|
||||
final siteId = _siteId;
|
||||
final nextPage = currentState.currentPage + 1;
|
||||
|
||||
try {
|
||||
final alarmsResult = await _getAlarmListUseCase(
|
||||
siteId: siteId,
|
||||
page: nextPage,
|
||||
pageSize: _pageSize,
|
||||
);
|
||||
|
||||
final newAlarms = alarmsResult.fold(
|
||||
(failure) => <AlarmEntity>[],
|
||||
(alarms) => alarms,
|
||||
);
|
||||
|
||||
final updatedAllAlarms = [
|
||||
...currentState.allAlarms,
|
||||
...newAlarms,
|
||||
];
|
||||
final filteredAlarms = _filterAlarms(
|
||||
updatedAllAlarms,
|
||||
currentState.selectedFilter,
|
||||
);
|
||||
|
||||
emit(
|
||||
AlarmLoaded(
|
||||
allAlarms: updatedAllAlarms,
|
||||
alarms: filteredAlarms,
|
||||
count: currentState.count,
|
||||
selectedFilter: currentState.selectedFilter,
|
||||
currentPage: nextPage,
|
||||
hasMore: newAlarms.length >= _pageSize,
|
||||
isLoadingMore: false,
|
||||
isCountLoading: currentState.isCountLoading,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(currentState.copyWith(isLoadingMore: false));
|
||||
}
|
||||
}
|
||||
|
||||
void changeFilter(AlarmFilterTab filter) {
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
final filteredAlarms = _filterAlarms(currentState.allAlarms, filter);
|
||||
emit(
|
||||
currentState.copyWith(alarms: filteredAlarms, selectedFilter: filter),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 刷新数据
|
||||
Future<void> refresh() async {
|
||||
final currentState = state;
|
||||
if (currentState is AlarmLoaded) {
|
||||
@@ -73,4 +235,26 @@ class AlarmCubit extends Cubit<AlarmState> {
|
||||
await loadAlarms();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<AlarmEntity> _filterAlarms(
|
||||
List<AlarmEntity> alarms,
|
||||
AlarmFilterTab filter,
|
||||
) {
|
||||
switch (filter) {
|
||||
case AlarmFilterTab.unprocessed:
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.pending)
|
||||
.toList();
|
||||
case AlarmFilterTab.confirmed:
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.processing)
|
||||
.toList();
|
||||
case AlarmFilterTab.recovered:
|
||||
return alarms
|
||||
.where((alarm) => alarm.status == AlarmStatus.closed)
|
||||
.toList();
|
||||
case AlarmFilterTab.all:
|
||||
return alarms;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/usecases/alarm_actions_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/usecases/get_alarm_detail_usecase.dart';
|
||||
@@ -8,14 +9,17 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
AlarmDetailCubit({
|
||||
required GetAlarmDetailUseCase getAlarmDetailUseCase,
|
||||
required ConfirmAlarmUseCase confirmAlarmUseCase,
|
||||
required HandleAlarmUseCase handleAlarmUseCase,
|
||||
required AIDiagnosisUseCase aiDiagnosisUseCase,
|
||||
}) : _getAlarmDetailUseCase = getAlarmDetailUseCase,
|
||||
_confirmAlarmUseCase = confirmAlarmUseCase,
|
||||
_aiDiagnosisUseCase = aiDiagnosisUseCase,
|
||||
super(AlarmDetailInitial());
|
||||
}) : _getAlarmDetailUseCase = getAlarmDetailUseCase,
|
||||
_confirmAlarmUseCase = confirmAlarmUseCase,
|
||||
_handleAlarmUseCase = handleAlarmUseCase,
|
||||
_aiDiagnosisUseCase = aiDiagnosisUseCase,
|
||||
super(AlarmDetailInitial());
|
||||
|
||||
final GetAlarmDetailUseCase _getAlarmDetailUseCase;
|
||||
final ConfirmAlarmUseCase _confirmAlarmUseCase;
|
||||
final HandleAlarmUseCase _handleAlarmUseCase;
|
||||
final AIDiagnosisUseCase _aiDiagnosisUseCase;
|
||||
|
||||
/// 加载告警详情
|
||||
@@ -47,7 +51,12 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
final currentState = state;
|
||||
if (currentState is! AlarmDetailLoaded) return;
|
||||
|
||||
emit(const AlarmDetailActionInProgress('确认告警'));
|
||||
emit(
|
||||
AlarmDetailActionInProgress(
|
||||
'确认告警',
|
||||
alarmDetail: currentState.alarmDetail,
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final result = await _confirmAlarmUseCase(alarmId);
|
||||
@@ -56,17 +65,16 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
(failure) {
|
||||
emit(AlarmDetailError(failure.message));
|
||||
},
|
||||
(success) {
|
||||
if (success) {
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
isConfirmed: true,
|
||||
alarmDetail: currentState.alarmDetail.copyWith(
|
||||
alarmStatus: '已处理',
|
||||
),
|
||||
(responseData) {
|
||||
debugPrint('确认告警响应数据: $responseData');
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
isConfirmed: true,
|
||||
alarmDetail: currentState.alarmDetail.copyWith(
|
||||
alarmStatus: '处理中',
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -79,7 +87,12 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
final currentState = state;
|
||||
if (currentState is! AlarmDetailLoaded) return;
|
||||
|
||||
emit(const AlarmDetailActionInProgress('AI诊断'));
|
||||
emit(
|
||||
AlarmDetailActionInProgress(
|
||||
'AI诊断',
|
||||
alarmDetail: currentState.alarmDetail,
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final result = await _aiDiagnosisUseCase(alarmId);
|
||||
@@ -96,4 +109,40 @@ class AlarmDetailCubit extends Cubit<AlarmDetailState> {
|
||||
emit(AlarmDetailError('AI诊断失败: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// 处理告警(提交处理)
|
||||
Future<void> handleAlarm(Map<String, dynamic> handleData) async {
|
||||
final currentState = state;
|
||||
if (currentState is! AlarmDetailLoaded) return;
|
||||
|
||||
emit(
|
||||
AlarmDetailActionInProgress(
|
||||
'提交处理',
|
||||
alarmDetail: currentState.alarmDetail,
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final result = await _handleAlarmUseCase(handleData);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
emit(AlarmDetailError(failure.message));
|
||||
},
|
||||
(responseData) {
|
||||
debugPrint('处理告警响应数据: $responseData');
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
alarmDetail: currentState.alarmDetail.copyWith(
|
||||
alarmStatus: '已关闭',
|
||||
),
|
||||
isHandleSuccess: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
emit(AlarmDetailError('处理告警失败: $e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,27 +32,31 @@ class AlarmDetailLoaded extends AlarmDetailState {
|
||||
this.selectedMetric = MetricType.power,
|
||||
this.isConfirmed = false,
|
||||
this.aiDiagnosisResult,
|
||||
this.isHandleSuccess = false,
|
||||
});
|
||||
|
||||
final AlarmDetailEntity alarmDetail;
|
||||
final MetricType selectedMetric;
|
||||
final bool isConfirmed;
|
||||
final String? aiDiagnosisResult;
|
||||
final bool isHandleSuccess;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [alarmDetail, selectedMetric, isConfirmed, aiDiagnosisResult];
|
||||
List<Object?> get props => [alarmDetail, selectedMetric, isConfirmed, aiDiagnosisResult, isHandleSuccess];
|
||||
|
||||
AlarmDetailLoaded copyWith({
|
||||
AlarmDetailEntity? alarmDetail,
|
||||
MetricType? selectedMetric,
|
||||
bool? isConfirmed,
|
||||
String? aiDiagnosisResult,
|
||||
bool? isHandleSuccess,
|
||||
}) {
|
||||
return AlarmDetailLoaded(
|
||||
alarmDetail: alarmDetail ?? this.alarmDetail,
|
||||
selectedMetric: selectedMetric ?? this.selectedMetric,
|
||||
isConfirmed: isConfirmed ?? this.isConfirmed,
|
||||
aiDiagnosisResult: aiDiagnosisResult ?? this.aiDiagnosisResult,
|
||||
isHandleSuccess: isHandleSuccess ?? this.isHandleSuccess,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -69,10 +73,14 @@ class AlarmDetailError extends AlarmDetailState {
|
||||
|
||||
/// 操作进行中状态
|
||||
class AlarmDetailActionInProgress extends AlarmDetailState {
|
||||
const AlarmDetailActionInProgress(this.action);
|
||||
const AlarmDetailActionInProgress(
|
||||
this.action, {
|
||||
this.alarmDetail,
|
||||
});
|
||||
|
||||
final String action;
|
||||
final AlarmDetailEntity? alarmDetail;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [action];
|
||||
List<Object?> get props => [action, alarmDetail];
|
||||
}
|
||||
|
||||
@@ -20,27 +20,56 @@ class AlarmLoading extends AlarmState {}
|
||||
/// 加载成功状态
|
||||
class AlarmLoaded extends AlarmState {
|
||||
const AlarmLoaded({
|
||||
required this.allAlarms,
|
||||
required this.alarms,
|
||||
required this.count,
|
||||
this.selectedFilter = AlarmFilterTab.all,
|
||||
this.currentPage = 1,
|
||||
this.hasMore = true,
|
||||
this.isLoadingMore = false,
|
||||
this.isCountLoading = false,
|
||||
});
|
||||
|
||||
final List<AlarmEntity> allAlarms;
|
||||
final List<AlarmEntity> alarms;
|
||||
final AlarmCountEntity count;
|
||||
final AlarmFilterTab selectedFilter;
|
||||
final int currentPage;
|
||||
final bool hasMore;
|
||||
final bool isLoadingMore;
|
||||
final bool isCountLoading;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [alarms, count, selectedFilter];
|
||||
List<Object?> get props => [
|
||||
allAlarms,
|
||||
alarms,
|
||||
count,
|
||||
selectedFilter,
|
||||
currentPage,
|
||||
hasMore,
|
||||
isLoadingMore,
|
||||
isCountLoading,
|
||||
];
|
||||
|
||||
AlarmLoaded copyWith({
|
||||
List<AlarmEntity>? allAlarms,
|
||||
List<AlarmEntity>? alarms,
|
||||
AlarmCountEntity? count,
|
||||
AlarmFilterTab? selectedFilter,
|
||||
int? currentPage,
|
||||
bool? hasMore,
|
||||
bool? isLoadingMore,
|
||||
bool? isCountLoading,
|
||||
}) {
|
||||
return AlarmLoaded(
|
||||
allAlarms: allAlarms ?? this.allAlarms,
|
||||
alarms: alarms ?? this.alarms,
|
||||
count: count ?? this.count,
|
||||
selectedFilter: selectedFilter ?? this.selectedFilter,
|
||||
currentPage: currentPage ?? this.currentPage,
|
||||
hasMore: hasMore ?? this.hasMore,
|
||||
isLoadingMore: isLoadingMore ?? this.isLoadingMore,
|
||||
isCountLoading: isCountLoading ?? this.isCountLoading,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,14 +90,17 @@ enum AlarmLevel {
|
||||
|
||||
/// 告警状态枚举
|
||||
enum AlarmStatus {
|
||||
/// 未确认
|
||||
unconfirmed('未确认'),
|
||||
/// 待处理
|
||||
pending('待处理'),
|
||||
|
||||
/// 已确认
|
||||
confirmed('已确认'),
|
||||
/// 处理中
|
||||
processing('处理中'),
|
||||
|
||||
/// 已恢复
|
||||
recovered('已恢复');
|
||||
/// 已关闭
|
||||
closed('已关闭'),
|
||||
|
||||
/// 已忽略
|
||||
ignored('已忽略');
|
||||
|
||||
const AlarmStatus(this.label);
|
||||
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../domain/entities/alarm_dispatch_entity.dart';
|
||||
import '../../domain/entities/alarm_detail_entity.dart';
|
||||
import '../../domain/usecases/dispatch_workorder_usecase.dart';
|
||||
import '../states/alarm_dispatch_state.dart';
|
||||
import '../../../report/presentation/constants/report_constants.dart';
|
||||
import '../../../home/domain/entities/site_entity.dart';
|
||||
import '../../../home/domain/usecases/get_site_list_usecase.dart';
|
||||
import '../../../home/domain/repositories/site_repository.dart';
|
||||
import '../../../home/data/repositories/site_repository_impl.dart';
|
||||
import '../../../home/data/datasources/site_datasource_impl.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
|
||||
|
||||
/// deviceType → ReportType 映射配置(方便后续修改)
|
||||
const Map<String, ReportType> deviceTypeToReportType = {
|
||||
'UAV': ReportType.uavError,
|
||||
'DRONE': ReportType.uavError,
|
||||
'MOWER': ReportType.mowerError,
|
||||
'ROBOT': ReportType.mowerError,
|
||||
};
|
||||
|
||||
class AlarmDispatchCubit extends Cubit<AlarmDispatchState> {
|
||||
final DispatchWorkOrderUseCase dispatchUseCase;
|
||||
final AlarmDetailEntity alarmDetail;
|
||||
final Dio dio;
|
||||
final AppUserCubit appUserCubit;
|
||||
final UserStorage userStorage;
|
||||
|
||||
AlarmDispatchCubit({
|
||||
required this.dispatchUseCase,
|
||||
required this.alarmDetail,
|
||||
required this.dio,
|
||||
required this.appUserCubit,
|
||||
required this.userStorage,
|
||||
}) : super(AlarmDispatchLoading()) {
|
||||
_init();
|
||||
}
|
||||
|
||||
Future<void> _init() async {
|
||||
_initFromAlarm();
|
||||
await _loadSiteName();
|
||||
}
|
||||
|
||||
/// 从告警数据初始化表单
|
||||
void _initFromAlarm() {
|
||||
final deviceType = alarmDetail.deviceType?.toUpperCase() ?? '';
|
||||
final reportType = deviceTypeToReportType[deviceType] ?? ReportType.other;
|
||||
final now = DateTime.now();
|
||||
|
||||
final entity = AlarmDispatchEntity(
|
||||
alarmId: alarmDetail.id,
|
||||
alarmNo: alarmDetail.alarmNo,
|
||||
deviceType: alarmDetail.deviceType,
|
||||
orderType: reportType.orderType,
|
||||
siteId: alarmDetail.siteId,
|
||||
siteName: null,
|
||||
deviceId: alarmDetail.deviceId,
|
||||
deviceName: alarmDetail.deviceInfo,
|
||||
description: alarmDetail.description,
|
||||
problemLevel: _mapAlarmLevelToProblemLevel(alarmDetail.level),
|
||||
planStartTime: now,
|
||||
planEndTime: now.add(const Duration(hours: 4)),
|
||||
);
|
||||
|
||||
emit(AlarmDispatchFormState(
|
||||
alarmId: alarmDetail.id,
|
||||
alarmNo: alarmDetail.alarmNo,
|
||||
entity: entity,
|
||||
selectedReportType: reportType,
|
||||
selectedDevice: alarmDetail.deviceInfo,
|
||||
selectedDeviceId: alarmDetail.deviceId,
|
||||
planStartTime: now,
|
||||
planEndTime: now.add(const Duration(hours: 4)),
|
||||
siteId: alarmDetail.siteId,
|
||||
));
|
||||
}
|
||||
|
||||
/// 加载场站列表,根据 siteId 找到场站名称
|
||||
Future<void> _loadSiteName() async {
|
||||
if (state is! AlarmDispatchFormState) return;
|
||||
final currentState = state as AlarmDispatchFormState;
|
||||
final siteId = currentState.siteId;
|
||||
if (siteId == null) return;
|
||||
|
||||
try {
|
||||
final siteDataSource = SiteDataSourceImpl(
|
||||
dio,
|
||||
userStorage,
|
||||
appUserCubit,
|
||||
);
|
||||
final siteRepository = SiteRepositoryImpl(siteDataSource);
|
||||
final getSiteListUseCase = GetSiteListUseCase(siteRepository);
|
||||
|
||||
final user = appUserCubit.state.user;
|
||||
if (user == null) return;
|
||||
|
||||
final result = await getSiteListUseCase(user.userId);
|
||||
result.fold(
|
||||
(failure) {},
|
||||
(sites) {
|
||||
final matches = sites.where((s) => s.id == siteId);
|
||||
if (matches.isNotEmpty) {
|
||||
final matchedSite = matches.first;
|
||||
emit(currentState.copyWith(
|
||||
siteName: matchedSite.siteName,
|
||||
entity: currentState.entity.copyWith(siteName: matchedSite.siteName),
|
||||
));
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
// 加载失败不影响表单使用
|
||||
}
|
||||
}
|
||||
|
||||
/// 告警等级 → 问题等级映射
|
||||
String _mapAlarmLevelToProblemLevel(dynamic level) {
|
||||
final label = level.label?.toUpperCase() ?? level.toString().toUpperCase();
|
||||
if (label.contains('DANGER') || label.contains('严重') || label.contains('高危')) {
|
||||
return 'ERROR';
|
||||
}
|
||||
if (label.contains('WARNING') || label.contains('中危')) {
|
||||
return 'WARNING';
|
||||
}
|
||||
return 'INFO';
|
||||
}
|
||||
|
||||
/// 选择上报类型
|
||||
void selectReportType(ReportType type) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
selectedReportType: type,
|
||||
entity: s.entity.copyWith(orderType: type.orderType),
|
||||
));
|
||||
}
|
||||
|
||||
/// 选择问题等级
|
||||
void selectProblemLevel(ProblemLevel level) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
selectedProblemLevel: level,
|
||||
entity: s.entity.copyWith(problemLevel: level.level),
|
||||
));
|
||||
}
|
||||
|
||||
/// 更新描述
|
||||
void updateDescription(String description) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
entity: s.entity.copyWith(description: description),
|
||||
));
|
||||
}
|
||||
|
||||
/// 更新设备
|
||||
void updateDevice(String deviceName, String deviceId) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
selectedDevice: deviceName,
|
||||
selectedDeviceId: deviceId,
|
||||
entity: s.entity.copyWith(deviceId: deviceId, deviceName: deviceName),
|
||||
));
|
||||
}
|
||||
|
||||
/// 添加媒体文件
|
||||
void addMediaFile(String filePath) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
final updatedFiles = List<String>.from(s.mediaFiles)..add(filePath);
|
||||
emit(s.copyWith(
|
||||
mediaFiles: updatedFiles,
|
||||
entity: s.entity.copyWith(mediaUrls: updatedFiles),
|
||||
));
|
||||
}
|
||||
|
||||
/// 移除媒体文件
|
||||
void removeMediaFile(int index) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
final updatedFiles = List<String>.from(s.mediaFiles)..removeAt(index);
|
||||
emit(s.copyWith(
|
||||
mediaFiles: updatedFiles,
|
||||
entity: s.entity.copyWith(mediaUrls: updatedFiles),
|
||||
));
|
||||
}
|
||||
|
||||
/// 更新计划开始时间
|
||||
void updatePlanStartTime(DateTime time) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
planStartTime: time,
|
||||
entity: s.entity.copyWith(planStartTime: time),
|
||||
));
|
||||
}
|
||||
|
||||
/// 更新计划结束时间
|
||||
void updatePlanEndTime(DateTime time) {
|
||||
final s = state as AlarmDispatchFormState;
|
||||
emit(s.copyWith(
|
||||
planEndTime: time,
|
||||
entity: s.entity.copyWith(planEndTime: time),
|
||||
));
|
||||
}
|
||||
|
||||
/// 提交派发
|
||||
Future<void> submitDispatch() async {
|
||||
final s = state;
|
||||
if (s is! AlarmDispatchFormState) return;
|
||||
|
||||
emit(AlarmDispatchSubmitting());
|
||||
|
||||
final result = await dispatchUseCase.execute(s.entity);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
emit(s.copyWith(toastMessage: failure.message, isSuccess: false));
|
||||
},
|
||||
(success) {
|
||||
emit(s.copyWith(toastMessage: '工单派发成功', isSuccess: true));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 清除 toast 消息
|
||||
void clearToast() {
|
||||
final s = state;
|
||||
if (s is AlarmDispatchFormState) {
|
||||
emit(s.copyWith(toastMessage: null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/alarm_item_card.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/alarm_tab_bar.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/ai_diagnosis_card.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/site/presentation/widgets/site_selector_widget.dart';
|
||||
|
||||
/// 告警中心页面
|
||||
class AlarmCenterPage extends StatefulWidget {
|
||||
@@ -21,17 +22,33 @@ class AlarmCenterPage extends StatefulWidget {
|
||||
|
||||
class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
late AlarmCubit _cubit;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cubit = context.read<AlarmCubit>();
|
||||
// 首次加载数据
|
||||
_scrollController.addListener(_onScroll);
|
||||
|
||||
if (_cubit.state is AlarmInitial) {
|
||||
_cubit.loadAlarms();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onScroll() {
|
||||
final maxScroll = _scrollController.position.maxScrollExtent;
|
||||
final currentScroll = _scrollController.position.pixels;
|
||||
if (currentScroll >= maxScroll - 200) {
|
||||
_cubit.loadMore();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
@@ -88,35 +105,33 @@ class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
await _cubit.refresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
controller: _scrollController,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: AlarmDimensions.moduleSpacing,
|
||||
bottom: 40,
|
||||
),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
//const SizedBox(height: AlarmDimensions.moduleSpacing),
|
||||
// 告警统计卡片
|
||||
AlarmCountCard(count: state.count),
|
||||
AlarmCountCard(count: state.count, isCountLoading: state.isCountLoading),
|
||||
const SizedBox(
|
||||
height: AlarmDimensions.moduleSpacing,
|
||||
),
|
||||
// 告警列表
|
||||
...state.alarms.map((alarm) {
|
||||
return AlarmItemCard(
|
||||
alarm: alarm,
|
||||
onTap: () {
|
||||
context.push(
|
||||
'/alarm_center/detail/${alarm.id}',
|
||||
);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
if (state.alarms.isNotEmpty)
|
||||
...state.alarms.map((alarm) {
|
||||
return AlarmItemCard(
|
||||
alarm: alarm,
|
||||
onTap: () async {
|
||||
await context.push(
|
||||
'/alarm_center/detail/${alarm.id}',
|
||||
);
|
||||
_cubit.loadAlarms();
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
const SizedBox(
|
||||
height: AlarmDimensions.moduleSpacing,
|
||||
),
|
||||
// AI 诊断建议(仅当有 AI 诊断内容时显示)
|
||||
if (state.alarms.any(
|
||||
(alarm) => alarm.aiDiagnosis != null,
|
||||
))
|
||||
@@ -130,10 +145,10 @@ class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
.aiDiagnosis ??
|
||||
'',
|
||||
onViewDetails: () {
|
||||
// TODO: 查看详情
|
||||
debugPrint('查看 AI 诊断详情');
|
||||
},
|
||||
),
|
||||
_buildLoadMoreIndicator(state),
|
||||
]),
|
||||
),
|
||||
),
|
||||
@@ -262,15 +277,24 @@ class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('alarm_center.title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
const Flexible(child: SiteSelectorWidget(compact: true)),
|
||||
const SizedBox(width: 8),
|
||||
Container(width: 1, height: 20, color: const Color(0xFFE5E6EB)),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('alarm_center.title'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
// 铃铛图标(消息通知)
|
||||
Stack(
|
||||
children: [
|
||||
@@ -323,6 +347,48 @@ class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadMoreIndicator(AlarmLoaded state) {
|
||||
if (state.isLoadingMore) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
CircularProgressIndicator(strokeWidth: 2),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'加载中...',
|
||||
style: TextStyle(fontSize: 12, color: AlarmColors.textTertiary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!state.hasMore) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'已加载全部数据',
|
||||
style: TextStyle(fontSize: 12, color: AlarmColors.textTertiary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'上滑加载更多',
|
||||
style: TextStyle(fontSize: 12, color: AlarmColors.textTertiary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterOption(String title, List<String> options) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -12,10 +12,7 @@ import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/
|
||||
class AlarmDetailPage extends StatefulWidget {
|
||||
final String alarmId;
|
||||
|
||||
const AlarmDetailPage({
|
||||
super.key,
|
||||
required this.alarmId,
|
||||
});
|
||||
const AlarmDetailPage({super.key, required this.alarmId});
|
||||
|
||||
@override
|
||||
State<AlarmDetailPage> createState() => _AlarmDetailPageState();
|
||||
@@ -23,6 +20,7 @@ class AlarmDetailPage extends StatefulWidget {
|
||||
|
||||
class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
late AlarmDetailCubit _cubit;
|
||||
AlarmDetailLoaded? _lastLoadedState;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -48,19 +46,14 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
_showAIDiagnosisDialog(state.aiDiagnosisResult!);
|
||||
}
|
||||
|
||||
// 确认告警成功后返回
|
||||
// 确认告警成功后显示提示
|
||||
if (state is AlarmDetailLoaded && state.isConfirmed) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('告警已确认'),
|
||||
content: Text('告警已确认,正在处理中'),
|
||||
backgroundColor: AlarmColors.success,
|
||||
),
|
||||
);
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (mounted) {
|
||||
context.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
@@ -73,10 +66,19 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
}
|
||||
|
||||
if (state is AlarmDetailLoaded) {
|
||||
_lastLoadedState = state;
|
||||
return _buildContent(state);
|
||||
}
|
||||
|
||||
if (state is AlarmDetailActionInProgress) {
|
||||
if (_lastLoadedState != null) {
|
||||
return Stack(
|
||||
children: [
|
||||
_buildContent(_lastLoadedState!),
|
||||
_buildLoadingOverlay(state.action),
|
||||
],
|
||||
);
|
||||
}
|
||||
return _buildLoadingOverlay(state.action);
|
||||
}
|
||||
|
||||
@@ -106,7 +108,10 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.share_outlined, color: AlarmColors.textPrimary),
|
||||
icon: const Icon(
|
||||
Icons.share_outlined,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
onPressed: () {
|
||||
// TODO: 分享功能
|
||||
},
|
||||
@@ -140,9 +145,7 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AlarmColors.primary,
|
||||
),
|
||||
child: CircularProgressIndicator(color: AlarmColors.primary),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -193,9 +196,7 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
color: AlarmColors.primary,
|
||||
),
|
||||
CircularProgressIndicator(color: AlarmColors.primary),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'$action...',
|
||||
@@ -229,15 +230,17 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
// 告警详情信息列表
|
||||
_buildAlarmInfoList(alarm),
|
||||
const SizedBox(height: 16),
|
||||
// 指标趋势图
|
||||
MetricTrendChart(
|
||||
historyData: alarm.historyData,
|
||||
selectedMetric: state.selectedMetric,
|
||||
onMetricChanged: (metric) => _cubit.changeMetricType(metric),
|
||||
),
|
||||
// 指标趋势图(仅当有历史数据时显示)
|
||||
if (_hasHistoryData(alarm.historyData))
|
||||
MetricTrendChart(
|
||||
historyData: alarm.historyData,
|
||||
selectedMetric: state.selectedMetric,
|
||||
onMetricChanged: (metric) => _cubit.changeMetricType(metric),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 处理建议
|
||||
_buildSuggestionsCard(alarm.suggestions),
|
||||
// 处理建议(仅当有建议时显示)
|
||||
if (alarm.suggestions.isNotEmpty)
|
||||
_buildSuggestionsCard(alarm.suggestions),
|
||||
const SizedBox(height: 100), // 为底部按钮留出空间
|
||||
],
|
||||
),
|
||||
@@ -323,6 +326,61 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
|
||||
/// 告警详情信息列表
|
||||
Widget _buildAlarmInfoList(AlarmDetailEntity alarm) {
|
||||
final List<Widget> infoRows = [];
|
||||
|
||||
void addRow(String label, dynamic value, {Color? valueColor}) {
|
||||
if (value == null || value == '' || value == 0) return;
|
||||
final displayValue = value is bool
|
||||
? (value ? '是' : '否')
|
||||
: value.toString();
|
||||
infoRows.add(_buildInfoRow(label, displayValue, valueColor: valueColor));
|
||||
}
|
||||
|
||||
addRow('告警编号', alarm.alarmNo);
|
||||
addRow(
|
||||
'告警状态',
|
||||
alarm.alarmStatus,
|
||||
valueColor: alarm.alarmStatus == '待处理'
|
||||
? AlarmColors.danger
|
||||
: AlarmColors.success,
|
||||
);
|
||||
addRow('发生时间', alarm.occurTime);
|
||||
addRow('恢复时间', alarm.recoverTime);
|
||||
addRow('持续时长', alarm.duration);
|
||||
addRow(
|
||||
'设备名称',
|
||||
alarm.deviceInfo.isNotEmpty ? alarm.deviceInfo : alarm.deviceId,
|
||||
);
|
||||
addRow(
|
||||
'告警类型',
|
||||
alarm.deviceType != null ? _mapDeviceType(alarm.deviceType!) : null,
|
||||
);
|
||||
addRow('告警描述', alarm.description);
|
||||
addRow('创建时间', alarm.createTime);
|
||||
addRow('更新时间', alarm.updateTime);
|
||||
addRow('处理人', alarm.handleUserName);
|
||||
addRow('处理时间', alarm.handleTime);
|
||||
addRow('处理备注', alarm.handleRemark);
|
||||
addRow('根因分析', alarm.rootCause);
|
||||
addRow('处理建议', alarm.handleSuggestion);
|
||||
addRow('处理结果', alarm.handleResult);
|
||||
addRow(
|
||||
'短信通知',
|
||||
alarm.notifySms != null ? (alarm.notifySms == 1 ? '是' : '否') : null,
|
||||
);
|
||||
addRow(
|
||||
'电报通知',
|
||||
alarm.notifyTelegram != null
|
||||
? (alarm.notifyTelegram == 1 ? '是' : '否')
|
||||
: null,
|
||||
);
|
||||
addRow(
|
||||
'邮件通知',
|
||||
alarm.notifyEmail != null ? (alarm.notifyEmail == 1 ? '是' : '否') : null,
|
||||
);
|
||||
|
||||
if (infoRows.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
@@ -331,25 +389,55 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
boxShadow: [AlarmDimensions.cardShadow],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildInfoRow('告警状态', alarm.alarmStatus,
|
||||
valueColor: alarm.alarmStatus == '未处理' ? AlarmColors.danger : AlarmColors.success),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('发生时间', alarm.occurTime),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('恢复时间', alarm.recoverTime ?? '--'),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('持续时长', alarm.duration),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('影响范围', alarm.affectRange),
|
||||
_buildDivider(),
|
||||
_buildInfoRow('告警描述', alarm.description, isLast: true),
|
||||
],
|
||||
children: infoRows
|
||||
.asMap()
|
||||
.entries
|
||||
.map(
|
||||
(entry) => [
|
||||
entry.value,
|
||||
if (entry.key < infoRows.length - 1) _buildDivider(),
|
||||
],
|
||||
)
|
||||
.expand((e) => e)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value, {Color? valueColor, bool isLast = false}) {
|
||||
String _mapDeviceType(String type) {
|
||||
final lowerType = type.toLowerCase();
|
||||
switch (lowerType) {
|
||||
case 'uav_fault':
|
||||
case 'uav':
|
||||
return '无人机故障';
|
||||
case 'mower_fault':
|
||||
case 'mower':
|
||||
return '割草机故障';
|
||||
case 'other_device_fault':
|
||||
case 'other_device':
|
||||
return '其他设备故障';
|
||||
case 'server_failure':
|
||||
case 'server':
|
||||
return '服务器故障';
|
||||
case 'system_error':
|
||||
case 'system':
|
||||
return '系统错误';
|
||||
default:
|
||||
if (lowerType.contains('uav')) return '无人机故障';
|
||||
if (lowerType.contains('mower')) return '割草机故障';
|
||||
if (lowerType.contains('other_device')) return '其他设备故障';
|
||||
if (lowerType.contains('server')) return '服务器故障';
|
||||
if (lowerType.contains('system')) return '系统错误';
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(
|
||||
String label,
|
||||
String value, {
|
||||
Color? valueColor,
|
||||
bool isLast = false,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: isLast ? 0 : 12),
|
||||
child: Row(
|
||||
@@ -381,11 +469,13 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
}
|
||||
|
||||
Widget _buildDivider() {
|
||||
return const Divider(
|
||||
height: 24,
|
||||
thickness: 0.5,
|
||||
color: Color(0xFFE5E6EB),
|
||||
);
|
||||
return const Divider(height: 24, thickness: 0.5, color: Color(0xFFE5E6EB));
|
||||
}
|
||||
|
||||
bool _hasHistoryData(HistoryMetrics historyData) {
|
||||
return historyData.power.isNotEmpty ||
|
||||
historyData.voltage.isNotEmpty ||
|
||||
historyData.frequency.isNotEmpty;
|
||||
}
|
||||
|
||||
/// 处理建议卡片
|
||||
@@ -444,9 +534,10 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
|
||||
/// 底部按钮
|
||||
Widget _buildBottomButtons(AlarmDetailLoaded state) {
|
||||
final isConfirmed = state.isConfirmed;
|
||||
final alarmStatus = state.alarmDetail.alarmStatus;
|
||||
final isInProgress = _cubit.state is AlarmDetailActionInProgress;
|
||||
final isDisabled = isConfirmed || isInProgress;
|
||||
final isPending = alarmStatus == '待处理';
|
||||
final isDisabled = !isPending || isInProgress;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 20),
|
||||
@@ -467,26 +558,68 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
child: _buildButton(
|
||||
text: 'AI诊断',
|
||||
isPrimary: false,
|
||||
isLoading: isInProgress && _cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action == 'AI诊断',
|
||||
isDisabled: isDisabled,
|
||||
onPressed: isDisabled
|
||||
isLoading:
|
||||
isInProgress &&
|
||||
_cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action ==
|
||||
'AI诊断',
|
||||
isDisabled: isInProgress,
|
||||
onPressed: isInProgress
|
||||
? null
|
||||
: () => _cubit.aiDiagnosis(widget.alarmId),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
const SizedBox(width: 12),
|
||||
// 确认告警按钮
|
||||
Expanded(
|
||||
child: _buildButton(
|
||||
text: '确认告警',
|
||||
text: isPending ? '确认告警' : '已确认',
|
||||
isPrimary: true,
|
||||
isLoading: isInProgress && _cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action == '确认告警',
|
||||
isDisabled: isDisabled,
|
||||
onPressed: isDisabled
|
||||
? null
|
||||
: () => _cubit.confirmAlarm(widget.alarmId),
|
||||
isLoading:
|
||||
isInProgress &&
|
||||
_cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action ==
|
||||
'确认告警',
|
||||
isDisabled: true,
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('暂未开放'),
|
||||
backgroundColor: AlarmColors.warning,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 去处理按钮
|
||||
SizedBox(
|
||||
width: 88,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
await context.push(
|
||||
'/alarm_center/detail/${widget.alarmId}/handle',
|
||||
);
|
||||
_cubit.loadAlarmDetail(widget.alarmId);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: AlarmColors.primary,
|
||||
elevation: 0,
|
||||
side: const BorderSide(color: AlarmColors.primary),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 6),
|
||||
),
|
||||
child: Text(
|
||||
alarmStatus == '已关闭' ? '已处理' : '去处理',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -510,9 +643,7 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
foregroundColor: isPrimary ? Colors.white : AlarmColors.primary,
|
||||
elevation: 0,
|
||||
side: isPrimary ? null : const BorderSide(color: AlarmColors.primary),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: isLoading
|
||||
? SizedBox(
|
||||
@@ -526,8 +657,8 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -542,25 +673,16 @@ class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
return AlertDialog(
|
||||
title: const Text(
|
||||
'AI诊断结果',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
content: SingleChildScrollView(
|
||||
child: Text(
|
||||
result,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.6,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, height: 1.6),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: const Text('关闭'),
|
||||
),
|
||||
TextButton(onPressed: () => context.pop(), child: const Text('关闭')),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -0,0 +1,560 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import '../../domain/entities/alarm_detail_entity.dart';
|
||||
import '../../domain/usecases/dispatch_workorder_usecase.dart';
|
||||
import '../../data/datasources/alarm_dispatch_remote_datasource.dart';
|
||||
import '../../data/datasources/impl/alarm_dispatch_remote_datasource_impl.dart';
|
||||
import '../../data/repositories/alarm_dispatch_repository_impl.dart';
|
||||
import '../cubit/alarm_dispatch_cubit.dart';
|
||||
import '../states/alarm_dispatch_state.dart';
|
||||
import '../../../report/presentation/constants/report_constants.dart';
|
||||
import '../../../report/presentation/widgets/report_type_selector.dart';
|
||||
import '../../../report/presentation/widgets/device_selector.dart';
|
||||
import '../../../report/presentation/widgets/description_input.dart';
|
||||
import '../../../report/presentation/widgets/media_uploader.dart';
|
||||
import '../../../report/presentation/widgets/level_selector.dart';
|
||||
import '../../../report/presentation/pages/media_preview_page.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
|
||||
|
||||
/// 告警派发工单页面
|
||||
class AlarmDispatchPage extends StatelessWidget {
|
||||
final AlarmDetailEntity alarmDetail;
|
||||
|
||||
const AlarmDispatchPage({super.key, required this.alarmDetail});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => _createCubit(alarmDetail),
|
||||
child: _AlarmDispatchPageContent(),
|
||||
);
|
||||
}
|
||||
|
||||
AlarmDispatchCubit _createCubit(AlarmDetailEntity alarmDetail) {
|
||||
final sl = GetIt.I;
|
||||
final datasource = AlarmDispatchRemoteDataSourceImpl();
|
||||
final repository = AlarmDispatchRepositoryImpl(
|
||||
remoteDataSource: datasource,
|
||||
);
|
||||
final useCase = DispatchWorkOrderUseCase(repository);
|
||||
return AlarmDispatchCubit(
|
||||
dispatchUseCase: useCase,
|
||||
alarmDetail: alarmDetail,
|
||||
dio: sl<Dio>(),
|
||||
appUserCubit: sl<AppUserCubit>(),
|
||||
userStorage: sl<UserStorage>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AlarmDispatchPageContent extends StatelessWidget {
|
||||
const _AlarmDispatchPageContent();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.cardBackground,
|
||||
appBar: _buildAppBar(context),
|
||||
body: BlocConsumer<AlarmDispatchCubit, AlarmDispatchState>(
|
||||
listener: (context, state) {
|
||||
if (state is AlarmDispatchFormState && state.toastMessage != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.toastMessage!),
|
||||
backgroundColor: state.isSuccess ? Colors.green : Colors.red,
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
context.read<AlarmDispatchCubit>().clearToast();
|
||||
if (state.isSuccess) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is AlarmDispatchSubmitting) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AlarmDispatchLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AlarmDispatchFormState) {
|
||||
return _buildForm(context, state);
|
||||
}
|
||||
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
PreferredSizeWidget _buildAppBar(BuildContext context) {
|
||||
return AppBar(
|
||||
backgroundColor: AppColors.background,
|
||||
elevation: 0,
|
||||
title: const Text(
|
||||
'告警派发工单',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
centerTitle: true,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios, size: 20, color: Colors.black),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.read<AlarmDispatchCubit>().submitDispatch(),
|
||||
child: const Text(
|
||||
'提交',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildForm(BuildContext context, AlarmDispatchFormState state) {
|
||||
final cubit = context.read<AlarmDispatchCubit>();
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(bottom: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 场站信息
|
||||
_buildSiteInfoCard(state),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 告警关联信息条
|
||||
_buildAlarmInfoBar(state),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 上报类型选择
|
||||
ReportTypeSelector(
|
||||
selectedType: state.selectedReportType,
|
||||
onSelected: (type) => cubit.selectReportType(type),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 设备选择
|
||||
DeviceSelector(
|
||||
selectedDevice: state.selectedDevice,
|
||||
onTap: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('设备已从告警自动关联,暂不支持修改'),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 问题描述
|
||||
DescriptionInput(
|
||||
description: state.entity.description,
|
||||
onChanged: (value) => cubit.updateDescription(value),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 媒体上传
|
||||
MediaUploader(
|
||||
mediaFiles: state.mediaFiles,
|
||||
onCameraTap: () => _pickImage(cubit),
|
||||
onVideoTap: () => _pickVideo(cubit),
|
||||
onAddFromGallery: () => _pickFromGallery(context, cubit),
|
||||
onTap: (index) {
|
||||
_previewMedia(context, state.mediaFiles, index);
|
||||
},
|
||||
onRemove: (index) => cubit.removeMediaFile(index),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 计划时间
|
||||
_buildPlanTimeSection(context, state, cubit),
|
||||
const SizedBox(height: AppDimensions.moduleSpacing),
|
||||
// 问题等级
|
||||
LevelSelector(
|
||||
selectedLevel: state.selectedProblemLevel,
|
||||
onSelected: (level) => cubit.selectProblemLevel(level),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 场站信息卡片
|
||||
Widget _buildSiteInfoCard(AlarmDispatchFormState state) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadius),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0x0D000000),
|
||||
blurRadius: AppDimensions.cardShadowBlur,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Row(
|
||||
children: [
|
||||
Icon(Icons.location_on, size: 18, color: AppColors.primary),
|
||||
SizedBox(width: 6),
|
||||
Text(
|
||||
'场站信息',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
// _buildInfoLabel('场站ID'),
|
||||
// const SizedBox(width: 8),
|
||||
// Text(
|
||||
// state.siteId != null ? '${state.siteId}' : '--',
|
||||
// style: const TextStyle(
|
||||
// fontSize: 14,
|
||||
// color: AppColors.textPrimary,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(width: 24),
|
||||
_buildInfoLabel('场站名称'),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.siteName ?? '加载中...',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: state.siteName != null
|
||||
? AppColors.textPrimary
|
||||
: AppColors.textHint,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
_buildInfoLabel('告警编号'),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.alarmNo ?? state.alarmId,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textPrimary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoLabel(String label) {
|
||||
return Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.textHint),
|
||||
);
|
||||
}
|
||||
|
||||
/// 告警关联信息条
|
||||
Widget _buildAlarmInfoBar(AlarmDispatchFormState state) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF7E6),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
border: Border.all(color: const Color(0xFFFFD591)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
color: Color(0xFFFA8C16),
|
||||
size: 18,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'关联告警: ${state.alarmNo ?? state.alarmId}',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF8C6E1F),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, size: 18, color: Color(0xFFFA8C16)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 计划时间区域
|
||||
Widget _buildPlanTimeSection(
|
||||
BuildContext context,
|
||||
AlarmDispatchFormState state,
|
||||
AlarmDispatchCubit cubit,
|
||||
) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.horizontalPadding,
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadius),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0x0D000000),
|
||||
blurRadius: AppDimensions.cardShadowBlur,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'计划时间',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildTimeRow(
|
||||
label: '计划开始',
|
||||
time: state.planStartTime,
|
||||
onTap: () => _pickDateTime(context, (time) {
|
||||
cubit.updatePlanStartTime(time);
|
||||
}),
|
||||
required: true,
|
||||
),
|
||||
// const SizedBox(height: 8),
|
||||
// _buildTimeRow(
|
||||
// label: '计划结束',
|
||||
// time: state.planEndTime,
|
||||
// onTap: () => _pickDateTime(context, (time) {
|
||||
// cubit.updatePlanEndTime(time);
|
||||
// }),
|
||||
// required: true,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTimeRow({
|
||||
required String label,
|
||||
required DateTime? time,
|
||||
required VoidCallback onTap,
|
||||
required bool required,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.borderRadiusSmall),
|
||||
border: Border.all(color: AppColors.borderColor),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'$label${required ? ' *' : ''}',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
time != null
|
||||
? '${time.year}-${time.month.toString().padLeft(2, '0')}-${time.day.toString().padLeft(2, '0')} '
|
||||
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}'
|
||||
: '请选择',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: time != null
|
||||
? AppColors.textPrimary
|
||||
: AppColors.textHint,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(
|
||||
Icons.calendar_today,
|
||||
size: 16,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pickDateTime(
|
||||
BuildContext context,
|
||||
Function(DateTime) onPicked,
|
||||
) async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime.now().subtract(const Duration(days: 30)),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
||||
helpText: '选择日期',
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
);
|
||||
if (date == null || !context.mounted) return;
|
||||
|
||||
final time = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
helpText: '选择时间',
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
);
|
||||
if (time == null) return;
|
||||
|
||||
final dateTime = DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
onPicked(dateTime);
|
||||
}
|
||||
|
||||
Future<void> _pickImage(AlarmDispatchCubit cubit) async {
|
||||
final picker = ImagePicker();
|
||||
try {
|
||||
final image = await picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
maxWidth: 1920,
|
||||
maxHeight: 1080,
|
||||
imageQuality: 85,
|
||||
);
|
||||
if (image != null) {
|
||||
cubit.addMediaFile(image.path);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickVideo(AlarmDispatchCubit cubit) async {
|
||||
final picker = ImagePicker();
|
||||
try {
|
||||
final video = await picker.pickVideo(
|
||||
source: ImageSource.camera,
|
||||
maxDuration: const Duration(minutes: 5),
|
||||
);
|
||||
if (video != null) {
|
||||
cubit.addMediaFile(video.path);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
void _previewMedia(BuildContext context, List<String> mediaFiles, int index) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
MediaPreviewPage(mediaFiles: mediaFiles, initialIndex: index),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pickFromGallery(
|
||||
BuildContext context,
|
||||
AlarmDispatchCubit cubit,
|
||||
) async {
|
||||
final picker = ImagePicker();
|
||||
try {
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.image),
|
||||
title: const Text('选择图片'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context);
|
||||
final image = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxWidth: 1920,
|
||||
maxHeight: 1080,
|
||||
imageQuality: 85,
|
||||
);
|
||||
if (image != null) cubit.addMediaFile(image.path);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.video_library),
|
||||
title: const Text('选择视频'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context);
|
||||
final video = await picker.pickVideo(
|
||||
source: ImageSource.gallery,
|
||||
);
|
||||
if (video != null) cubit.addMediaFile(video.path);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,639 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_detail_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_detail_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_detail_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
class AlarmHandlePage extends StatelessWidget {
|
||||
final String alarmId;
|
||||
|
||||
const AlarmHandlePage({super.key, required this.alarmId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => sl<AlarmDetailCubit>()..loadAlarmDetail(alarmId),
|
||||
child: _AlarmHandlePageContent(alarmId: alarmId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AlarmHandlePageContent extends StatefulWidget {
|
||||
final String alarmId;
|
||||
|
||||
const _AlarmHandlePageContent({required this.alarmId});
|
||||
|
||||
@override
|
||||
State<_AlarmHandlePageContent> createState() =>
|
||||
_AlarmHandlePageContentState();
|
||||
}
|
||||
|
||||
class _AlarmHandlePageContentState extends State<_AlarmHandlePageContent> {
|
||||
final TextEditingController _handlerController = TextEditingController();
|
||||
final TextEditingController _remarkController = TextEditingController();
|
||||
final TextEditingController _rootCauseController = TextEditingController();
|
||||
String _handleStatus = '已关闭';
|
||||
String _handleResult = '';
|
||||
String _currentAlarmStatus = '待处理';
|
||||
int? _selectedActionIndex;
|
||||
|
||||
final Map<String, String> _handleResultMap = {
|
||||
'Handled': '已处理',
|
||||
'Restored': '已恢复',
|
||||
'Ignored': '已忽略',
|
||||
'UnableToHandle': '无法处理',
|
||||
'ManufacturerHandling': '厂家处理中',
|
||||
'FalseAlarm': '误报',
|
||||
};
|
||||
|
||||
final List<Map<String, dynamic>> _actionButtons = [
|
||||
{
|
||||
'label': '确认告警',
|
||||
'icon': Icons.check_circle_outline,
|
||||
'color': const Color(0xFF52C41A),
|
||||
'bgColor': const Color(0xFFF6FFED),
|
||||
'confirmedLabel': '已确认告警',
|
||||
'confirmedTip': '确认无需',
|
||||
'unconfirmedTip': '确认无需',
|
||||
},
|
||||
{
|
||||
'label': '派发工单',
|
||||
'icon': Icons.file_copy_outlined,
|
||||
'color': const Color(0xFF1890FF),
|
||||
'bgColor': const Color(0xFFE6F7FF),
|
||||
'tip': '请填下方表格',
|
||||
},
|
||||
{
|
||||
'label': '联系负责人',
|
||||
'icon': Icons.person_outline,
|
||||
'color': const Color(0xFFFA8C16),
|
||||
'bgColor': const Color(0xFFFFF7E6),
|
||||
'tip': '暂无功能',
|
||||
},
|
||||
{
|
||||
'label': '拍照取证',
|
||||
'icon': Icons.camera_alt_outlined,
|
||||
'color': const Color(0xFF722ED1),
|
||||
'bgColor': const Color(0xFFF9F0FF),
|
||||
'tip': '暂不支持',
|
||||
},
|
||||
{
|
||||
'label': '备注记录',
|
||||
'icon': Icons.edit_note_outlined,
|
||||
'color': const Color(0xFF13C2C2),
|
||||
'bgColor': const Color(0xFFE6FFFB),
|
||||
'tip': '请填下方表格',
|
||||
},
|
||||
{
|
||||
'label': '更多操作',
|
||||
'icon': Icons.more_horiz,
|
||||
'color': const Color(0xFF8C8C8C),
|
||||
'bgColor': const Color(0xFFF5F5F5),
|
||||
'tip': '暂未开发',
|
||||
},
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF5F5F5),
|
||||
appBar: _buildAppBar(),
|
||||
body: BlocConsumer<AlarmDetailCubit, AlarmDetailState>(
|
||||
listener: (context, state) {
|
||||
if (state is AlarmDetailLoaded && state.isHandleSuccess) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('处理成功'),
|
||||
backgroundColor: Color(0xFF52C41A),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
context.pop();
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is AlarmDetailLoaded) {
|
||||
_currentAlarmStatus = state.alarmDetail.alarmStatus;
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildAlarmInfoCard(state.alarmDetail),
|
||||
const SizedBox(height: 16),
|
||||
_buildActionButtons(),
|
||||
const SizedBox(height: 16),
|
||||
_buildFormCard(),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AlarmDetailError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: Color(0xFFBFBFBF),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
state.message,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF8C8C8C),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => context
|
||||
.read<AlarmDetailCubit>()
|
||||
.loadAlarmDetail(widget.alarmId),
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('重试'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF1890FF),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
bottomNavigationBar: _buildBottomSubmitButton(),
|
||||
);
|
||||
}
|
||||
|
||||
AppBar _buildAppBar() {
|
||||
return AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios, color: Colors.black, size: 20),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
title: const Text(
|
||||
'告警处理',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAlarmInfoCard(AlarmDetailEntity alarm) {
|
||||
final levelColor = alarm.level == AlarmLevel.danger
|
||||
? const Color(0xFFFF4D4F)
|
||||
: alarm.level == AlarmLevel.warning
|
||||
? const Color(0xFFFA8C16)
|
||||
: alarm.level == AlarmLevel.low
|
||||
? const Color(0xFF1890FF)
|
||||
: const Color(0xFF52C41A);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.warning, color: levelColor, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
alarm.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: levelColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
alarm.level.label,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: levelColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'${alarm.alarmNo ?? alarm.id} | ${alarm.deviceInfo} | ${alarm.occurTime}',
|
||||
style: const TextStyle(fontSize: 13, color: Color(0xFF8C8C8C)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionButtons() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
childAspectRatio: 1,
|
||||
crossAxisSpacing: 16,
|
||||
mainAxisSpacing: 16,
|
||||
),
|
||||
itemCount: _actionButtons.length,
|
||||
itemBuilder: (context, index) {
|
||||
final button = _actionButtons[index];
|
||||
return _buildActionButton(button, index);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionButton(Map<String, dynamic> button, int index) {
|
||||
final isConfirmed = _currentAlarmStatus != '待处理';
|
||||
final isSelected = _selectedActionIndex == index;
|
||||
String displayLabel = button['label'] as String;
|
||||
|
||||
if (index == 0 && isConfirmed && button.containsKey('confirmedLabel')) {
|
||||
displayLabel = button['confirmedLabel'] as String;
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => _onActionButtonTap(button, index),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? (button['color'] as Color)
|
||||
: (button['bgColor'] as Color),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: isSelected
|
||||
? Border.all(color: button['color'] as Color, width: 2)
|
||||
: Border.all(color: Colors.transparent),
|
||||
),
|
||||
child: Icon(
|
||||
button['icon'] as IconData,
|
||||
color: isSelected ? Colors.white : (button['color'] as Color),
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
displayLabel,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: button['color'] as Color,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onActionButtonTap(Map<String, dynamic> button, int index) {
|
||||
setState(() {
|
||||
_selectedActionIndex = index;
|
||||
});
|
||||
|
||||
// 确认告警:暂未开放
|
||||
if (index == 0) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('暂未开放'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 派发工单:跳转到告警派发页面
|
||||
if (index == 1) {
|
||||
final cubitState = context.read<AlarmDetailCubit>().state;
|
||||
if (cubitState is AlarmDetailLoaded) {
|
||||
context.push(
|
||||
'/alarm_center/detail/${widget.alarmId}/handle/dispatch',
|
||||
extra: cubitState.alarmDetail,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String tip = button['tip'] as String? ?? '';
|
||||
|
||||
if (tip.isNotEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(tip),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildFormCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildFormRow(
|
||||
label: '处理状态',
|
||||
child: _buildDropdown(
|
||||
value: _handleStatus,
|
||||
items: const ['已关闭'],
|
||||
onChanged: (value) {
|
||||
setState(() => _handleStatus = value!);
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildFormRow(label: '处理结果', child: _buildHandleResultDropdown()),
|
||||
_buildDivider(),
|
||||
_buildFormRow(
|
||||
label: '根因分析',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _rootCauseController,
|
||||
maxLines: 4,
|
||||
maxLength: 200,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入根因分析,最多200字',
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Text(
|
||||
'${_rootCauseController.text.length}/200',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFBFBFBF),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildFormRow(
|
||||
label: '处理人',
|
||||
child: TextField(
|
||||
controller: _handlerController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入处理人',
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildFormRow(
|
||||
label: '备注说明',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _remarkController,
|
||||
maxLines: 4,
|
||||
maxLength: 200,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入处理备注,最多200字',
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Text(
|
||||
'${_remarkController.text.length}/200',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFBFBFBF),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFormRow({required String label, required Widget child}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 72,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF8C8C8C)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: child),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdown({
|
||||
required String value,
|
||||
required List<String> items,
|
||||
String? hintText,
|
||||
required ValueChanged<String?> onChanged,
|
||||
}) {
|
||||
return DropdownButtonFormField<String>(
|
||||
value: value.isEmpty ? null : value,
|
||||
items: items.map((item) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: item,
|
||||
child: Text(
|
||||
item.isEmpty ? hintText ?? '' : item,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: item.isEmpty ? const Color(0xFFBFBFBF) : Colors.black,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: onChanged,
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
icon: const Icon(Icons.keyboard_arrow_down, color: Color(0xFFBFBFBF)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHandleResultDropdown() {
|
||||
return DropdownButtonFormField<String>(
|
||||
value: _handleResult.isEmpty ? null : _handleResult,
|
||||
items: [
|
||||
const DropdownMenuItem<String>(
|
||||
value: '',
|
||||
child: Text(
|
||||
'请选择处理结果',
|
||||
style: TextStyle(fontSize: 14, color: Color(0xFFBFBFBF)),
|
||||
),
|
||||
),
|
||||
..._handleResultMap.entries.map((entry) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: entry.key,
|
||||
child: Text(
|
||||
entry.value,
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() => _handleResult = value ?? '');
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 12),
|
||||
isDense: false,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black),
|
||||
icon: const Icon(Icons.keyboard_arrow_down, color: Color(0xFFBFBFBF)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDivider() {
|
||||
return const Divider(height: 1, color: Color(0xFFF0F0F0));
|
||||
}
|
||||
|
||||
Widget _buildBottomSubmitButton() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, -2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 56,
|
||||
child: ElevatedButton(
|
||||
onPressed: _submitHandle,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF1890FF),
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'提交处理',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _submitHandle() {
|
||||
int handleStatusValue = 2;
|
||||
debugPrint('提交处理 - handleStatus: $handleStatusValue');
|
||||
|
||||
final handleData = {
|
||||
'alarmId': widget.alarmId,
|
||||
'handleStatus': handleStatusValue,
|
||||
'handleRemark': _remarkController.text,
|
||||
'rootCause': _rootCauseController.text,
|
||||
'handleResult': _handleResult,
|
||||
};
|
||||
|
||||
context.read<AlarmDetailCubit>().handleAlarm(handleData);
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,59 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/message_center/presentation/pages/message_center_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_detail_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_detail_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/pages/alarm_center_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/pages/alarm_detail_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/pages/alarm_handle_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/pages/alarm_dispatch_page.dart';
|
||||
|
||||
/// 告警中心路由配置
|
||||
class AlarmCenterRoutes {
|
||||
static List<RouteBase> get routes => [
|
||||
GoRoute(
|
||||
path: '/alarm_center',
|
||||
name: 'alarmCenter',
|
||||
builder: (context, state) => const AlarmCenterPage(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/alarm_center',
|
||||
name: 'alarmCenter',
|
||||
builder: (context, state) => const AlarmCenterPage(),
|
||||
path: 'detail/:alarmId',
|
||||
name: 'alarmDetail',
|
||||
builder: (context, state) {
|
||||
final alarmId = state.pathParameters['alarmId']!;
|
||||
return BlocProvider(
|
||||
create: (_) => sl<AlarmDetailCubit>(),
|
||||
child: AlarmDetailPage(alarmId: alarmId),
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'detail/:alarmId',
|
||||
name: 'alarmDetail',
|
||||
path: 'handle',
|
||||
name: 'alarmHandle',
|
||||
builder: (context, state) {
|
||||
final alarmId = state.pathParameters['alarmId']!;
|
||||
return BlocProvider(
|
||||
create: (_) => sl<AlarmDetailCubit>(),
|
||||
child: AlarmDetailPage(alarmId: alarmId),
|
||||
);
|
||||
return AlarmHandlePage(alarmId: alarmId);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'dispatch',
|
||||
name: 'alarmDispatch',
|
||||
builder: (context, state) {
|
||||
final alarmDetail = state.extra as AlarmDetailEntity;
|
||||
return AlarmDispatchPage(alarmDetail: alarmDetail);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// 消息中心页路由
|
||||
GoRoute(
|
||||
path: '/message_center',
|
||||
name: 'messageCenter',
|
||||
builder: (context, state) => const MessageCenterPage(),
|
||||
),
|
||||
];
|
||||
],
|
||||
),
|
||||
// 消息中心页路由
|
||||
GoRoute(
|
||||
path: '/message_center',
|
||||
name: 'messageCenter',
|
||||
builder: (context, state) => const MessageCenterPage(),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../domain/entities/alarm_dispatch_entity.dart';
|
||||
import '../../../report/presentation/constants/report_constants.dart';
|
||||
|
||||
/// 告警派发状态基类
|
||||
abstract class AlarmDispatchState extends Equatable {
|
||||
const AlarmDispatchState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// 加载中
|
||||
class AlarmDispatchLoading extends AlarmDispatchState {}
|
||||
|
||||
/// 提交中
|
||||
class AlarmDispatchSubmitting extends AlarmDispatchState {}
|
||||
|
||||
/// 表单状态
|
||||
class AlarmDispatchFormState extends AlarmDispatchState {
|
||||
/// 关联的告警ID
|
||||
final String alarmId;
|
||||
|
||||
/// 告警编号
|
||||
final String? alarmNo;
|
||||
|
||||
/// 派发实体
|
||||
final AlarmDispatchEntity entity;
|
||||
|
||||
/// 选中的上报类型
|
||||
final ReportType? selectedReportType;
|
||||
|
||||
/// 选中的问题等级
|
||||
final ProblemLevel? selectedProblemLevel;
|
||||
|
||||
/// 选中的设备
|
||||
final String? selectedDevice;
|
||||
|
||||
/// 选中的设备ID
|
||||
final String? selectedDeviceId;
|
||||
|
||||
/// 媒体文件列表
|
||||
final List<String> mediaFiles;
|
||||
|
||||
/// 计划开始时间
|
||||
final DateTime? planStartTime;
|
||||
|
||||
/// 计划结束时间
|
||||
final DateTime? planEndTime;
|
||||
|
||||
/// toast 消息(成功/失败)
|
||||
final String? toastMessage;
|
||||
|
||||
/// 场站ID(展示用)
|
||||
final int? siteId;
|
||||
|
||||
/// 场站名称(展示用)
|
||||
final String? siteName;
|
||||
|
||||
/// 是否为成功消息
|
||||
final bool isSuccess;
|
||||
|
||||
const AlarmDispatchFormState({
|
||||
required this.alarmId,
|
||||
this.alarmNo,
|
||||
required this.entity,
|
||||
this.selectedReportType,
|
||||
this.selectedProblemLevel,
|
||||
this.selectedDevice,
|
||||
this.selectedDeviceId,
|
||||
this.mediaFiles = const [],
|
||||
this.planStartTime,
|
||||
this.planEndTime,
|
||||
this.toastMessage,
|
||||
this.isSuccess = false,
|
||||
this.siteId,
|
||||
this.siteName,
|
||||
});
|
||||
|
||||
AlarmDispatchFormState copyWith({
|
||||
AlarmDispatchEntity? entity,
|
||||
ReportType? selectedReportType,
|
||||
ProblemLevel? selectedProblemLevel,
|
||||
String? selectedDevice,
|
||||
String? selectedDeviceId,
|
||||
List<String>? mediaFiles,
|
||||
DateTime? planStartTime,
|
||||
DateTime? planEndTime,
|
||||
String? toastMessage,
|
||||
bool? isSuccess,
|
||||
int? siteId,
|
||||
String? siteName,
|
||||
}) {
|
||||
return AlarmDispatchFormState(
|
||||
alarmId: alarmId,
|
||||
alarmNo: alarmNo,
|
||||
entity: entity ?? this.entity,
|
||||
selectedReportType: selectedReportType ?? this.selectedReportType,
|
||||
selectedProblemLevel: selectedProblemLevel ?? this.selectedProblemLevel,
|
||||
selectedDevice: selectedDevice ?? this.selectedDevice,
|
||||
selectedDeviceId: selectedDeviceId ?? this.selectedDeviceId,
|
||||
mediaFiles: mediaFiles ?? this.mediaFiles,
|
||||
planStartTime: planStartTime ?? this.planStartTime,
|
||||
planEndTime: planEndTime ?? this.planEndTime,
|
||||
toastMessage: toastMessage,
|
||||
isSuccess: isSuccess ?? this.isSuccess,
|
||||
siteId: siteId ?? this.siteId,
|
||||
siteName: siteName ?? this.siteName,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
alarmId,
|
||||
alarmNo,
|
||||
entity,
|
||||
selectedReportType,
|
||||
selectedProblemLevel,
|
||||
selectedDevice,
|
||||
selectedDeviceId,
|
||||
mediaFiles,
|
||||
planStartTime,
|
||||
planEndTime,
|
||||
toastMessage,
|
||||
isSuccess,
|
||||
siteId,
|
||||
siteName,
|
||||
];
|
||||
}
|
||||
@@ -3,11 +3,15 @@ import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/domain/entities/alarm_count_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 告警统计卡片
|
||||
class AlarmCountCard extends StatelessWidget {
|
||||
const AlarmCountCard({super.key, required this.count});
|
||||
const AlarmCountCard({
|
||||
super.key,
|
||||
required this.count,
|
||||
this.isCountLoading = false,
|
||||
});
|
||||
|
||||
final AlarmCountEntity count;
|
||||
final bool isCountLoading;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -25,9 +29,7 @@ class AlarmCountCard extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildCountItem(
|
||||
label: AppLocalizations.of(
|
||||
context,
|
||||
).translate('alarm_center.unprocessed'),
|
||||
label: '待处理',
|
||||
value: count.unprocessed,
|
||||
color: AlarmColors.danger,
|
||||
bgColor: AlarmColors.unprocessedBg,
|
||||
@@ -37,15 +39,7 @@ class AlarmCountCard extends StatelessWidget {
|
||||
_buildDivider(),
|
||||
Expanded(
|
||||
child: _buildCountItem(
|
||||
label: '处理中',
|
||||
value: count.processing,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
_buildDivider(),
|
||||
Expanded(
|
||||
child: _buildCountItem(
|
||||
label: '已确认',
|
||||
label: '已关闭',
|
||||
value: count.confirmed,
|
||||
color: const Color(0xFF1D2129),
|
||||
),
|
||||
@@ -88,14 +82,25 @@ class AlarmCountCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
isCountLoading
|
||||
? const SizedBox(
|
||||
height: 24,
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
value.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -85,12 +85,10 @@ class AlarmItemCard extends StatelessWidget {
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
_getStatusLabel(context, alarm.status),
|
||||
alarm.status.label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: alarm.status == AlarmStatus.unconfirmed
|
||||
? AlarmColors.warning
|
||||
: AlarmColors.textTertiary,
|
||||
color: _getStatusColor(alarm.status),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
@@ -98,9 +96,7 @@ class AlarmItemCard extends StatelessWidget {
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 12,
|
||||
color: alarm.status == AlarmStatus.unconfirmed
|
||||
? AlarmColors.warning
|
||||
: AlarmColors.textTertiary,
|
||||
color: _getStatusColor(alarm.status),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -125,16 +121,14 @@ class AlarmItemCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
String _getStatusLabel(BuildContext context, AlarmStatus status) {
|
||||
Color _getStatusColor(AlarmStatus status) {
|
||||
switch (status) {
|
||||
case AlarmStatus.unconfirmed:
|
||||
return AppLocalizations.of(
|
||||
context,
|
||||
).translate('alarm_center.unconfirmed');
|
||||
case AlarmStatus.confirmed:
|
||||
return AppLocalizations.of(context).translate('alarm_center.confirmed');
|
||||
case AlarmStatus.recovered:
|
||||
return AppLocalizations.of(context).translate('alarm_center.recovered');
|
||||
case AlarmStatus.pending:
|
||||
return AlarmColors.danger;
|
||||
case AlarmStatus.processing:
|
||||
case AlarmStatus.closed:
|
||||
case AlarmStatus.ignored:
|
||||
return AlarmColors.textTertiary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
|
||||
|
||||
/// 告警筛选标签栏
|
||||
/// 告警筛选标签栏 - 全部/未处理/已确认/已恢复
|
||||
class AlarmTabBar extends StatelessWidget {
|
||||
const AlarmTabBar({
|
||||
super.key,
|
||||
@@ -15,6 +15,14 @@ class AlarmTabBar extends StatelessWidget {
|
||||
final ValueChanged<AlarmFilterTab> onFilterChanged;
|
||||
final Color backgroundColor;
|
||||
|
||||
// 待显示的标签列表(已注释掉"已确认"标签)
|
||||
static const List<AlarmFilterTab> _visibleTabs = [
|
||||
AlarmFilterTab.all,
|
||||
AlarmFilterTab.unprocessed,
|
||||
// AlarmFilterTab.confirmed, // 已确认 - 暂不显示
|
||||
AlarmFilterTab.recovered,
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@@ -23,44 +31,14 @@ class AlarmTabBar extends StatelessWidget {
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: AlarmFilterTab.values.length,
|
||||
itemCount: _visibleTabs.length,
|
||||
itemBuilder: (context, index) {
|
||||
final filter = AlarmFilterTab.values[index];
|
||||
final isSelected = selectedFilter == filter;
|
||||
|
||||
return GestureDetector(
|
||||
final filter = _visibleTabs[index];
|
||||
return _buildTabItem(
|
||||
context,
|
||||
label: _getFilterLabel(context, filter),
|
||||
isSelected: selectedFilter == filter,
|
||||
onTap: () => onFilterChanged(filter),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
_getFilterLabel(context, filter),
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: isSelected
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal,
|
||||
color: isSelected
|
||||
? AlarmColors.primary
|
||||
: AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
height: 2,
|
||||
width: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AlarmColors.primary
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -72,13 +50,49 @@ class AlarmTabBar extends StatelessWidget {
|
||||
case AlarmFilterTab.all:
|
||||
return AppLocalizations.of(context).translate('alarm_center.all');
|
||||
case AlarmFilterTab.unprocessed:
|
||||
return AppLocalizations.of(
|
||||
context,
|
||||
).translate('alarm_center.unprocessed');
|
||||
return '待处理';
|
||||
case AlarmFilterTab.confirmed:
|
||||
return AppLocalizations.of(context).translate('alarm_center.confirmed');
|
||||
case AlarmFilterTab.recovered:
|
||||
return AppLocalizations.of(context).translate('alarm_center.recovered');
|
||||
return '已关闭(已恢复)';
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildTabItem(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
required bool isSelected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
color: isSelected
|
||||
? AlarmColors.primary
|
||||
: AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
height: 2,
|
||||
width: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? AlarmColors.primary : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user