🐛 修复获取话题帖子异常

This commit is contained in:
目棃
2025-03-02 12:22:54 +08:00
parent 530f45e75c
commit 92603e8599
3 changed files with 39 additions and 37 deletions

View File

@@ -95,6 +95,7 @@ import { useRoute, useRouter } from "vue-router";
import { createPost } from "@/utils/TGWindow.js";
import apiHubReq from "@/web/request/apiHubReq.js";
import postReq from "@/web/request/postReq.js";
import topicReq from "@/web/request/topicReq.js";
type SortSelect = { text: string; value: number };
@@ -169,13 +170,13 @@ watch(
async function firstLoad(): Promise<void> {
await showLoading.start(`正在加载话题${topicInfo.value?.topic.name}信息`);
router.push({
await router.push({
name: "话题",
params: route.params,
query: { gid: curGid.value, topic: curTopic.value },
});
document.documentElement.scrollTo({ top: 0, behavior: "smooth" });
const postList = await topicReq.posts(curGid.value, curTopic.value, curSortType.value);
const postList = await postReq.topic(curGid.value, curTopic.value, curSortType.value);
if ("retcode" in postList) {
await showLoading.end();
showSnackbar.error(`[${postList.retcode}] ${postList.message}`);
@@ -200,7 +201,7 @@ async function freshPostData(): Promise<void> {
await showLoading.start(`正在刷新${topicInfo.value?.topic.name}帖子列表`);
const mod20 = postRaw.value.total % 20;
const pageSize = mod20 === 0 ? 20 : 20 - mod20;
const postList = await topicReq.posts(
const postList = await postReq.topic(
curGid.value,
curTopic.value,
curSortType.value,

View File

@@ -138,6 +138,39 @@ async function getSubReplies(
return resp.data;
}
/**
* @description 获取特定话题帖子列表
* @since Beta v0.7.1
* @param {number} gid 游戏分区 ID
* @param {string} topicId 话题 ID
* @param {string} orderType 排序方式
* @param {string} lastId 最后一条帖子 ID
* @param {number} size 每页大小
* @return {Promise<TGApp.BBS.Topic.PostRes|TGApp.BBS.Response.Base>}
*/
async function getTopicPostList(
gid: number,
topicId: string,
orderType: number = 0,
lastId?: string,
size: number = 20,
): Promise<TGApp.BBS.Topic.PostRes | TGApp.BBS.Response.Base> {
const resp = await TGHttp<TGApp.BBS.Topic.PostResp>(`${bapBu}getTopicPostList`, {
method: "GET",
headers: { referer: Referer },
query: {
gids: gid,
game_id: gid,
topic_id: topicId,
list_type: orderType,
last_id: lastId ?? "",
page_size: size,
},
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* @description 搜索帖子
* @since Beta v0.7.1
@@ -186,6 +219,7 @@ async function userFavouritePost(
const postReq = {
collection: getPostFullInCollection,
post: getPostFull,
topic: getTopicPostList,
reply: { main: getPostReplies, sub: getSubReplies },
search: searchPosts,
userFavourite: userFavouritePost,

View File

@@ -29,39 +29,6 @@ async function getTopicFullInfo(
return resp.data;
}
/**
* @description 获取特定话题帖子列表
* @since Beta v0.7.1
* @param {number} gid 游戏分区 ID
* @param {string} topicId 话题 ID
* @param {string} orderType 排序方式
* @param {string} lastId 最后一条帖子 ID
* @param {number} size 每页大小
* @return {Promise<TGApp.BBS.Topic.PostRes|TGApp.BBS.Response.Base>}
*/
async function getTopicPostList(
gid: number,
topicId: string,
orderType: number = 0,
lastId?: string,
size: number = 20,
): Promise<TGApp.BBS.Topic.PostRes | TGApp.BBS.Response.Base> {
const resp = await TGHttp<TGApp.BBS.Topic.PostResp>(`${batBu}getTopicPostList`, {
method: "GET",
headers: { referer: Referer },
query: {
gids: gid,
game_id: gid,
topic_id: topicId,
list_type: orderType,
last_id: lastId ?? "",
page_size: size,
},
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
const topicReq = { info: getTopicFullInfo, posts: getTopicPostList };
const topicReq = { info: getTopicFullInfo };
export default topicReq;