mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: query data (#659)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
import 'package:PiliPlus/common/widgets/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/user/black.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/pages/blacklist/controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/http/black.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
|
||||
@@ -50,36 +45,37 @@ class _BlackListPageState extends State<BlackListPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
Widget _buildBody(LoadingState<List<BlackListItem>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => loadingWidget,
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? ListView.builder(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: _blackListController.scrollController,
|
||||
itemCount: loadingState.response.length,
|
||||
itemCount: loadingState.response!.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_blackListController.onLoadMore();
|
||||
}
|
||||
final item = loadingState.response![index];
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
'/member?mid=${loadingState.response[index].mid}');
|
||||
Get.toNamed('/member?mid=${item.mid}');
|
||||
},
|
||||
leading: NetworkImgLayer(
|
||||
width: 45,
|
||||
height: 45,
|
||||
type: 'avatar',
|
||||
src: loadingState.response[index].face,
|
||||
src: item.face,
|
||||
),
|
||||
title: Text(
|
||||
loadingState.response[index].uname!,
|
||||
item.uname!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
subtitle: Text(
|
||||
Utils.dateFormat(loadingState.response[index].mtime),
|
||||
Utils.dateFormat(item.mtime),
|
||||
maxLines: 1,
|
||||
style:
|
||||
TextStyle(color: Theme.of(context).colorScheme.outline),
|
||||
@@ -87,10 +83,11 @@ class _BlackListPageState extends State<BlackListPage> {
|
||||
),
|
||||
dense: true,
|
||||
trailing: TextButton(
|
||||
onPressed: () => _blackListController.removeBlack(
|
||||
onPressed: () => _blackListController.onRemove(
|
||||
context,
|
||||
loadingState.response[index].uname,
|
||||
loadingState.response[index].mid,
|
||||
index,
|
||||
item.uname,
|
||||
item.mid,
|
||||
),
|
||||
child: const Text('移除'),
|
||||
),
|
||||
@@ -108,56 +105,3 @@ class _BlackListPageState extends State<BlackListPage> {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class BlackListController extends CommonController {
|
||||
int pageSize = 50;
|
||||
RxInt total = 0.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
total.value = response.response.total;
|
||||
if ((response.response.list as List?).isNullOrEmpty) {
|
||||
isEnd = true;
|
||||
}
|
||||
if (currentPage != 1 && loadingState.value is Success) {
|
||||
response.response.list ??= <BlackListItem>[];
|
||||
response.response.list!
|
||||
.insertAll(0, (loadingState.value as Success).response);
|
||||
}
|
||||
if (isEnd.not && response.response.list.length >= total.value) {
|
||||
isEnd = true;
|
||||
}
|
||||
loadingState.value = LoadingState.success(response.response.list.isNotEmpty
|
||||
? response.response.list
|
||||
: <BlackListItem>[]);
|
||||
return true;
|
||||
}
|
||||
|
||||
Future removeBlack(context, name, mid) async {
|
||||
showConfirmDialog(
|
||||
context: context,
|
||||
title: '确定将 $name 移出黑名单?',
|
||||
onConfirm: () async {
|
||||
var result = await VideoHttp.relationMod(mid: mid, act: 6, reSrc: 11);
|
||||
if (result['status']) {
|
||||
List list = (loadingState.value as Success).response;
|
||||
list.removeWhere((e) => e.mid == mid);
|
||||
total.value = total.value - 1;
|
||||
loadingState.value =
|
||||
LoadingState.success(list.isNotEmpty ? list : <BlackListItem>[]);
|
||||
SmartDialog.showToast('操作成功');
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
BlackHttp.blackList(pn: currentPage, ps: pageSize);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user