12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import 'dart:collection';
- import 'package:get/get.dart';
- import 'package:vnoteapp/architecture/defines.dart';
- /// 分页状态Mixin
- mixin PagedStateMixin<T> {
- final RxString _searchString = RxString("");
- final RxInt _pageIndex = RxInt(0);
- final RxInt _pageSize = RxInt(20);
- final RxInt _totalCount = RxInt(0);
- final RxList<T> _dataList = RxList<T>();
- /// 模糊搜索字符串
- String get searchString => _searchString.value;
- set searchString(String val) => _searchString.updateValue(val);
- /// 当前页索引
- int get pageIndex => _pageIndex.value;
- set pageIndex(int val) => _pageIndex.updateValue(val);
- /// 每页数量
- int get pageSize => _pageSize.value;
- set pageSize(int val) => _pageSize.updateValue(val);
- /// 总数据量
- int get totalCount => _totalCount.value;
- set totalCount(int val) => _totalCount.updateValue(val);
- /// 是否存在下一页
- bool get hasNextPage => _totalCount > pageIndex * pageSize;
- /// 列表数据集合
- List<T> get dataList => UnmodifiableListView(_dataList.toList());
- set dataList(List<T> val) => _dataList.value = val;
- /// 追加数据集合
- void appendDataList(List<T> arr) {
- List<T> newArray = List<T>.from(_dataList);
- newArray.addAll(arr);
- _dataList.value = newArray;
- }
- }
|