一次大的提交
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user