paged_state_mixin.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import 'dart:collection';
  2. import 'package:get/get.dart';
  3. import 'package:vnoteapp/architecture/defines.dart';
  4. /// 分页状态Mixin
  5. mixin PagedStateMixin<T> {
  6. final RxString _searchString = RxString("");
  7. final RxInt _pageIndex = RxInt(0);
  8. final RxInt _pageSize = RxInt(20);
  9. final RxInt _totalCount = RxInt(0);
  10. final RxList<T> _dataList = RxList<T>();
  11. /// 模糊搜索字符串
  12. String get searchString => _searchString.value;
  13. set searchString(String val) => _searchString.updateValue(val);
  14. /// 当前页索引
  15. int get pageIndex => _pageIndex.value;
  16. set pageIndex(int val) => _pageIndex.updateValue(val);
  17. /// 每页数量
  18. int get pageSize => _pageSize.value;
  19. set pageSize(int val) => _pageSize.updateValue(val);
  20. /// 总数据量
  21. int get totalCount => _totalCount.value;
  22. set totalCount(int val) => _totalCount.updateValue(val);
  23. /// 是否存在下一页
  24. bool get hasNextPage => _totalCount > pageIndex * pageSize;
  25. /// 列表数据集合
  26. List<T> get dataList => UnmodifiableListView(_dataList.toList());
  27. set dataList(List<T> val) => _dataList.value = val;
  28. /// 追加数据集合
  29. void appendDataList(List<T> arr) {
  30. List<T> newArray = List<T>.from(_dataList);
  31. newArray.addAll(arr);
  32. _dataList.value = newArray;
  33. }
  34. }