告警中心的二级详情页面+信息中心的页面+对接机器人接口
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.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/domain/usecases/message_center_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/message_center/presentation/bloc/message_center_state.dart';
|
||||
|
||||
/// 消息中心Cubit
|
||||
class MessageCenterCubit extends Cubit<MessageCenterState> {
|
||||
MessageCenterCubit({
|
||||
required GetMessageListUseCase getMessageListUseCase,
|
||||
required MarkAllAsReadUseCase markAllAsReadUseCase,
|
||||
}) : _getMessageListUseCase = getMessageListUseCase,
|
||||
_markAllAsReadUseCase = markAllAsReadUseCase,
|
||||
super(MessageCenterInitial());
|
||||
|
||||
final GetMessageListUseCase _getMessageListUseCase;
|
||||
final MarkAllAsReadUseCase _markAllAsReadUseCase;
|
||||
|
||||
/// 加载消息列表
|
||||
Future<void> loadMessageList({MessageType? type}) async {
|
||||
emit(MessageCenterLoading());
|
||||
final result = await _getMessageListUseCase(type: type);
|
||||
result.fold(
|
||||
(failure) => emit(MessageCenterError(failure.message)),
|
||||
(messageList) {
|
||||
final totalUnread = messageList.fold<int>(
|
||||
0,
|
||||
(sum, msg) => sum + msg.unreadCount,
|
||||
);
|
||||
emit(MessageCenterLoaded(
|
||||
messageList: messageList,
|
||||
selectedType: type ?? MessageType.all,
|
||||
totalUnread: totalUnread,
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 切换消息类型筛选
|
||||
Future<void> changeFilter(MessageType type) async {
|
||||
await loadMessageList(type: type);
|
||||
}
|
||||
|
||||
/// 一键已读
|
||||
Future<void> markAllAsRead() async {
|
||||
// 检查当前状态
|
||||
if (state is! MessageCenterLoaded) return;
|
||||
|
||||
emit(const MessageCenterActionInProgress('一键已读'));
|
||||
final result = await _markAllAsReadUseCase();
|
||||
result.fold(
|
||||
(failure) => emit(MessageCenterError(failure.message)),
|
||||
(success) {
|
||||
if (success) {
|
||||
// 将所有消息的未读数清零
|
||||
final currentState = state as MessageCenterLoaded;
|
||||
final updatedList = currentState.messageList
|
||||
.map((msg) => msg.copyWith(unreadCount: 0))
|
||||
.toList();
|
||||
emit(currentState.copyWith(
|
||||
messageList: updatedList,
|
||||
totalUnread: 0,
|
||||
));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/message_center/domain/entities/message_category_entity.dart';
|
||||
|
||||
/// 消息中心状态
|
||||
sealed class MessageCenterState extends Equatable {
|
||||
const MessageCenterState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// 初始状态
|
||||
final class MessageCenterInitial extends MessageCenterState {}
|
||||
|
||||
/// 加载状态
|
||||
final class MessageCenterLoading extends MessageCenterState {}
|
||||
|
||||
/// 加载成功状态
|
||||
final class MessageCenterLoaded extends MessageCenterState {
|
||||
const MessageCenterLoaded({
|
||||
required this.messageList,
|
||||
this.selectedType = MessageType.all,
|
||||
this.totalUnread = 0,
|
||||
});
|
||||
|
||||
final List<MessageCategoryEntity> messageList;
|
||||
final MessageType selectedType;
|
||||
final int totalUnread;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [messageList, selectedType, totalUnread];
|
||||
|
||||
MessageCenterLoaded copyWith({
|
||||
List<MessageCategoryEntity>? messageList,
|
||||
MessageType? selectedType,
|
||||
int? totalUnread,
|
||||
}) {
|
||||
return MessageCenterLoaded(
|
||||
messageList: messageList ?? this.messageList,
|
||||
selectedType: selectedType ?? this.selectedType,
|
||||
totalUnread: totalUnread ?? this.totalUnread,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 加载失败状态
|
||||
final class MessageCenterError extends MessageCenterState {
|
||||
const MessageCenterError(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
/// 操作中状态(一键已读)
|
||||
final class MessageCenterActionInProgress extends MessageCenterState {
|
||||
const MessageCenterActionInProgress(this.action);
|
||||
|
||||
final String action;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [action];
|
||||
}
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user