639 lines
22 KiB
Dart
639 lines
22 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||
import 'package:maibu_satabot_v2/features/waring_center/presentation/bloc/warning_center_bloc.dart';
|
||
import 'package:maibu_satabot_v2/features/waring_center/presentation/bloc/warning_center_event.dart';
|
||
import 'package:maibu_satabot_v2/features/waring_center/presentation/bloc/warning_center_state.dart';
|
||
|
||
class WarningCenterPage extends StatefulWidget {
|
||
const WarningCenterPage({super.key});
|
||
|
||
@override
|
||
State<WarningCenterPage> createState() => _WarningCenterPageState();
|
||
}
|
||
|
||
class _WarningCenterPageState extends State<WarningCenterPage> {
|
||
late WarningCenterBloc _bloc;
|
||
final TextEditingController _searchController = TextEditingController();
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_bloc = WarningCenterBloc();
|
||
_bloc.add(const WarningCenterLoadData());
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
_searchController.dispose();
|
||
_bloc.close();
|
||
super.dispose();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return BlocProvider.value(
|
||
value: _bloc,
|
||
child: Scaffold(
|
||
backgroundColor: const Color(0xFF0A2E6B),
|
||
body: BlocBuilder<WarningCenterBloc, WarningCenterState>(
|
||
builder: (context, state) {
|
||
if (state is WarningCenterLoading) {
|
||
return const Center(
|
||
child: CircularProgressIndicator(color: Colors.white),
|
||
);
|
||
}
|
||
|
||
if (state is WarningCenterError) {
|
||
return Center(
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
const Icon(Icons.error_outline, color: Colors.white, size: 48),
|
||
const SizedBox(height: 16),
|
||
Text(
|
||
state.message,
|
||
style: const TextStyle(color: Colors.white),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
if (state is WarningCenterLoaded) {
|
||
return _buildContent(context, state);
|
||
}
|
||
|
||
return const SizedBox();
|
||
},
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildContent(BuildContext context, WarningCenterLoaded state) {
|
||
return CustomScrollView(
|
||
slivers: [
|
||
SliverAppBar(
|
||
expandedHeight: 80,
|
||
floating: false,
|
||
pinned: true,
|
||
backgroundColor: const Color(0xFF0A2E6B),
|
||
title: Row(
|
||
children: [
|
||
Text(
|
||
AppLocalizations.of(context).translate('warning_center.title'),
|
||
style: const TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 24,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
const SizedBox(width: 8),
|
||
Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xFF4A7AFF),
|
||
borderRadius: BorderRadius.circular(12),
|
||
),
|
||
child: const Text(
|
||
'1',
|
||
style: TextStyle(color: Colors.white, fontSize: 12),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
actions: [
|
||
Stack(
|
||
children: [
|
||
IconButton(
|
||
icon: const Icon(Icons.notifications_none, color: Colors.white, size: 28),
|
||
onPressed: () {},
|
||
),
|
||
Positioned(
|
||
right: 8,
|
||
top: 8,
|
||
child: Container(
|
||
padding: const EdgeInsets.all(4),
|
||
decoration: const BoxDecoration(
|
||
color: Colors.red,
|
||
shape: BoxShape.circle,
|
||
),
|
||
constraints: const BoxConstraints(
|
||
minWidth: 16,
|
||
minHeight: 16,
|
||
),
|
||
child: const Text(
|
||
'8',
|
||
style: TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 10,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
textAlign: TextAlign.center,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(width: 8),
|
||
],
|
||
),
|
||
SliverToBoxAdapter(
|
||
child: Container(
|
||
margin: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||
padding: const EdgeInsets.all(16),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(12),
|
||
),
|
||
child: Column(
|
||
children: [
|
||
Row(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Expanded(
|
||
flex: 2,
|
||
child: _buildTodayStatsCard(context, state),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Expanded(
|
||
flex: 3,
|
||
child: Column(
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: _buildStatsCard(
|
||
context,
|
||
AppLocalizations.of(context).translate('warning_center.severe_alerts'),
|
||
state.stats.severeCount.toString(),
|
||
const Color(0xFFE74C3C),
|
||
),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Expanded(
|
||
child: _buildStatsCard(
|
||
context,
|
||
AppLocalizations.of(context).translate('warning_center.processing'),
|
||
state.stats.processingCount.toString(),
|
||
const Color(0xFFF39C12),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 12),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: _buildStatsCard(
|
||
context,
|
||
AppLocalizations.of(context).translate('warning_center.closed'),
|
||
state.stats.closedCount.toString(),
|
||
const Color(0xFF27AE60),
|
||
),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Expanded(
|
||
child: _buildStatsCard(
|
||
context,
|
||
AppLocalizations.of(context).translate('warning_center.avg_response_time'),
|
||
'${state.stats.avgResponseTime}h',
|
||
const Color(0xFF3498DB),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
SliverToBoxAdapter(
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||
child: Column(
|
||
children: [
|
||
Wrap(
|
||
spacing: 8,
|
||
runSpacing: 8,
|
||
children: [
|
||
_buildFilterChip(context, state, AppLocalizations.of(context).translate('warning_center.all')),
|
||
_buildFilterChip(context, state, AppLocalizations.of(context).translate('warning_center.severe')),
|
||
_buildFilterChip(context, state, AppLocalizations.of(context).translate('warning_center.important')),
|
||
_buildFilterChip(context, state, AppLocalizations.of(context).translate('warning_center.general')),
|
||
_buildFilterChip(context, state, AppLocalizations.of(context).translate('warning_center.hint')),
|
||
Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||
decoration: BoxDecoration(
|
||
border: Border.all(color: Colors.grey.shade300),
|
||
borderRadius: BorderRadius.circular(16),
|
||
),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Text(
|
||
AppLocalizations.of(context).translate('warning_center.device_type'),
|
||
style: TextStyle(
|
||
fontSize: 13,
|
||
color: state.selectedLevel == AppLocalizations.of(context).translate('warning_center.all')
|
||
? const Color(0xFF4A7AFF)
|
||
: Colors.grey.shade700,
|
||
),
|
||
),
|
||
const SizedBox(width: 4),
|
||
Icon(Icons.keyboard_arrow_down, size: 16, color: Colors.grey.shade600),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 12),
|
||
Row(
|
||
children: [
|
||
_buildTimeFilterChip(context, state, AppLocalizations.of(context).translate('warning_center.last_7_days')),
|
||
const SizedBox(width: 8),
|
||
_buildTimeFilterChip(context, state, AppLocalizations.of(context).translate('warning_center.specific_date')),
|
||
const SizedBox(width: 8),
|
||
_buildTimeFilterChip(context, state, AppLocalizations.of(context).translate('warning_center.all')),
|
||
const SizedBox(width: 8),
|
||
Expanded(
|
||
child: Container(
|
||
height: 36,
|
||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(18),
|
||
border: Border.all(color: Colors.grey.shade300),
|
||
),
|
||
child: Row(
|
||
children: [
|
||
Expanded(
|
||
child: TextField(
|
||
controller: _searchController,
|
||
decoration: InputDecoration(
|
||
hintText: AppLocalizations.of(context).translate('warning_center.search_placeholder'),
|
||
hintStyle: TextStyle(fontSize: 13, color: Colors.grey.shade400),
|
||
border: InputBorder.none,
|
||
isDense: true,
|
||
),
|
||
style: const TextStyle(fontSize: 13),
|
||
onChanged: (value) {
|
||
_bloc.add(WarningCenterSearch(value));
|
||
},
|
||
),
|
||
),
|
||
Icon(Icons.search, size: 18, color: Colors.grey.shade400),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
SliverPadding(
|
||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||
sliver: SliverList(
|
||
delegate: SliverChildBuilderDelegate(
|
||
(context, index) {
|
||
final warning = state.warnings[index];
|
||
return _buildWarningCard(context, warning);
|
||
},
|
||
childCount: state.warnings.length,
|
||
),
|
||
),
|
||
),
|
||
const SliverToBoxAdapter(
|
||
child: SizedBox(height: 100),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
|
||
Widget _buildTodayStatsCard(BuildContext context, WarningCenterLoaded state) {
|
||
return Container(
|
||
padding: const EdgeInsets.all(16),
|
||
decoration: BoxDecoration(
|
||
gradient: const LinearGradient(
|
||
begin: Alignment.topLeft,
|
||
end: Alignment.bottomRight,
|
||
colors: [Color(0xFF4A7AFF), Color(0xFF2E5CDB)],
|
||
),
|
||
borderRadius: BorderRadius.circular(12),
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Text(
|
||
AppLocalizations.of(context).translate('warning_center.today_total'),
|
||
style: const TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 14,
|
||
),
|
||
),
|
||
const SizedBox(width: 8),
|
||
Container(
|
||
padding: const EdgeInsets.all(4),
|
||
decoration: const BoxDecoration(
|
||
color: Color(0xFFE74C3C),
|
||
shape: BoxShape.circle,
|
||
),
|
||
child: const Icon(Icons.arrow_downward, color: Colors.white, size: 12),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 8),
|
||
Text(
|
||
state.stats.todayCount.toString(),
|
||
style: const TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 36,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
Row(
|
||
children: [
|
||
const Icon(Icons.arrow_downward, color: Colors.white, size: 14),
|
||
const SizedBox(width: 4),
|
||
Text(
|
||
'${state.stats.changePercent.abs()}% ${AppLocalizations.of(context).translate('warning_center.vs_yesterday')}',
|
||
style: const TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 12,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildStatsCard(BuildContext context, String title, String value, Color color) {
|
||
return Container(
|
||
padding: const EdgeInsets.all(12),
|
||
decoration: BoxDecoration(
|
||
color: color,
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
title,
|
||
style: const TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 13,
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
Text(
|
||
value,
|
||
style: const TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 24,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildFilterChip(BuildContext context, WarningCenterLoaded state, String label) {
|
||
final isSelected = state.selectedLevel == label;
|
||
return GestureDetector(
|
||
onTap: () {
|
||
_bloc.add(WarningCenterFilterByLevel(label));
|
||
},
|
||
child: Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||
decoration: BoxDecoration(
|
||
color: isSelected ? const Color(0xFF4A7AFF) : Colors.white,
|
||
borderRadius: BorderRadius.circular(16),
|
||
border: Border.all(
|
||
color: isSelected ? const Color(0xFF4A7AFF) : Colors.grey.shade300,
|
||
),
|
||
),
|
||
child: Text(
|
||
label,
|
||
style: TextStyle(
|
||
fontSize: 13,
|
||
color: isSelected ? Colors.white : Colors.grey.shade700,
|
||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildTimeFilterChip(BuildContext context, WarningCenterLoaded state, String label) {
|
||
final isSelected = state.selectedTimeRange == label;
|
||
return GestureDetector(
|
||
onTap: () {
|
||
_bloc.add(WarningCenterFilterByTime(label));
|
||
},
|
||
child: Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||
decoration: BoxDecoration(
|
||
color: isSelected ? const Color(0xFF4A7AFF) : Colors.white,
|
||
borderRadius: BorderRadius.circular(16),
|
||
border: Border.all(
|
||
color: isSelected ? const Color(0xFF4A7AFF) : Colors.grey.shade300,
|
||
),
|
||
),
|
||
child: Text(
|
||
label,
|
||
style: TextStyle(
|
||
fontSize: 13,
|
||
color: isSelected ? Colors.white : Colors.grey.shade700,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildWarningCard(BuildContext context, WarningItem warning) {
|
||
Color levelColor;
|
||
switch (warning.level) {
|
||
case '严重':
|
||
levelColor = const Color(0xFFE74C3C);
|
||
break;
|
||
case '重要':
|
||
levelColor = const Color(0xFFF39C12);
|
||
break;
|
||
case '一般':
|
||
levelColor = const Color(0xFF27AE60);
|
||
break;
|
||
default:
|
||
levelColor = const Color(0xFF3498DB);
|
||
}
|
||
|
||
Color statusColor;
|
||
switch (warning.status) {
|
||
case '处理中':
|
||
statusColor = const Color(0xFF4A7AFF);
|
||
break;
|
||
case '待处理':
|
||
statusColor = const Color(0xFFF39C12);
|
||
break;
|
||
case '已关闭':
|
||
statusColor = const Color(0xFF27AE60);
|
||
break;
|
||
default:
|
||
statusColor = Colors.grey;
|
||
}
|
||
|
||
return Container(
|
||
margin: const EdgeInsets.only(bottom: 12),
|
||
padding: const EdgeInsets.all(16),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(12),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: Colors.black.withOpacity(0.05),
|
||
blurRadius: 8,
|
||
offset: const Offset(0, 2),
|
||
),
|
||
],
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||
decoration: BoxDecoration(
|
||
color: levelColor,
|
||
borderRadius: BorderRadius.circular(4),
|
||
),
|
||
child: Text(
|
||
warning.level,
|
||
style: const TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 13,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Expanded(
|
||
child: Text(
|
||
'${warning.deviceName}(${warning.deviceType})',
|
||
style: const TextStyle(
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.bold,
|
||
color: Color(0xFF1A1A1A),
|
||
),
|
||
),
|
||
),
|
||
Text(
|
||
warning.duration,
|
||
style: TextStyle(
|
||
fontSize: 13,
|
||
color: Colors.grey.shade600,
|
||
),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||
decoration: BoxDecoration(
|
||
color: statusColor.withOpacity(0.1),
|
||
borderRadius: BorderRadius.circular(4),
|
||
border: Border.all(color: statusColor),
|
||
),
|
||
child: Text(
|
||
warning.status,
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
color: statusColor,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 12),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
'${AppLocalizations.of(context).translate('warning_center.alert_content')}:${warning.content}',
|
||
style: const TextStyle(
|
||
fontSize: 14,
|
||
color: Color(0xFF333333),
|
||
),
|
||
),
|
||
const SizedBox(height: 6),
|
||
Text(
|
||
'${AppLocalizations.of(context).translate('warning_center.alert_time')}:${warning.time}',
|
||
style: TextStyle(
|
||
fontSize: 13,
|
||
color: Colors.grey.shade600,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Column(
|
||
crossAxisAlignment: CrossAxisAlignment.end,
|
||
children: [
|
||
Text(
|
||
AppLocalizations.of(context).translate('warning_center.pending_status'),
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
color: Colors.grey.shade600,
|
||
),
|
||
),
|
||
const SizedBox(height: 4),
|
||
Text(
|
||
warning.status,
|
||
style: const TextStyle(
|
||
fontSize: 13,
|
||
fontWeight: FontWeight.bold,
|
||
color: Color(0xFF1A1A1A),
|
||
),
|
||
),
|
||
const SizedBox(height: 4),
|
||
Text(
|
||
AppLocalizations.of(context).translate('warning_center.responsible_person'),
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
color: Colors.grey.shade600,
|
||
),
|
||
),
|
||
const SizedBox(height: 4),
|
||
Text(
|
||
warning.responsiblePerson,
|
||
style: const TextStyle(
|
||
fontSize: 13,
|
||
fontWeight: FontWeight.bold,
|
||
color: Color(0xFF1A1A1A),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|