From a669488612d4483ef472f902b1c1dcfbf45ce356 Mon Sep 17 00:00:00 2001 From: orz12 Date: Tue, 13 Aug 2024 01:11:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=84=E8=AE=BA=E5=8C=BA=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=88=87=E6=8D=A2=E6=9C=80=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/api.dart | 2 +- lib/http/reply.dart | 10 ++-- lib/models/video/reply/data.dart | 39 ++++++++++++-- lib/models/video/reply/page.dart | 57 ++++++++++++++++++++ lib/pages/dynamics/detail/controller.dart | 14 ++--- lib/pages/html/controller.dart | 18 +++---- lib/pages/video/detail/reply/controller.dart | 22 +++----- 7 files changed, 122 insertions(+), 40 deletions(-) diff --git a/lib/http/api.dart b/lib/http/api.dart index f0563e3eb..4e67c14bb 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -129,7 +129,7 @@ class Api { // 评论列表 // https://api.bilibili.com/x/v2/reply/main?csrf=6e22efc1a47225ea25f901f922b5cfdd&mode=3&oid=254175381&pagination_str=%7B%22offset%22:%22%22%7D&plat=1&seek_rpid=0&type=11 - static const String replyList = '/x/v2/reply'; + static const String replyList = '/x/v2/reply/main'; // 楼中楼 static const String replyReplyList = '/x/v2/reply/reply'; diff --git a/lib/http/reply.dart b/lib/http/reply.dart index 7925fe842..7a9bc9afa 100644 --- a/lib/http/reply.dart +++ b/lib/http/reply.dart @@ -6,17 +6,15 @@ import 'init.dart'; class ReplyHttp { static Future replyList({ required int oid, - required int pageNum, + required String nextOffset, required int type, - int? ps, int sort = 1, }) async { var res = await Request().get(Api.replyList, data: { 'oid': oid, - 'pn': pageNum, 'type': type, - 'sort': sort, - 'ps': ps ?? 20 + 'pagination_str': '{"offset":"${nextOffset.replaceAll('"', '\\"')}"}', + 'mode': sort + 2, //2:按时间排序;3:按热度排序 }); if (res.data['code'] == 0) { return { @@ -50,7 +48,7 @@ class ReplyHttp { if (res.data['code'] == 0) { return { 'status': true, - 'data': ReplyData.fromJson(res.data['data']), + 'data': ReplyReplyData.fromJson(res.data['data']), }; } else { return { diff --git a/lib/models/video/reply/data.dart b/lib/models/video/reply/data.dart index 7103253dd..cce2b5d45 100644 --- a/lib/models/video/reply/data.dart +++ b/lib/models/video/reply/data.dart @@ -6,21 +6,21 @@ import 'upper.dart'; class ReplyData { ReplyData({ - this.page, + this.cursor, this.config, this.replies, this.topReplies, this.upper, }); - ReplyPage? page; + ReplyCursor? cursor; ReplyConfig? config; late List? replies; late List? topReplies; ReplyUpper? upper; ReplyData.fromJson(Map json) { - page = ReplyPage.fromJson(json['page']); + cursor = ReplyCursor.fromJson(json['cursor']); config = ReplyConfig.fromJson(json['config']); replies = json['replies'] != null ? List.from(json['replies'] @@ -36,3 +36,36 @@ class ReplyData { upper = ReplyUpper.fromJson(json['upper']); } } + +class ReplyReplyData { + ReplyReplyData({ + this.page, + this.config, + this.replies, + this.topReplies, + this.upper, + }); + + ReplyPage? page; + ReplyConfig? config; + late List? replies; + late List? topReplies; + ReplyUpper? upper; + + ReplyReplyData.fromJson(Map json) { + page = ReplyPage.fromJson(json['page']); + config = ReplyConfig.fromJson(json['config']); + replies = json['replies'] != null + ? List.from(json['replies'] + .map( + (item) => ReplyItemModel.fromJson(item, json['upper']['mid']))) + : []; + topReplies = json['top_replies'] != null + ? List.from(json['top_replies'] + .map((item) => ReplyItemModel.fromJson( + item, json['upper']['mid'], + isTopStatus: true))) + : []; + upper = ReplyUpper.fromJson(json['upper']); + } +} diff --git a/lib/models/video/reply/page.dart b/lib/models/video/reply/page.dart index 771b05158..ee10c7ac5 100644 --- a/lib/models/video/reply/page.dart +++ b/lib/models/video/reply/page.dart @@ -18,3 +18,60 @@ class ReplyPage { acount = json['acount']; } } + +class ReplyCursor { + ReplyCursor({ + this.isBegin, + this.prev, + this.next, + this.isEnd, + this.mode, + this.modeText, + this.allCount, + this.supportMode, + this.name, + this.paginationReply, + this.sessionId, + }); + + bool? isBegin; + int? prev; + int? next; + bool? isEnd; + int? mode; + String? modeText; + int? allCount; + List? supportMode; + String? name; + PaginationReply? paginationReply; + String? sessionId; + + ReplyCursor.fromJson(Map json) { + isBegin = json['is_begin']; + prev = json['prev']; + next = json['next']; + isEnd = json['is_end']; + mode = json['mode']; + modeText = json['mode_text']; + allCount = json['all_count']; + supportMode = json['support_mode'].cast(); + name = json['name']; + paginationReply = json['pagination_reply'] != null + ? PaginationReply.fromJson(json['pagination_reply']) + : null; + sessionId = json['session_id']; + } +} + +class PaginationReply { + PaginationReply({ + this.nextOffset, + this.prevOffset, + }); + String? nextOffset; + String? prevOffset; + PaginationReply.fromJson(Map json) { + nextOffset = json['next_offset']; + prevOffset = json['prev_offset']; + } +} diff --git a/lib/pages/dynamics/detail/controller.dart b/lib/pages/dynamics/detail/controller.dart index 7b8c90892..54fd0f6fb 100644 --- a/lib/pages/dynamics/detail/controller.dart +++ b/lib/pages/dynamics/detail/controller.dart @@ -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 replyList = [].obs; @@ -48,27 +48,27 @@ class DynamicDetailController extends GetxController { Future queryReplyList({reqType = 'init'}) async { if (reqType == 'init') { - currentPage = 0; + nextOffset = ""; } isLoadingMore = true; var res = await ReplyHttp.replyList( oid: oid!, - pageNum: currentPage + 1, + nextOffset: nextOffset, type: type!, sort: _sortType.index, ); isLoadingMore = false; if (res['status']) { List 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') { // 添加置顶回复 diff --git a/lib/pages/html/controller.dart b/lib/pages/html/controller.dart index 96ee1325d..f027c189b 100644 --- a/lib/pages/html/controller.dart +++ b/lib/pages/html/controller.dart @@ -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 replyList = [].obs; @@ -34,7 +34,7 @@ class HtmlRenderController extends GetxController { dynamicType = Get.parameters['dynamicType']!; type = dynamicType == 'picture' ? 11 : 12; int defaultReplySortIndex = - setting.get(SettingBoxKey.replySortType, defaultValue: 0) as int; + setting.get(SettingBoxKey.replySortType, defaultValue: 0) as int; if (defaultReplySortIndex == 2) { setting.put(SettingBoxKey.replySortType, 0); defaultReplySortIndex = 0; @@ -61,25 +61,25 @@ class HtmlRenderController extends GetxController { // 请求评论 Future queryReplyList({reqType = 'init'}) async { if (reqType == 'init') { - currentPage = 0; + nextOffset = ""; } var res = await ReplyHttp.replyList( oid: oid.value, - pageNum: currentPage + 1, + nextOffset: nextOffset, type: type, sort: _sortType.index, ); if (res['status']) { List 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') { // 添加置顶回复 @@ -115,7 +115,7 @@ class HtmlRenderController extends GetxController { } sortTypeTitle.value = _sortType.titles; sortTypeLabel.value = _sortType.labels; - currentPage = 0; + nextOffset = ""; replyList.clear(); queryReplyList(reqType: 'init'); } diff --git a/lib/pages/video/detail/reply/controller.dart b/lib/pages/video/detail/reply/controller.dart index 6d2b34c57..3a13d25f3 100644 --- a/lib/pages/video/detail/reply/controller.dart +++ b/lib/pages/video/detail/reply/controller.dart @@ -23,11 +23,9 @@ class VideoReplyController extends GetxController { // rpid 请求楼中楼回复 String? rpid; RxList replyList = [].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 { return; } if (type == 'init') { - currentPage = 0; + nextOffset = ''; noMore.value = ''; } if (noMore.value == '没有更多了') { @@ -66,29 +64,25 @@ class VideoReplyController extends GetxController { isLoadingMore = true; final res = await ReplyHttp.replyList( oid: aid!, - pageNum: currentPage + 1, - ps: ps, + nextOffset: nextOffset, type: ReplyType.video.index, sort: _sortType.index, ); isLoadingMore = false; if (res['status']) { final List replies = res['data'].replies; + nextOffset = res['data'].cursor.paginationReply.nextOffset ?? ""; if (replies.isNotEmpty) { noMore.value = '加载中...'; /// 第一页回复数小于20 - if (currentPage == 0 && replies.length < 18) { + if (res['data'].cursor.isEnd == true) { noMore.value = '没有更多了'; } - currentPage++; - if (replyList.length == res['data'].page.acount) { - noMore.value = '没有更多了'; - } } else { // 未登录状态replies可能返回null - noMore.value = currentPage == 0 ? '还没有评论' : '没有更多了'; + noMore.value = nextOffset == "" ? '还没有评论' : '没有更多了'; } if (type == 'init') { // 添加置顶回复 @@ -100,7 +94,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); @@ -128,7 +122,7 @@ class VideoReplyController extends GetxController { } sortTypeTitle.value = _sortType.titles; sortTypeLabel.value = _sortType.labels; - currentPage = 0; + nextOffset = ""; noMore.value = ''; replyList.clear(); queryReplyList(type: 'init');