Commit 13eec49e authored by 张宏's avatar 张宏

3

parent 1a461d59
......@@ -4,13 +4,22 @@ import '../models/bo/alert_list_bo.dart';
class AlertListRepository {
/// 获取告警列表
/// [alertStatus] 告警状态码:0=待处理 2=已处理 3=误报,不传则查询全部
Future<ResponseModel<AlertListBO>> getList({
required int pageSize,
required int pageNum,
String? alertStatus,
}) {
final params = <String, dynamic>{
'pageSize': pageSize,
'pageNum': pageNum,
};
if (alertStatus != null) {
params['alertStatus'] = alertStatus;
}
return DioRequest.instance.get<AlertListBO>(
'/app/alert/list',
queryParameters: {'pageSize': pageSize, 'pageNum': pageNum},
queryParameters: params,
fromJsonT: (data) =>
AlertListBO.fromJson(data as Map<String, dynamic>),
);
......
......@@ -7,10 +7,15 @@ class AlertListService {
AlertListService({required AlertListRepository repository})
: _repository = repository;
Future<AlertListBO> getList({required int pageSize, required int pageNum}) async {
Future<AlertListBO> getList({
required int pageSize,
required int pageNum,
String? alertStatus,
}) async {
final result = await _repository.getList(
pageSize: pageSize,
pageNum: pageNum,
alertStatus: alertStatus,
);
if (result.success && result.data != null) {
return result.data!;
......
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:smart_hotel_app/repositories/alert_list_repository.dart';
import 'package:smart_hotel_app/routes/app_router.gr.dart';
import 'package:smart_hotel_app/services/alert_list_service.dart';
import 'package:smart_hotel_app/views/home/abnormal_list/cubit/abnormal_list_state.dart';
/// AlarmStatus → 告警状态码(API 入参)
String? alarmStatusToApi(AlarmStatus filter) {
switch (filter) {
case AlarmStatus.all:
return null;
case AlarmStatus.pending:
return '0';
case AlarmStatus.processed:
return '2';
case AlarmStatus.falseAlarm:
return '3';
}
}
class AbnormalListCubit extends Cubit<AbnormalListState> {
final AlertListService _service;
static const int _pageSize = 20;
static const int pageSize = 20;
PagingController<int, AlarmItem>? _pagingController;
AbnormalListCubit()
: _service = AlertListService(
......@@ -17,16 +34,28 @@ class AbnormalListCubit extends Cubit<AbnormalListState> {
),
super(const AbnormalListState());
/// 绑定 PagingController(View initState 中调用)
void bindPagingController(PagingController<int, AlarmItem> controller) {
_pagingController = controller;
}
/// 解绑 PagingController(View dispose 中调用)
void unbindPagingController() {
_pagingController = null;
}
/// 供 PagingController.fetchPage 回调使用,每次加载新的一页
Future<List<AlarmItem>> fetchPage(int pageKey) async {
final alertList = await _service.getList(
pageSize: _pageSize,
pageSize: pageSize,
pageNum: pageKey,
alertStatus: alarmStatusToApi(state.currentFilter),
);
// 首頁時更新 tab 统计
// 首页时更新 tab 统计数和总
if (pageKey == 1) {
emit(state.copyWith(
totalCount: alertList.total,
allCount: alertList.tabCount.all,
pendingCount: alertList.tabCount.pending,
processedCount: alertList.tabCount.processed,
......@@ -39,12 +68,15 @@ class AbnormalListCubit extends Cubit<AbnormalListState> {
.toList();
}
/// 切换筛选 Tab,触发重新请求
void setFilter(AlarmStatus filter) {
if (state.currentFilter == filter) return;
emit(state.copyWith(currentFilter: filter));
_pagingController?.refresh();
}
void onAlarmItemTap(AlarmItem item, BuildContext context) {
final alertId = int.tryParse(item.id) ?? 0;
context.pushRoute(AbnormalDetailRoute(alertId: alertId));
}
}
\ No newline at end of file
}
......@@ -61,6 +61,7 @@ class AbnormalListState extends Equatable {
final bool isLoading;
final String? error;
final AlarmStatus currentFilter;
final int totalCount;
final int allCount;
final int pendingCount;
final int processedCount;
......@@ -70,6 +71,7 @@ class AbnormalListState extends Equatable {
this.isLoading = false,
this.error,
this.currentFilter = AlarmStatus.all,
this.totalCount = 0,
this.allCount = 0,
this.pendingCount = 0,
this.processedCount = 0,
......@@ -80,15 +82,18 @@ class AbnormalListState extends Equatable {
bool? isLoading,
String? error,
AlarmStatus? currentFilter,
int? totalCount,
int? allCount,
int? pendingCount,
int? processedCount,
int? falseAlarmCount,
bool clearError = false,
}) {
return AbnormalListState(
isLoading: isLoading ?? this.isLoading,
error: error,
error: clearError ? null : (error ?? this.error),
currentFilter: currentFilter ?? this.currentFilter,
totalCount: totalCount ?? this.totalCount,
allCount: allCount ?? this.allCount,
pendingCount: pendingCount ?? this.pendingCount,
processedCount: processedCount ?? this.processedCount,
......@@ -101,6 +106,7 @@ class AbnormalListState extends Equatable {
isLoading,
error,
currentFilter,
totalCount,
allCount,
pendingCount,
processedCount,
......
......@@ -30,23 +30,32 @@ class _AbnormalListBody extends StatefulWidget {
class _AbnormalListBodyState extends State<_AbnormalListBody> {
late final PagingController<int, AlarmItem> _pagingController;
late final AbnormalListCubit _cubit;
@override
void initState() {
super.initState();
_cubit = context.read<AbnormalListCubit>();
_pagingController = PagingController<int, AlarmItem>(
getNextPageKey: (state) {
if (state.keys == null || state.keys!.isEmpty) return 1;
return state.lastPageIsEmpty ? null : state.nextIntPageKey;
final total = _cubit.state.totalCount;
final nextKey = state.nextIntPageKey;
if (nextKey == null) return null;
if ((nextKey - 1) * AbnormalListCubit.pageSize >= total) {
return null;
}
return nextKey;
},
fetchPage: (pageKey) =>
context.read<AbnormalListCubit>().fetchPage(pageKey),
fetchPage: (pageKey) => _cubit.fetchPage(pageKey),
);
_cubit.bindPagingController(_pagingController);
}
@override
void dispose() {
_pagingController.dispose();
_cubit.unbindPagingController();
super.dispose();
}
......
# 智慧酒店 App 接口对接方案
# 智慧酒店 App 接口对接方案
......@@ -232,8 +232,8 @@ class xxxBO extends Equatable {
| 全部设备 |GET | /app/device/list | 已对接 | 全部设备 | |
| 联动规则管理 |GET | /app/linkage/rules | 对接 | 联动规则管理 | |
| 联动规则管理-启用/禁用 |PUT | /app/linkage/rules/toggle | 对接 | 联动规则管理-启用/禁用 | |
| 联动规则管理 |GET | /app/linkage/rules | 对接 | 联动规则管理 | |
| 联动规则管理-启用/禁用 |PUT | /app/linkage/rules/toggle | 对接 | 联动规则管理-启用/禁用 | |
......
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