告警中心的二级详情页面+信息中心的页面+对接机器人接口
This commit is contained in:
@@ -0,0 +1,569 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.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';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/metric_trend_chart.dart';
|
||||
|
||||
/// 告警详情页面
|
||||
class AlarmDetailPage extends StatefulWidget {
|
||||
final String alarmId;
|
||||
|
||||
const AlarmDetailPage({
|
||||
super.key,
|
||||
required this.alarmId,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AlarmDetailPage> createState() => _AlarmDetailPageState();
|
||||
}
|
||||
|
||||
class _AlarmDetailPageState extends State<AlarmDetailPage> {
|
||||
late AlarmDetailCubit _cubit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cubit = context.read<AlarmDetailCubit>();
|
||||
_cubit.loadAlarmDetail(widget.alarmId);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: SystemUiOverlayStyle.dark.copyWith(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
),
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFFF5F7FA),
|
||||
appBar: _buildAppBar(),
|
||||
body: BlocConsumer<AlarmDetailCubit, AlarmDetailState>(
|
||||
listener: (context, state) {
|
||||
// 监听AI诊断结果
|
||||
if (state is AlarmDetailLoaded && state.aiDiagnosisResult != null) {
|
||||
_showAIDiagnosisDialog(state.aiDiagnosisResult!);
|
||||
}
|
||||
|
||||
// 确认告警成功后返回
|
||||
if (state is AlarmDetailLoaded && state.isConfirmed) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('告警已确认'),
|
||||
backgroundColor: AlarmColors.success,
|
||||
),
|
||||
);
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (mounted) {
|
||||
context.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is AlarmDetailLoading || state is AlarmDetailInitial) {
|
||||
return _buildSkeletonScreen();
|
||||
}
|
||||
|
||||
if (state is AlarmDetailError) {
|
||||
return _buildErrorState(state.message);
|
||||
}
|
||||
|
||||
if (state is AlarmDetailLoaded) {
|
||||
return _buildContent(state);
|
||||
}
|
||||
|
||||
if (state is AlarmDetailActionInProgress) {
|
||||
return _buildLoadingOverlay(state.action);
|
||||
}
|
||||
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
PreferredSizeWidget _buildAppBar() {
|
||||
return AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: AlarmColors.textPrimary),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
title: const Text(
|
||||
'告警详情',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.share_outlined, color: AlarmColors.textPrimary),
|
||||
onPressed: () {
|
||||
// TODO: 分享功能
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 骨架屏
|
||||
Widget _buildSkeletonScreen() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildSkeletonCard(height: 120),
|
||||
const SizedBox(height: 16),
|
||||
_buildSkeletonCard(height: 200),
|
||||
const SizedBox(height: 16),
|
||||
_buildSkeletonCard(height: 150),
|
||||
const SizedBox(height: 80),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSkeletonCard({required double height}) {
|
||||
return Container(
|
||||
height: height,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AlarmColors.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 错误状态
|
||||
Widget _buildErrorState(String message) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: AlarmColors.textTertiary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
message,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AlarmColors.textSecondary,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => _cubit.loadAlarmDetail(widget.alarmId),
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('重试'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AlarmColors.primary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 加载中覆盖层
|
||||
Widget _buildLoadingOverlay(String action) {
|
||||
return Container(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
child: Center(
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
color: AlarmColors.primary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'$action...',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 主内容
|
||||
Widget _buildContent(AlarmDetailLoaded state) {
|
||||
final alarm = state.alarmDetail;
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 告警头部信息
|
||||
_buildAlarmHeader(alarm),
|
||||
const SizedBox(height: 16),
|
||||
// 告警详情信息列表
|
||||
_buildAlarmInfoList(alarm),
|
||||
const SizedBox(height: 16),
|
||||
// 指标趋势图
|
||||
MetricTrendChart(
|
||||
historyData: alarm.historyData,
|
||||
selectedMetric: state.selectedMetric,
|
||||
onMetricChanged: (metric) => _cubit.changeMetricType(metric),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 处理建议
|
||||
_buildSuggestionsCard(alarm.suggestions),
|
||||
const SizedBox(height: 100), // 为底部按钮留出空间
|
||||
],
|
||||
),
|
||||
),
|
||||
// 底部固定按钮
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: _buildBottomButtons(state),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 告警头部信息
|
||||
Widget _buildAlarmHeader(AlarmDetailEntity alarm) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [AlarmDimensions.cardShadow],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
color: AlarmColors.danger,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
alarm.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AlarmColors.danger.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
alarm.level.label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AlarmColors.danger,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
alarm.deviceInfo,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
alarm.occurTime,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AlarmColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 告警详情信息列表
|
||||
Widget _buildAlarmInfoList(AlarmDetailEntity alarm) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
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),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value, {Color? valueColor, bool isLast = false}) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: isLast ? 0 : 12),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
value,
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: valueColor ?? AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDivider() {
|
||||
return const Divider(
|
||||
height: 24,
|
||||
thickness: 0.5,
|
||||
color: Color(0xFFE5E6EB),
|
||||
);
|
||||
}
|
||||
|
||||
/// 处理建议卡片
|
||||
Widget _buildSuggestionsCard(List<String> suggestions) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [AlarmDimensions.cardShadow],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'处理建议',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
...suggestions.asMap().entries.map((entry) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${entry.key + 1}. ',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
entry.value,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AlarmColors.textSecondary,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 底部按钮
|
||||
Widget _buildBottomButtons(AlarmDetailLoaded state) {
|
||||
final isConfirmed = state.isConfirmed;
|
||||
final isInProgress = _cubit.state is AlarmDetailActionInProgress;
|
||||
final isDisabled = isConfirmed || isInProgress;
|
||||
|
||||
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: Row(
|
||||
children: [
|
||||
// AI诊断按钮
|
||||
Expanded(
|
||||
child: _buildButton(
|
||||
text: 'AI诊断',
|
||||
isPrimary: false,
|
||||
isLoading: isInProgress && _cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action == 'AI诊断',
|
||||
isDisabled: isDisabled,
|
||||
onPressed: isDisabled
|
||||
? null
|
||||
: () => _cubit.aiDiagnosis(widget.alarmId),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
// 确认告警按钮
|
||||
Expanded(
|
||||
child: _buildButton(
|
||||
text: '确认告警',
|
||||
isPrimary: true,
|
||||
isLoading: isInProgress && _cubit.state is AlarmDetailActionInProgress &&
|
||||
(_cubit.state as AlarmDetailActionInProgress).action == '确认告警',
|
||||
isDisabled: isDisabled,
|
||||
onPressed: isDisabled
|
||||
? null
|
||||
: () => _cubit.confirmAlarm(widget.alarmId),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildButton({
|
||||
required String text,
|
||||
required bool isPrimary,
|
||||
required bool isLoading,
|
||||
required bool isDisabled,
|
||||
VoidCallback? onPressed,
|
||||
}) {
|
||||
return SizedBox(
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: isLoading || isDisabled ? null : onPressed,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: isPrimary ? AlarmColors.primary : Colors.white,
|
||||
foregroundColor: isPrimary ? Colors.white : AlarmColors.primary,
|
||||
elevation: 0,
|
||||
side: isPrimary ? null : const BorderSide(color: AlarmColors.primary),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: isLoading
|
||||
? SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: isPrimary ? Colors.white : AlarmColors.primary,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示AI诊断结果弹窗
|
||||
void _showAIDiagnosisDialog(String result) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text(
|
||||
'AI诊断结果',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
content: SingleChildScrollView(
|
||||
child: Text(
|
||||
result,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.6,
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: const Text('关闭'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user