mod: reply api

This commit is contained in:
guozhigq
2024-10-17 23:24:45 +08:00
parent 163b8a3013
commit b60e693e2e
6 changed files with 123 additions and 46 deletions

View File

@ -14,7 +14,7 @@ class DynamicDetailController extends GetxController {
int? type;
dynamic item;
int? floor;
int currentPage = 0;
String nextOffset = "";
bool isLoadingMore = false;
RxString noMore = ''.obs;
RxList<ReplyItemModel> replyList = <ReplyItemModel>[].obs;
@ -49,25 +49,25 @@ class DynamicDetailController extends GetxController {
Future queryReplyList({reqType = 'init'}) async {
if (reqType == 'init') {
currentPage = 0;
nextOffset = "";
}
var res = await ReplyHttp.replyList(
oid: oid!,
pageNum: currentPage + 1,
nextOffset: nextOffset,
type: type!,
sort: _sortType.index,
);
if (res['status']) {
List<ReplyItemModel> replies = res['data'].replies;
acount.value = res['data'].page.acount;
acount.value = res['data'].cursor.allCount;
nextOffset = res['data'].cursor.paginationReply.nextOffset ?? "";
if (replies.isNotEmpty) {
currentPage++;
noMore.value = '加载中...';
if (replies.length < 20) {
if (res['data'].cursor.isEnd == true) {
noMore.value = '没有更多了';
}
} else {
noMore.value = currentPage == 0 ? '还没有评论' : '没有更多了';
noMore.value = nextOffset == "" ? '还没有评论' : '没有更多了';
}
if (reqType == 'init') {
// 添加置顶回复

View File

@ -15,7 +15,7 @@ class HtmlRenderController extends GetxController {
RxInt oid = (-1).obs;
late Map response;
int? floor;
int currentPage = 0;
String nextOffset = "";
bool isLoadingMore = false;
RxString noMore = ''.obs;
RxList<ReplyItemModel> replyList = <ReplyItemModel>[].obs;
@ -52,21 +52,21 @@ class HtmlRenderController extends GetxController {
Future queryReplyList({reqType = 'init'}) async {
var res = await ReplyHttp.replyList(
oid: oid.value,
pageNum: currentPage + 1,
nextOffset: nextOffset,
type: type,
sort: _sortType.index,
);
if (res['status']) {
List<ReplyItemModel> replies = res['data'].replies;
acount.value = res['data'].page.acount;
acount.value = res['data'].cursor.allCount;
nextOffset = res['data'].cursor.paginationReply.nextOffset ?? "";
if (replies.isNotEmpty) {
currentPage++;
noMore.value = '加载中...';
if (replies.length < 20) {
if (res['data'].cursor.isEnd == true) {
noMore.value = '没有更多了';
}
} else {
noMore.value = currentPage == 0 ? '还没有评论' : '没有更多了';
noMore.value = nextOffset == "" ? '还没有评论' : '没有更多了';
}
if (reqType == 'init') {
// 添加置顶回复
@ -102,7 +102,7 @@ class HtmlRenderController extends GetxController {
}
sortTypeTitle.value = _sortType.titles;
sortTypeLabel.value = _sortType.labels;
currentPage = 0;
nextOffset = "";
replyList.clear();
queryReplyList(reqType: 'init');
}

View File

@ -21,11 +21,9 @@ class VideoReplyController extends GetxController {
// rpid 请求楼中楼回复
String? rpid;
RxList<ReplyItemModel> replyList = <ReplyItemModel>[].obs;
// 当前页
int currentPage = 0;
String nextOffset = "";
bool isLoadingMore = false;
RxString noMore = ''.obs;
int ps = 20;
RxInt count = 0.obs;
// 当前回复的回复
ReplyItemModel? currentReplyItem;
@ -57,7 +55,7 @@ class VideoReplyController extends GetxController {
}
isLoadingMore = true;
if (type == 'init') {
currentPage = 0;
nextOffset = '';
noMore.value = '';
}
if (noMore.value == '没有更多了') {
@ -66,28 +64,20 @@ class VideoReplyController extends GetxController {
}
final res = await ReplyHttp.replyList(
oid: aid!,
pageNum: currentPage + 1,
ps: ps,
nextOffset: nextOffset,
type: ReplyType.video.index,
sort: _sortType.index,
);
if (res['status']) {
final List<ReplyItemModel> replies = res['data'].replies;
nextOffset = res['data'].cursor.paginationReply.nextOffset ?? "";
if (replies.isNotEmpty) {
noMore.value = '加载中...';
/// 第一页回复数小于20
if (currentPage == 0 && replies.length < 18) {
noMore.value = '没有更多了';
}
currentPage++;
if (replyList.length == res['data'].page.acount) {
if (res['data'].cursor.isEnd == true) {
noMore.value = '没有更多了';
}
} else {
// 未登录状态replies可能返回null
noMore.value = currentPage == 0 ? '还没有评论' : '没有更多了';
noMore.value = nextOffset == "" ? '还没有评论' : '没有更多了';
}
if (type == 'init') {
// 添加置顶回复
@ -99,7 +89,7 @@ class VideoReplyController extends GetxController {
}
}
replies.insertAll(0, res['data'].topReplies);
count.value = res['data'].page.count;
count.value = res['data'].cursor.allCount;
replyList.value = replies;
} else {
replyList.addAll(replies);
@ -130,7 +120,7 @@ class VideoReplyController extends GetxController {
}
sortTypeTitle.value = _sortType.titles;
sortTypeLabel.value = _sortType.labels;
currentPage = 0;
nextOffset = "";
noMore.value = '';
replyList.clear();
queryReplyList(type: 'init');