Commit 97313115 authored by 张宏's avatar 张宏

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