From 4fd49befbb11ef0cb04ad73dd23415b202dd70b1 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Fri, 1 Nov 2024 09:17:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=84=E8=AE=BA=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/dynamics/detail/controller.dart | 21 ++++++++------- lib/pages/dynamics/detail/view.dart | 2 +- lib/pages/video/detail/reply/controller.dart | 28 ++++++++++++-------- lib/pages/video/detail/reply/view.dart | 2 +- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/pages/dynamics/detail/controller.dart b/lib/pages/dynamics/detail/controller.dart index 7ca55c59..e7c179f3 100644 --- a/lib/pages/dynamics/detail/controller.dart +++ b/lib/pages/dynamics/detail/controller.dart @@ -26,6 +26,7 @@ class DynamicDetailController extends GetxController { RxString sortTypeLabel = ReplySortType.time.labels.obs; Box setting = GStrorage.setting; RxInt replyReqCode = 200.obs; + bool isEnd = false; @override void onInit() { @@ -48,7 +49,7 @@ class DynamicDetailController extends GetxController { } Future queryReplyList({reqType = 'init'}) async { - if (isLoadingMore) { + if (isLoadingMore || noMore.value == '没有更多了' || isEnd) { return; } isLoadingMore = true; @@ -56,10 +57,6 @@ class DynamicDetailController extends GetxController { nextOffset = ''; noMore.value = ''; } - if (noMore.value == '没有更多了') { - isLoadingMore = false; - return; - } var res = await ReplyHttp.replyList( oid: oid!, nextOffset: nextOffset, @@ -68,15 +65,14 @@ class DynamicDetailController extends GetxController { ); if (res['status']) { List replies = res['data'].replies; + isEnd = res['data'].cursor.isEnd ?? false; acount.value = res['data'].cursor.allCount; nextOffset = res['data'].cursor.paginationReply.nextOffset ?? ""; if (replies.isNotEmpty) { - noMore.value = '加载中...'; - if (res['data'].cursor.isEnd == true) { - noMore.value = '没有更多了'; - } + noMore.value = isEnd ? '没有更多了' : '加载中...'; } else { - noMore.value = nextOffset == "" ? '还没有评论' : '没有更多了'; + noMore.value = + replyList.isEmpty && nextOffset == "" ? '还没有评论' : '没有更多了'; } if (reqType == 'init') { // 添加置顶回复 @@ -122,4 +118,9 @@ class DynamicDetailController extends GetxController { var res = await HtmlHttp.reqHtml(id, 'opus'); oid = res['commentId']; } + + // 上拉加载 + Future onLoad() async { + queryReplyList(reqType: 'onLoad'); + } } diff --git a/lib/pages/dynamics/detail/view.dart b/lib/pages/dynamics/detail/view.dart index 395f89b8..e80befec 100644 --- a/lib/pages/dynamics/detail/view.dart +++ b/lib/pages/dynamics/detail/view.dart @@ -140,7 +140,7 @@ class _DynamicDetailPageState extends State if (scrollController.position.pixels >= scrollController.position.maxScrollExtent - 300) { EasyThrottle.throttle('replylist', const Duration(seconds: 2), () { - _dynamicDetailController.queryReplyList(reqType: 'onLoad'); + _dynamicDetailController.onLoad(); }); } diff --git a/lib/pages/video/detail/reply/controller.dart b/lib/pages/video/detail/reply/controller.dart index bb1d6a97..a5797c7b 100644 --- a/lib/pages/video/detail/reply/controller.dart +++ b/lib/pages/video/detail/reply/controller.dart @@ -34,6 +34,7 @@ class VideoReplyController extends GetxController { Box setting = GStrorage.setting; RxInt replyReqCode = 200.obs; + bool isEnd = false; @override void onInit() { @@ -49,8 +50,8 @@ class VideoReplyController extends GetxController { sortTypeLabel.value = _sortType.labels; } - Future queryReplyList({type = 'init'}) async { - if (isLoadingMore) { + Future queryReplyList({type = 'init'}) async { + if (isLoadingMore || noMore.value == '没有更多了' || isEnd) { return; } isLoadingMore = true; @@ -58,10 +59,6 @@ class VideoReplyController extends GetxController { nextOffset = ''; noMore.value = ''; } - if (noMore.value == '没有更多了') { - isLoadingMore = false; - return; - } final res = await ReplyHttp.replyList( oid: aid!, nextOffset: nextOffset, @@ -70,14 +67,13 @@ class VideoReplyController extends GetxController { ); if (res['status']) { final List replies = res['data'].replies; + isEnd = res['data'].cursor.isEnd ?? false; nextOffset = res['data'].cursor.paginationReply.nextOffset ?? ""; if (replies.isNotEmpty) { - noMore.value = '加载中...'; - if (res['data'].cursor.isEnd == true) { - noMore.value = '没有更多了'; - } + noMore.value = isEnd ? '没有更多了' : '加载中...'; } else { - noMore.value = nextOffset == "" ? '还没有评论' : '没有更多了'; + noMore.value = + replyList.isEmpty && nextOffset == "" ? '还没有评论' : '没有更多了'; } if (type == 'init') { // 添加置顶回复 @@ -105,6 +101,14 @@ class VideoReplyController extends GetxController { queryReplyList(type: 'onLoad'); } + // 下拉刷新 + Future onRefresh() async { + nextOffset = ""; + noMore.value = ''; + isEnd = false; + queryReplyList(type: 'init'); + } + // 排序搜索评论 queryBySort() { EasyThrottle.throttle('queryBySort', const Duration(seconds: 1), () { @@ -118,6 +122,8 @@ class VideoReplyController extends GetxController { break; default: } + isLoadingMore = false; + isEnd = false; sortTypeTitle.value = _sortType.titles; sortTypeLabel.value = _sortType.labels; nextOffset = ""; diff --git a/lib/pages/video/detail/reply/view.dart b/lib/pages/video/detail/reply/view.dart index 5d9b7dab..54372c5e 100644 --- a/lib/pages/video/detail/reply/view.dart +++ b/lib/pages/video/detail/reply/view.dart @@ -137,7 +137,7 @@ class _VideoReplyPanelState extends State super.build(context); return RefreshIndicator( onRefresh: () async { - return await _videoReplyController.queryReplyList(type: 'init'); + return await _videoReplyController.onRefresh(); }, child: Stack( children: [