Skip to content

Commit

Permalink
👽️ 适配帖子api更新
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Dec 18, 2024
1 parent e80fb19 commit 1c85a0b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 44 deletions.
24 changes: 22 additions & 2 deletions src/pages/common/PostForum.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,26 @@ function getSortLabel(value: number): string {
return order ? order.text : "";
}
async function getCurrentPosts(
loadMore: boolean = false,
): Promise<TGApp.Plugins.Mys.Forum.FullData> {
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<void> {
await showLoading.start(`正在刷新${getGameLabel(curGid.value)}帖子`);
const gameLabel = getGameLabel(curGid.value);
Expand All @@ -228,7 +248,7 @@ async function freshPostData(): Promise<void> {
);
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;
Expand All @@ -242,7 +262,7 @@ async function loadMore(): Promise<void> {
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}`,
);
Expand Down
78 changes: 78 additions & 0 deletions src/plugins/Mys/request/painterReq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TGApp.Plugins.Mys.Forum.FullData>}
*/
export async function getHotForumPostList(
forumId: number,
gid: number,
lastId?: string,
pageSize: number = 20,
): Promise<TGApp.Plugins.Mys.Forum.FullData> {
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<TGApp.Plugins.Mys.Forum.Response>(`${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<TGApp.Plugins.Mys.Forum.FullData>}
*/
export async function getRecentForumPostList(
forumId: number,
gid: number,
type: number = 1,
lastId?: string,
pageSize: number = 20,
): Promise<TGApp.Plugins.Mys.Forum.FullData> {
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<TGApp.Plugins.Mys.Forum.Response>(`${Mpabu}getRecentForumPostList`, {
method: "GET",
query: params,
})
).data;
}

/**
* @description 获取抽奖信息
* @since Beta v0.6.2
Expand Down
43 changes: 1 addition & 42 deletions src/plugins/Mys/request/postReq.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -12,47 +12,6 @@ const Mpabu: Readonly<string> = "https://bbs-api.mihoyo.com/post/wapi/";
const Mtabu: Readonly<string> = "https://bbs-api.miyoushe.com/topic/wapi/";
const Referer: Readonly<string> = "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<TGApp.Plugins.Mys.Forum.FullData>}
*/
export async function getForumPostList(
forumId: number,
type: number = 1,
last_id?: string,
page_size: number = 20,
): Promise<TGApp.Plugins.Mys.Forum.FullData> {
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<TGApp.Plugins.Mys.Forum.Response>(`${Mpabu}getForumPostList`, {
method: "GET",
query: params,
})
).data;
}

/**
* @description 获取单个帖子信息
* @since Beta v0.6.3
Expand Down

0 comments on commit 1c85a0b

Please sign in to comment.