告警中心的二级详情页面+信息中心的页面+对接机器人接口

This commit is contained in:
2026-06-02 08:40:50 +08:00
parent 9eab402551
commit d8879dad62
48 changed files with 4376 additions and 0 deletions

View File

@@ -0,0 +1,414 @@
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/message_center/domain/entities/message_category_entity.dart';
import 'package:maibu_satabot_v2/features/v2/message_center/presentation/bloc/message_center_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/message_center/presentation/bloc/message_center_state.dart';
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/constants/alarm_constants.dart';
/// 消息中心页面
class MessageCenterPage extends StatelessWidget {
const MessageCenterPage({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => sl<MessageCenterCubit>()..loadMessageList(),
child: const MessageCenterView(),
);
}
}
class MessageCenterView extends StatelessWidget {
const MessageCenterView({super.key});
@override
Widget build(BuildContext context) {
final cubit = context.read<MessageCenterCubit>();
return Scaffold(
backgroundColor: AlarmColors.background,
body: BlocConsumer<MessageCenterCubit, MessageCenterState>(
listener: (context, state) {
if (state is MessageCenterActionInProgress) {
// 显示加载提示
}
if (state is MessageCenterError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(state.message)),
);
}
},
builder: (context, state) {
return SafeArea(
child: Column(
children: [
// 顶部导航栏
_buildAppBar(context, cubit),
// 内容区域
Expanded(
child: _buildContent(context, state),
),
],
),
);
},
),
);
}
Widget _buildAppBar(BuildContext context, MessageCenterCubit cubit) {
return Container(
height: 44.0,
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
// 左侧:下拉筛选菜单
_buildFilterDropdown(context, cubit),
const Spacer(),
// 右侧:一键已读按钮
GestureDetector(
onTap: () => cubit.markAllAsRead(),
child: const Text(
'一键已读',
style: TextStyle(
fontSize: 14,
color: AlarmColors.primary,
fontWeight: FontWeight.w500,
),
),
),
],
),
);
}
Widget _buildFilterDropdown(BuildContext context, MessageCenterCubit cubit) {
return BlocBuilder<MessageCenterCubit, MessageCenterState>(
builder: (context, state) {
MessageType selectedType = MessageType.all;
if (state is MessageCenterLoaded) {
selectedType = state.selectedType;
}
return DropdownButton<MessageType>(
value: selectedType,
underline: const SizedBox(),
icon: const Icon(
Icons.keyboard_arrow_down,
size: 20,
color: AlarmColors.textSecondary,
),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AlarmColors.textPrimary,
),
items: MessageType.values.map((type) {
return DropdownMenuItem<MessageType>(
value: type,
child: Text(type.label),
);
}).toList(),
onChanged: (value) {
if (value != null) {
cubit.changeFilter(value);
}
},
);
},
);
}
Widget _buildContent(BuildContext context, MessageCenterState state) {
if (state is MessageCenterLoading) {
return _buildSkeletonScreen();
}
if (state is MessageCenterError) {
return _buildErrorState(context, state.message);
}
if (state is MessageCenterLoaded) {
return _buildMessageList(context, state);
}
if (state is MessageCenterActionInProgress) {
return _buildLoadingOverlay(context, state.action);
}
return const SizedBox();
}
Widget _buildMessageList(BuildContext context, MessageCenterLoaded state) {
if (state.messageList.isEmpty) {
return Center(
child: Text(
'暂无消息',
style: const TextStyle(
fontSize: 14,
color: AlarmColors.textSecondary,
),
),
);
}
return ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
itemCount: state.messageList.length,
separatorBuilder: (context, index) => const SizedBox(height: 12),
itemBuilder: (context, index) {
final message = state.messageList[index];
return _MessageCategoryCard(
message: message,
onTap: () => _handleMessageTap(context, message),
);
},
);
}
void _handleMessageTap(BuildContext context, MessageCategoryEntity message) {
// 根据目标路由跳转
if (message.targetRoute != null) {
context.push(message.targetRoute!);
} else {
// 显示消息详情(可以后续扩展)
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('查看${message.title}详情')),
);
}
}
Widget _buildSkeletonScreen() {
return ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
itemCount: 6,
separatorBuilder: (context, index) => const SizedBox(height: 12),
itemBuilder: (context, index) {
return Container(
height: 80,
decoration: BoxDecoration(
color: AlarmColors.background,
borderRadius: BorderRadius.circular(AlarmDimensions.borderRadius),
),
child: const Center(
child: CircularProgressIndicator(),
),
);
},
);
}
Widget _buildErrorState(BuildContext context, String message) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.error_outline,
size: 64,
color: AlarmColors.danger,
),
const SizedBox(height: 16),
Text(
message,
style: const TextStyle(
fontSize: 14,
color: AlarmColors.textSecondary,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () {
context.read<MessageCenterCubit>().loadMessageList();
},
child: const Text('重试'),
),
],
),
);
}
Widget _buildLoadingOverlay(BuildContext context, String action) {
return Stack(
children: [
BlocBuilder<MessageCenterCubit, MessageCenterState>(
builder: (context, state) {
if (state is MessageCenterLoaded) {
return _buildMessageList(context, state);
}
return const SizedBox();
},
),
Container(
color: Colors.black.withOpacity(0.3),
child: Center(
child: Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const CircularProgressIndicator(),
const SizedBox(height: 16),
Text(
'$action中...',
style: const TextStyle(
fontSize: 14,
color: AlarmColors.textSecondary,
),
),
],
),
),
),
),
],
);
}
}
/// 消息分类卡片组件
class _MessageCategoryCard extends StatelessWidget {
const _MessageCategoryCard({
required this.message,
required this.onTap,
});
final MessageCategoryEntity message;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final isUnread = message.unreadCount > 0;
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AlarmColors.background,
borderRadius: BorderRadius.circular(AlarmDimensions.borderRadius),
),
child: Row(
children: [
// 左侧图标
_buildIcon(),
const SizedBox(width: 12),
// 中间内容
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题
Text(
message.title,
style: TextStyle(
fontSize: 15,
fontWeight: isUnread ? FontWeight.bold : FontWeight.w500,
color: AlarmColors.textPrimary,
),
),
const SizedBox(height: 4),
// 内容摘要
Text(
message.content,
style: const TextStyle(
fontSize: 13,
color: AlarmColors.textSecondary,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
const SizedBox(width: 12),
// 右侧信息
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
// 未读角标
if (isUnread) _buildUnreadBadge(),
// 时间
Text(
message.time,
style: const TextStyle(
fontSize: 12,
color: AlarmColors.textSecondary,
),
),
],
),
],
),
),
);
}
Widget _buildIcon() {
final iconColor = Color(
int.parse(message.iconColor.replaceAll('#', '0xFF')),
);
IconData iconData;
switch (message.icon) {
case 'notifications':
iconData = Icons.notifications;
break;
case 'assignment':
iconData = Icons.assignment;
break;
case 'campaign':
iconData = Icons.campaign;
break;
case 'chat':
iconData = Icons.chat_bubble;
break;
case 'description':
iconData = Icons.description;
break;
case 'security':
iconData = Icons.security;
break;
default:
iconData = Icons.notifications;
}
return Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: iconColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(
iconData,
color: iconColor,
size: 20,
),
);
}
Widget _buildUnreadBadge() {
return Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: AlarmColors.danger,
borderRadius: BorderRadius.circular(10),
),
child: Text(
message.unreadCount.toString(),
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
);
}
}