所有一级页面和不分二级页面
This commit is contained in:
@@ -0,0 +1,275 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_cubit.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';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/widgets/alarm_count_card.dart';
|
||||
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';
|
||||
|
||||
/// 告警中心页面
|
||||
class AlarmCenterPage extends StatefulWidget {
|
||||
const AlarmCenterPage({super.key});
|
||||
|
||||
@override
|
||||
State<AlarmCenterPage> createState() => _AlarmCenterPageState();
|
||||
}
|
||||
|
||||
class _AlarmCenterPageState extends State<AlarmCenterPage> {
|
||||
late AlarmCubit _cubit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cubit = context.read<AlarmCubit>();
|
||||
// 首次加载数据
|
||||
if (_cubit.state is AlarmInitial) {
|
||||
_cubit.loadAlarms();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: SystemUiOverlayStyle.dark.copyWith(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
),
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFFF5F7FA),
|
||||
body: SafeArea(
|
||||
child: BlocBuilder<AlarmCubit, AlarmState>(
|
||||
builder: (context, state) {
|
||||
if (state is AlarmLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AlarmError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: AlarmColors.textTertiary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(state.message),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () => _cubit.loadAlarms(),
|
||||
child: const Text('重试'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AlarmLoaded) {
|
||||
return Column(
|
||||
children: [
|
||||
// 顶部标题栏
|
||||
_buildAppBar(),
|
||||
// 横向标签栏
|
||||
_buildTabBar(state),
|
||||
// 内容区域
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _cubit.refresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: AlarmDimensions.moduleSpacing,
|
||||
bottom: 40,
|
||||
),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
//const SizedBox(height: AlarmDimensions.moduleSpacing),
|
||||
// 告警统计卡片
|
||||
AlarmCountCard(count: state.count),
|
||||
const SizedBox(height: AlarmDimensions.moduleSpacing),
|
||||
// 告警列表
|
||||
...state.alarms.map((alarm) {
|
||||
return AlarmItemCard(
|
||||
alarm: alarm,
|
||||
onTap: () {
|
||||
// TODO: 跳转到告警详情页
|
||||
debugPrint('点击告警: ${alarm.title}');
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
const SizedBox(height: AlarmDimensions.moduleSpacing),
|
||||
// AI 诊断建议(仅当有 AI 诊断内容时显示)
|
||||
if (state.alarms.any((alarm) => alarm.aiDiagnosis != null))
|
||||
AiDiagnosisCard(
|
||||
content: state.alarms
|
||||
.firstWhere((alarm) => alarm.aiDiagnosis != null)
|
||||
.aiDiagnosis ??
|
||||
'',
|
||||
onViewDetails: () {
|
||||
// TODO: 查看详情
|
||||
debugPrint('查看 AI 诊断详情');
|
||||
},
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示筛选弹窗
|
||||
void _showFilterDialog() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: Colors.white,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
builder: (context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'筛选条件',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildFilterOption('告警等级', ['高危', '中危', '低危', '提示']),
|
||||
const SizedBox(height: 16),
|
||||
_buildFilterOption('时间范围', ['今天', '本周', '本月', '全部']),
|
||||
const SizedBox(height: 16),
|
||||
_buildFilterOption('区域', ['A区', 'B区', 'C区', 'D区', '全部']),
|
||||
const SizedBox(height: 24),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AlarmColors.primary,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'应用筛选',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppBar() {
|
||||
return Container(
|
||||
height: 44.0,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text(
|
||||
'告警中心',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.filter_list,
|
||||
size: 24,
|
||||
color: Color(0xFF1D2129),
|
||||
),
|
||||
onPressed: _showFilterDialog,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabBar(AlarmLoaded state) {
|
||||
return AlarmTabBar(
|
||||
selectedFilter: state.selectedFilter,
|
||||
backgroundColor: const Color(0xFFF5F7FA),
|
||||
onFilterChanged: (filter) {
|
||||
_cubit.changeFilter(filter);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterOption(String title, List<String> options) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AlarmColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: options.map((option) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AlarmColors.textTertiary),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
option,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AlarmColors.textSecondary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user