From 1c85a0b43b1ba2eba03f3ba7b0e1543cbc2c590a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Wed, 18 Dec 2024 10:39:10 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20=E9=80=82=E9=85=8D?= =?UTF-8?q?=E5=B8=96=E5=AD=90api=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/common/PostForum.vue | 24 ++++++++- src/plugins/Mys/request/painterReq.ts | 78 +++++++++++++++++++++++++++ src/plugins/Mys/request/postReq.ts | 43 +-------------- 3 files changed, 101 insertions(+), 44 deletions(-) diff --git a/src/pages/common/PostForum.vue b/src/pages/common/PostForum.vue index e0b42bc0..dc7444e8 100644 --- a/src/pages/common/PostForum.vue +++ b/src/pages/common/PostForum.vue @@ -218,6 +218,26 @@ function getSortLabel(value: number): string { return order ? order.text : ""; } +async function getCurrentPosts( + loadMore: boolean = false, +): Promise { + if (curSortType.value === 3) { + if (loadMore) { + return await Mys.Painter.getHotForumPostList(curForum.value, curGid.value, lastId.value); + } + return await Mys.Painter.getHotForumPostList(curForum.value, curGid.value); + } + if (loadMore) { + return await Mys.Painter.getRecentForumPostList( + curForum.value, + curGid.value, + curSortType.value, + lastId.value, + ); + } + return await Mys.Painter.getRecentForumPostList(curForum.value, curGid.value, curSortType.value); +} + async function freshPostData(): Promise { await showLoading.start(`正在刷新${getGameLabel(curGid.value)}帖子`); const gameLabel = getGameLabel(curGid.value); @@ -228,7 +248,7 @@ async function freshPostData(): Promise { ); await showLoading.update(`版块:${forumLabel},排序:${sortLabel}`); document.documentElement.scrollTo({ top: 0, behavior: "smooth" }); - const postsGet = await Mys.Post.getForumPostList(curForum.value, curSortType.value); + const postsGet = await getCurrentPosts(); posts.value = postsGet.list; lastId.value = postsGet.last_id; isLast.value = postsGet.is_last; @@ -242,7 +262,7 @@ async function loadMore(): Promise { return; } await showLoading.start("正在加载更多帖子数据", `游戏:${getGameLabel(curGid.value)}`); - const postsGet = await Mys.Post.getForumPostList(curForum.value, curSortType.value, lastId.value); + const postsGet = await getCurrentPosts(true); await showLoading.update( `版块:${curForumLabel.value},排序:${getSortLabel(curSortType.value)},数量:${postsGet.list.length}`, ); diff --git a/src/plugins/Mys/request/painterReq.ts b/src/plugins/Mys/request/painterReq.ts index 214a27dd..fd675d3e 100644 --- a/src/plugins/Mys/request/painterReq.ts +++ b/src/plugins/Mys/request/painterReq.ts @@ -32,6 +32,84 @@ export async function getNewsList( ).data; } +/** + * @description 获取最近版块热门帖子列表 + * @since Beta v0.6.7 + * @param {number} forumId 版块 ID + * @param {number} gid 社区 ID + * @param {number} pageSize 每页数量 + * @param {string} lastId 最后 ID + * @return {Promise} + */ +export async function getHotForumPostList( + forumId: number, + gid: number, + lastId?: string, + pageSize: number = 20, +): Promise { + type ReqParams = { + forum_id: number; + gids: number; + page_size: number; + is_good: boolean; + last_id?: string; + }; + const params: ReqParams = { + forum_id: forumId, + gids: gid, + page_size: pageSize, + is_good: false, + }; + if (lastId) params.last_id = lastId; + return ( + await TGHttp(`${Mpabu}getHotForumPostList`, { + method: "GET", + query: params, + }) + ).data; +} + +/** + * @description 获取最近版块帖子列表 + * @since Beta v0.6.7 + * @param {number} forumId 版块 ID + * @param {number} gid 社区 ID + * @param {number} type 排序方式: 1-最新回复,2-最新发布 + * @param {string} lastId 最后 ID + * @param {number} pageSize 每页数量 + * @return {Promise} + */ +export async function getRecentForumPostList( + forumId: number, + gid: number, + type: number = 1, + lastId?: string, + pageSize: number = 20, +): Promise { + type ReqParams = { + forum_id: number; + gids: number; + sort_type: number; + is_good: boolean; + page_size: number; + last_id?: string; + }; + const params: ReqParams = { + forum_id: forumId, + gids: gid, + sort_type: type, + is_good: false, + page_size: pageSize, + }; + if (lastId) params.last_id = lastId; + return ( + await TGHttp(`${Mpabu}getRecentForumPostList`, { + method: "GET", + query: params, + }) + ).data; +} + /** * @description 获取抽奖信息 * @since Beta v0.6.2 diff --git a/src/plugins/Mys/request/postReq.ts b/src/plugins/Mys/request/postReq.ts index 42b26098..0406ea65 100644 --- a/src/plugins/Mys/request/postReq.ts +++ b/src/plugins/Mys/request/postReq.ts @@ -1,7 +1,7 @@ /** * @file plugins/Mys/request/postReq.ts * @description 帖子相关的获取 - * @since Beta v0.6.4 + * @since Beta v0.6.7 */ import TGHttp from "@/utils/TGHttp.js"; @@ -12,47 +12,6 @@ const Mpabu: Readonly = "https://bbs-api.mihoyo.com/post/wapi/"; const Mtabu: Readonly = "https://bbs-api.miyoushe.com/topic/wapi/"; const Referer: Readonly = "https://bbs.mihoyo.com/"; -/** - * @description 获取特定论坛列表 - * @since Beta v0.6.2 - * @param {number} forumId 特定论坛 ID - * @param {number} type 排序方式: 0-按热度排序,1-最新回复,2-按时间排序 - * @param {string} last_id 最后 ID - * @param {number} page_size 每页数量 - * @return {Promise} - */ -export async function getForumPostList( - forumId: number, - type: number = 1, - last_id?: string, - page_size: number = 20, -): Promise { - let params; - if (type === 3) { - params = { - forum_id: forumId, - is_hot: true, - page_size: page_size, - last_id: last_id, - }; - } else { - params = { - forum_id: forumId, - sort_type: type, - is_good: false, - is_hot: false, - page_size: page_size, - last_id: last_id, - }; - } - return ( - await TGHttp(`${Mpabu}getForumPostList`, { - method: "GET", - query: params, - }) - ).data; -} - /** * @description 获取单个帖子信息 * @since Beta v0.6.3