Commit 97313115 authored by 张宏's avatar 张宏

parent e4085511
...@@ -4,9 +4,13 @@ import '../models/bo/alert_list_bo.dart'; ...@@ -4,9 +4,13 @@ import '../models/bo/alert_list_bo.dart';
class AlertListRepository { class AlertListRepository {
/// 获取告警列表 /// 获取告警列表
Future<ResponseModel<AlertListBO>> getList() { Future<ResponseModel<AlertListBO>> getList({
required int pageSize,
required int pageNum,
}) {
return DioRequest.instance.get<AlertListBO>( return DioRequest.instance.get<AlertListBO>(
'/app/alert/list', '/app/alert/list',
queryParameters: {'pageSize': pageSize, 'pageNum': pageNum},
fromJsonT: (data) => fromJsonT: (data) =>
AlertListBO.fromJson(data as Map<String, dynamic>), AlertListBO.fromJson(data as Map<String, dynamic>),
); );
......
...@@ -7,8 +7,11 @@ class AlertListService { ...@@ -7,8 +7,11 @@ class AlertListService {
AlertListService({required AlertListRepository repository}) AlertListService({required AlertListRepository repository})
: _repository = repository; : _repository = repository;
Future<AlertListBO> getList() async { Future<AlertListBO> getList({required int pageSize, required int pageNum}) async {
final result = await _repository.getList(); final result = await _repository.getList(
pageSize: pageSize,
pageNum: pageNum,
);
if (result.success && result.data != null) { if (result.success && result.data != null) {
return result.data!; return result.data!;
} }
......
...@@ -9,29 +9,34 @@ import 'package:smart_hotel_app/views/home/abnormal_list/cubit/abnormal_list_sta ...@@ -9,29 +9,34 @@ import 'package:smart_hotel_app/views/home/abnormal_list/cubit/abnormal_list_sta
class AbnormalListCubit extends Cubit<AbnormalListState> { class AbnormalListCubit extends Cubit<AbnormalListState> {
final AlertListService _service; final AlertListService _service;
static const int _pageSize = 20;
AbnormalListCubit() AbnormalListCubit()
: _service = AlertListService( : _service = AlertListService(
repository: AlertListRepository(), repository: AlertListRepository(),
), ),
super(const AbnormalListState()) { super(const AbnormalListState());
loadList();
}
Future<void> loadList() async { /// 供 PagingController.fetchPage 回调使用,每次加载新的一页
emit(const AbnormalListState(isLoading: true)); Future<List<AlarmItem>> fetchPage(int pageKey) async {
try { final alertList = await _service.getList(
final alertList = await _service.getList(); pageSize: _pageSize,
emit(AbnormalListState( pageNum: pageKey,
alarmList: );
alertList.rows.map((e) => AlarmItem.fromAlertListItemBO(e)).toList(),
// 首頁時更新 tab 统计数
if (pageKey == 1) {
emit(state.copyWith(
allCount: alertList.tabCount.all, allCount: alertList.tabCount.all,
pendingCount: alertList.tabCount.pending, pendingCount: alertList.tabCount.pending,
processedCount: alertList.tabCount.processed, processedCount: alertList.tabCount.processed,
falseAlarmCount: alertList.tabCount.falseAlarm, falseAlarmCount: alertList.tabCount.falseAlarm,
)); ));
} catch (e) {
emit(AbnormalListState(error: e.toString()));
} }
return alertList.rows
.map((e) => AlarmItem.fromAlertListItemBO(e))
.toList();
} }
void setFilter(AlarmStatus filter) { void setFilter(AlarmStatus filter) {
......
...@@ -61,7 +61,6 @@ class AbnormalListState extends Equatable { ...@@ -61,7 +61,6 @@ class AbnormalListState extends Equatable {
final bool isLoading; final bool isLoading;
final String? error; final String? error;
final AlarmStatus currentFilter; final AlarmStatus currentFilter;
final List<AlarmItem> alarmList;
final int allCount; final int allCount;
final int pendingCount; final int pendingCount;
final int processedCount; final int processedCount;
...@@ -71,7 +70,6 @@ class AbnormalListState extends Equatable { ...@@ -71,7 +70,6 @@ class AbnormalListState extends Equatable {
this.isLoading = false, this.isLoading = false,
this.error, this.error,
this.currentFilter = AlarmStatus.all, this.currentFilter = AlarmStatus.all,
this.alarmList = const [],
this.allCount = 0, this.allCount = 0,
this.pendingCount = 0, this.pendingCount = 0,
this.processedCount = 0, this.processedCount = 0,
...@@ -82,7 +80,6 @@ class AbnormalListState extends Equatable { ...@@ -82,7 +80,6 @@ class AbnormalListState extends Equatable {
bool? isLoading, bool? isLoading,
String? error, String? error,
AlarmStatus? currentFilter, AlarmStatus? currentFilter,
List<AlarmItem>? alarmList,
int? allCount, int? allCount,
int? pendingCount, int? pendingCount,
int? processedCount, int? processedCount,
...@@ -92,7 +89,6 @@ class AbnormalListState extends Equatable { ...@@ -92,7 +89,6 @@ class AbnormalListState extends Equatable {
isLoading: isLoading ?? this.isLoading, isLoading: isLoading ?? this.isLoading,
error: error, error: error,
currentFilter: currentFilter ?? this.currentFilter, currentFilter: currentFilter ?? this.currentFilter,
alarmList: alarmList ?? this.alarmList,
allCount: allCount ?? this.allCount, allCount: allCount ?? this.allCount,
pendingCount: pendingCount ?? this.pendingCount, pendingCount: pendingCount ?? this.pendingCount,
processedCount: processedCount ?? this.processedCount, processedCount: processedCount ?? this.processedCount,
...@@ -100,19 +96,11 @@ class AbnormalListState extends Equatable { ...@@ -100,19 +96,11 @@ class AbnormalListState extends Equatable {
); );
} }
List<AlarmItem> get filteredList {
if (currentFilter == AlarmStatus.all) {
return alarmList;
}
return alarmList.where((item) => item.status == currentFilter).toList();
}
@override @override
List<Object?> get props => [ List<Object?> get props => [
isLoading, isLoading,
error, error,
currentFilter, currentFilter,
alarmList,
allCount, allCount,
pendingCount, pendingCount,
processedCount, processedCount,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment