fix: 评论重复加载

This commit is contained in:
guozhigq
2024-11-01 09:17:57 +08:00
parent dd1bc66c57
commit 4fd49befbb
4 changed files with 30 additions and 23 deletions

View File

@ -26,6 +26,7 @@ class DynamicDetailController extends GetxController {
RxString sortTypeLabel = ReplySortType.time.labels.obs; RxString sortTypeLabel = ReplySortType.time.labels.obs;
Box setting = GStrorage.setting; Box setting = GStrorage.setting;
RxInt replyReqCode = 200.obs; RxInt replyReqCode = 200.obs;
bool isEnd = false;
@override @override
void onInit() { void onInit() {
@ -48,7 +49,7 @@ class DynamicDetailController extends GetxController {
} }
Future queryReplyList({reqType = 'init'}) async { Future queryReplyList({reqType = 'init'}) async {
if (isLoadingMore) { if (isLoadingMore || noMore.value == '没有更多了' || isEnd) {
return; return;
} }
isLoadingMore = true; isLoadingMore = true;
@ -56,10 +57,6 @@ class DynamicDetailController extends GetxController {
nextOffset = ''; nextOffset = '';
noMore.value = ''; noMore.value = '';
} }
if (noMore.value == '没有更多了') {
isLoadingMore = false;
return;
}
var res = await ReplyHttp.replyList( var res = await ReplyHttp.replyList(
oid: oid!, oid: oid!,
nextOffset: nextOffset, nextOffset: nextOffset,
@ -68,15 +65,14 @@ class DynamicDetailController extends GetxController {
); );
if (res['status']) { if (res['status']) {
List<ReplyItemModel> replies = res['data'].replies; List<ReplyItemModel> replies = res['data'].replies;
isEnd = res['data'].cursor.isEnd ?? false;
acount.value = res['data'].cursor.allCount; acount.value = res['data'].cursor.allCount;
nextOffset = res['data'].cursor.paginationReply.nextOffset ?? ""; nextOffset = res['data'].cursor.paginationReply.nextOffset ?? "";
if (replies.isNotEmpty) { if (replies.isNotEmpty) {
noMore.value = '加载中...'; noMore.value = isEnd ? '没有更多了' : '加载中...';
if (res['data'].cursor.isEnd == true) {
noMore.value = '没有更多了';
}
} else { } else {
noMore.value = nextOffset == "" ? '还没有评论' : '没有更多了'; noMore.value =
replyList.isEmpty && nextOffset == "" ? '还没有评论' : '没有更多了';
} }
if (reqType == 'init') { if (reqType == 'init') {
// 添加置顶回复 // 添加置顶回复
@ -122,4 +118,9 @@ class DynamicDetailController extends GetxController {
var res = await HtmlHttp.reqHtml(id, 'opus'); var res = await HtmlHttp.reqHtml(id, 'opus');
oid = res['commentId']; oid = res['commentId'];
} }
// 上拉加载
Future onLoad() async {
queryReplyList(reqType: 'onLoad');
}
} }

View File

@ -140,7 +140,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
if (scrollController.position.pixels >= if (scrollController.position.pixels >=
scrollController.position.maxScrollExtent - 300) { scrollController.position.maxScrollExtent - 300) {
EasyThrottle.throttle('replylist', const Duration(seconds: 2), () { EasyThrottle.throttle('replylist', const Duration(seconds: 2), () {
_dynamicDetailController.queryReplyList(reqType: 'onLoad'); _dynamicDetailController.onLoad();
}); });
} }

View File

@ -34,6 +34,7 @@ class VideoReplyController extends GetxController {
Box setting = GStrorage.setting; Box setting = GStrorage.setting;
RxInt replyReqCode = 200.obs; RxInt replyReqCode = 200.obs;
bool isEnd = false;
@override @override
void onInit() { void onInit() {
@ -49,8 +50,8 @@ class VideoReplyController extends GetxController {
sortTypeLabel.value = _sortType.labels; sortTypeLabel.value = _sortType.labels;
} }
Future queryReplyList({type = 'init'}) async { Future<dynamic> queryReplyList({type = 'init'}) async {
if (isLoadingMore) { if (isLoadingMore || noMore.value == '没有更多了' || isEnd) {
return; return;
} }
isLoadingMore = true; isLoadingMore = true;
@ -58,10 +59,6 @@ class VideoReplyController extends GetxController {
nextOffset = ''; nextOffset = '';
noMore.value = ''; noMore.value = '';
} }
if (noMore.value == '没有更多了') {
isLoadingMore = false;
return;
}
final res = await ReplyHttp.replyList( final res = await ReplyHttp.replyList(
oid: aid!, oid: aid!,
nextOffset: nextOffset, nextOffset: nextOffset,
@ -70,14 +67,13 @@ class VideoReplyController extends GetxController {
); );
if (res['status']) { if (res['status']) {
final List<ReplyItemModel> replies = res['data'].replies; final List<ReplyItemModel> replies = res['data'].replies;
isEnd = res['data'].cursor.isEnd ?? false;
nextOffset = res['data'].cursor.paginationReply.nextOffset ?? ""; nextOffset = res['data'].cursor.paginationReply.nextOffset ?? "";
if (replies.isNotEmpty) { if (replies.isNotEmpty) {
noMore.value = '加载中...'; noMore.value = isEnd ? '没有更多了' : '加载中...';
if (res['data'].cursor.isEnd == true) {
noMore.value = '没有更多了';
}
} else { } else {
noMore.value = nextOffset == "" ? '还没有评论' : '没有更多了'; noMore.value =
replyList.isEmpty && nextOffset == "" ? '还没有评论' : '没有更多了';
} }
if (type == 'init') { if (type == 'init') {
// 添加置顶回复 // 添加置顶回复
@ -105,6 +101,14 @@ class VideoReplyController extends GetxController {
queryReplyList(type: 'onLoad'); queryReplyList(type: 'onLoad');
} }
// 下拉刷新
Future onRefresh() async {
nextOffset = "";
noMore.value = '';
isEnd = false;
queryReplyList(type: 'init');
}
// 排序搜索评论 // 排序搜索评论
queryBySort() { queryBySort() {
EasyThrottle.throttle('queryBySort', const Duration(seconds: 1), () { EasyThrottle.throttle('queryBySort', const Duration(seconds: 1), () {
@ -118,6 +122,8 @@ class VideoReplyController extends GetxController {
break; break;
default: default:
} }
isLoadingMore = false;
isEnd = false;
sortTypeTitle.value = _sortType.titles; sortTypeTitle.value = _sortType.titles;
sortTypeLabel.value = _sortType.labels; sortTypeLabel.value = _sortType.labels;
nextOffset = ""; nextOffset = "";

View File

@ -137,7 +137,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
super.build(context); super.build(context);
return RefreshIndicator( return RefreshIndicator(
onRefresh: () async { onRefresh: () async {
return await _videoReplyController.queryReplyList(type: 'init'); return await _videoReplyController.onRefresh();
}, },
child: Stack( child: Stack(
children: [ children: [