mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-22 21:59:49 +08:00
♻️ 迁移topicReq
This commit is contained in:
@@ -109,6 +109,8 @@ import postReq from "@req/postReq.js";
|
||||
import topicReq from "@req/topicReq.js";
|
||||
import useAppStore from "@store/app.js";
|
||||
import useBBSStore from "@store/bbs.js";
|
||||
import TGHttps from "@utils/TGHttps.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { createPost } from "@utils/TGWindow.js";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref, shallowRef, watch } from "vue";
|
||||
@@ -172,18 +174,29 @@ onMounted(async () => {
|
||||
curGid.value = Number(gid);
|
||||
curTopic.value = topic;
|
||||
await showLoading.start(`正在加载话题${topic}信息`);
|
||||
const info = await topicReq.info(gid, topic);
|
||||
if ("retcode" in info) {
|
||||
let info: TGApp.BBS.Topic.InfoResp | undefined;
|
||||
try {
|
||||
info = await topicReq.info(gid, topic);
|
||||
if (info.retcode !== 0) {
|
||||
await showLoading.end();
|
||||
showSnackbar.error(`[${info.retcode}] ${info.message}`);
|
||||
await TGLogger.Warn(`[PostTopic] 获取话题信息失败:[${info.retcode}] ${info.message}`);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
const errMsg = TGHttps.getErrMsg(e);
|
||||
await showLoading.end();
|
||||
showSnackbar.error(`[${info.retcode}] ${info.message}`);
|
||||
showSnackbar.error(`获取话题信息失败:${errMsg}`);
|
||||
await TGLogger.Error(`[PostTopic] 获取话题信息异常`);
|
||||
await TGLogger.Error(`[PostTopic] ${e}`);
|
||||
return;
|
||||
}
|
||||
topicInfo.value = info;
|
||||
topicInfo.value = info.data;
|
||||
let tmpGame: GameList | undefined;
|
||||
if (curGame.value === undefined) {
|
||||
tmpGame = info.game_info_list.find((i) => i.id === curGid.value);
|
||||
tmpGame = info.data.game_info_list.find((i) => i.id === curGid.value);
|
||||
}
|
||||
if (tmpGame === undefined) tmpGame = info.game_info_list[0];
|
||||
if (tmpGame === undefined) tmpGame = info.data.game_info_list[0];
|
||||
const gameFind = gameList.value.find((i) => i.id === tmpGame?.id);
|
||||
curGame.value = { ...tmpGame, icon: gameFind?.app_icon };
|
||||
await freshPostData();
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
/**
|
||||
* 话题相关的请求
|
||||
* @since Beta v0.7.9
|
||||
* @since Beta v0.10.1
|
||||
*/
|
||||
import TGHttp from "@utils/TGHttp.js";
|
||||
import TGHttps from "@utils/TGHttps.js";
|
||||
|
||||
// BBSApiTopicBaseUrl => batBu
|
||||
const batBu: Readonly<string> = "https://bbs-api.miyoushe.com/topic/wapi/";
|
||||
const Referer: Readonly<string> = "https://bbs.mihoyo.com/";
|
||||
|
||||
/**
|
||||
* 获取特定话题信息
|
||||
* @since Beta v0.7.9
|
||||
* @since Beta v0.10.1
|
||||
* @param gid - 游戏分区 ID
|
||||
* @param topicId - 话题 ID
|
||||
* @returns 话题信息
|
||||
* @returns 话题信息响应数据
|
||||
*/
|
||||
async function getTopicFullInfo(
|
||||
gid: string,
|
||||
topicId: string,
|
||||
): Promise<TGApp.BBS.Topic.InfoRes | TGApp.BBS.Response.Base> {
|
||||
const resp = await TGHttp<TGApp.BBS.Topic.InfoResp>(`${batBu}getTopicFullInfo`, {
|
||||
method: "GET",
|
||||
async function getTopicFullInfo(gid: string, topicId: string): Promise<TGApp.BBS.Topic.InfoResp> {
|
||||
const resp = await TGHttps.get<TGApp.BBS.Topic.InfoResp>(`${batBu}getTopicFullInfo`, {
|
||||
headers: { referer: Referer, cookie: "" },
|
||||
query: { gids: gid, id: topicId },
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user