From 6f6959d987c6cc54649cdf1976ff859000768ebb Mon Sep 17 00:00:00 2001 From: BTMuli Date: Tue, 14 Apr 2026 21:01:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E8=BF=91=E6=9C=9F=E6=B4=BB=E5=8A=A8=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/pageHome/ph-comp-position.vue | 84 ++++++++++++++++---- src/request/recordReq.ts | 19 +++-- src/request/takumiReq.ts | 40 ++-------- src/types/Game/ActCalendar.d.ts | 22 ++--- 4 files changed, 97 insertions(+), 68 deletions(-) diff --git a/src/components/pageHome/ph-comp-position.vue b/src/components/pageHome/ph-comp-position.vue index 2ae01a60..ac3cb777 100644 --- a/src/components/pageHome/ph-comp-position.vue +++ b/src/components/pageHome/ph-comp-position.vue @@ -35,6 +35,7 @@ import TSUserBagMaterial from "@Sqlm/userBagMaterial.js"; import useAppStore from "@store/app.js"; import useUserStore from "@store/user.js"; import { openUrl } from "@tauri-apps/plugin-opener"; +import TGHttps from "@utils/TGHttps.js"; import TGLogger from "@utils/TGLogger.js"; import { timestampToDate } from "@utils/toolFunc.js"; import { storeToRefs } from "pinia"; @@ -95,31 +96,84 @@ async function loadUserPosition(forceReload: boolean = false): Promise { return; } if (isInit.value) await showLoading.start("正在获取近期活动"); - const resp = await recordReq.actCalendar(cookie.value, account.value); - console.log(resp); - if (isInit.value) await showLoading.end(); - if ("retcode" in resp) { - showSnackbar.error(`获取近期活动失败:[${resp.retcode}]-${resp.message}`); - await TGLogger.Error(`获取近期活动失败:[${resp.retcode}]-${resp.message}`); + // 获取近期活动 + let resp: TGApp.Game.ActCalendar.ActResp | undefined; + try { + resp = await recordReq.actCalendar(cookie.value, account.value); + if (resp.retcode !== 0) { + if (isInit.value) { + showSnackbar.warn(`[${resp.retcode}] ${resp.message}`); + await showLoading.end(); + } + await TGLogger.Warn(`[PhCompPosition][loadUserPosition] 获取近期活动异常`); + await TGLogger.Warn(`[PhCompPosition][loadUserPosition] ${resp.retcode}-${resp.message}`); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); + if (isInit.value) { + showSnackbar.error(`获取近期活动失败:${errMsg}`); + await showLoading.end(); + } + await TGLogger.Error(`[PhCompPosition][loadUserPosition] 获取近期活动异常`); + await TGLogger.Error(`[PhCompPosition][loadUserPosition] ${e}`); return; } - userPos.value = [...resp.act_list, ...resp.fixed_act_list] + if (!resp) { + if (isInit.value) await showLoading.end(); + return; + } + // 处理近期活动数据 + userPos.value = [...resp.data.act_list, ...resp.data.fixed_act_list] .filter((i) => i.start_timestamp !== "0") .sort((a, b) => Number(a.is_finished) - Number(b.is_finished) || b.id - a.id); + if (isInit.value) await showLoading.end(); } async function loadWikiPosition(): Promise { if (obsPos.value.length > 0) return; if (isInit.value) await showLoading.start("正在加载近期活动"); - const resp = await takumiReq.obc.position(); - if (isInit.value) await showLoading.end(); - if (Array.isArray(resp)) { - obsPos.value = resp; - if (resp.length === 0) showSnackbar.warn("暂无近期活动"); - } else { - showSnackbar.error(`获取近期活动失败:[${resp.retcode}]-${resp.message}`); - await TGLogger.Error(`获取近期活动失败:[${resp.retcode}]-${resp.message}`); + let resp: TGApp.BBS.Obc.PositionResp | undefined; + try { + resp = await takumiReq.obc.position(); + if (resp.retcode !== 0) { + if (isInit.value) { + showSnackbar.warn(`[${resp.retcode}] ${resp.message}`); + await showLoading.end(); + } + await TGLogger.Warn(`[PhCompPosition][loadWikiPosition] 获取近期活动异常`); + await TGLogger.Warn(`[PhCompPosition][loadWikiPosition] ${resp.retcode}-${resp.message}`); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); + if (isInit.value) { + showSnackbar.error(`获取近期活动失败:${errMsg}`); + await showLoading.end(); + } + await TGLogger.Error(`[PhCompPosition][loadWikiPosition] 获取近期活动异常`); + await TGLogger.Error(`[PhCompPosition][loadWikiPosition] ${e}`); + return; } + if (!resp) { + if (isInit.value) await showLoading.end(); + return; + } + const data = dfsObc(resp.data.list); + obsPos.value = data; + if (data.length === 0) showSnackbar.warn("暂无近期活动"); + if (isInit.value) await showLoading.end(); +} + +function dfsObc( + list: Array>, +): Array { + const res: Array = []; + for (const item of list) { + if (item.name === "近期活动") res.push(...item.list); + if (item.children) res.push(...dfsObc(item.children)); + } + return res; } function genEmptyMaterial(material: TGApp.App.Material.WikiItem): MaterialInfo { diff --git a/src/request/recordReq.ts b/src/request/recordReq.ts index 5cc713a5..3ebd38e5 100644 --- a/src/request/recordReq.ts +++ b/src/request/recordReq.ts @@ -1,12 +1,12 @@ /** * TakumiRecordGenshinApi 相关请求 - * @since Beta v0.10.0 + * @since Beta v0.10.1 */ import gameEnum from "@enum/game.js"; import { getRequestHeader } from "@utils/getRequestHeader.js"; -import TGHttps from "@utils/TGHttps.js"; import TGHttp from "@utils/TGHttp.js"; +import TGHttps from "@utils/TGHttps.js"; // TakumiRecordGenshinApiBaseUrl => trgAbu const trgAbu: Readonly = @@ -210,22 +210,21 @@ async function hardChallengeDetail( /** * 获取活动日历数据 - * @since Beta v0.8.0 + * @since Beta v0.10.1 * @param cookie - Cookie * @param user - 用户 - * @returns 活动日历数据 + * @returns 活动日历响应数据 */ async function actCalendar( cookie: TGApp.App.Account.Cookie, user: TGApp.Sqlite.Account.Game, -): Promise { +): Promise { const ck = { account_id: cookie.account_id, cookie_token: cookie.cookie_token }; const body = { role_id: user.gameUid, server: user.region }; - const resp = await TGHttp( - `${trgAbu}act_calendar`, - { method: "POST", headers: getRequestHeader(ck, "POST", body), body: JSON.stringify(body) }, - ); - if (resp.retcode !== 0) return resp; + const resp = await TGHttps.post(`${trgAbu}act_calendar`, { + headers: getRequestHeader(ck, "POST", body), + body: JSON.stringify(body), + }); return resp.data; } diff --git a/src/request/takumiReq.ts b/src/request/takumiReq.ts index 3fb06566..13aedb53 100644 --- a/src/request/takumiReq.ts +++ b/src/request/takumiReq.ts @@ -1,9 +1,10 @@ /** * Takumi 相关请求函数 - * @since Beta v0.7.2 + * @since Beta v0.10.1 */ import { getRequestHeader } from "@utils/getRequestHeader.js"; import TGHttp from "@utils/TGHttp.js"; +import TGHttps from "@utils/TGHttps.js"; // TakumiApiBaseUrl => taBu const taBu: Readonly = "https://api-takumi.mihoyo.com/"; @@ -148,42 +149,17 @@ async function getObcGachaPool(): Promise< return resp.data.list; } -/** - * 深度优先遍历 - * @since Beta v0.7.2 - * @param list - 列表 - * @returns 返回列表 - */ -function DfsObc( - list: Array>, -): Array { - const res: Array = []; - for (const item of list) { - if (item.name === "近期活动") res.push(...item.list); - if (item.children) res.push(...DfsObc(item.children)); - } - return res; -} - /** * 获取热点追踪信息 - * @since Beta v0.7.2 - * @returns 近期活动 + * @since Beta v0.10.1 + * @returns 近期活动响应数据 */ -async function getObcHomePosition(): Promise< - Array | TGApp.BBS.Response.Base -> { - const resp = await TGHttp( +async function getObcHomePosition(): Promise { + const resp = await TGHttps.get( `${taBu}common/blackboard/ys_obc/v1/home/position`, - { - method: "GET", - query: { app_sn: "ys_obc" }, - headers: { "Content-Type": "application/json" }, - }, + { headers: { "Content-Type": "application/json" }, query: { app_sn: "ys_obc" } }, ); - if (resp.retcode !== 0) return resp; - const data = resp.data.list; - return DfsObc(data); + return resp.data; } const takumiReq = { diff --git a/src/types/Game/ActCalendar.d.ts b/src/types/Game/ActCalendar.d.ts index 6869b1b8..d90e6e4d 100644 --- a/src/types/Game/ActCalendar.d.ts +++ b/src/types/Game/ActCalendar.d.ts @@ -1,14 +1,14 @@ /** * 游戏-活动日历相关类型定义文件 - * @since Beta v0.9.9 + * @since Beta v0.10.1 */ declare namespace TGApp.Game.ActCalendar { /** * 获取活动日历返回响应 - * @since Beta v0.8.0 + * @since Beta v0.10.1 */ - type Response = TGApp.BBS.Response.BaseWithData; + type ActResp = TGApp.BBS.Response.BaseWithData; /** * 活动日历返回数据 @@ -214,7 +214,7 @@ declare namespace TGApp.Game.ActCalendar { * 幽境危战 * @since Beta v0.8.0 */ - type ActItemHardChallenge = ActItemBase<"ActTypeHardChallenge"> & { + type ActItemHardChallenge = ActItemBase & { /** 幽境危战活动详情 */ hard_challenge_detail: ActHardChallenge; }; @@ -253,7 +253,7 @@ declare namespace TGApp.Game.ActCalendar { * 真境剧诗 * @since Beta v0.8.0剧诗活动详情 */ - type ActItemRoleCombat = ActItemBase<"ActTypeRoleCombat"> & { + type ActItemRoleCombat = ActItemBase & { /** 真境剧诗活动详情 */ role_combat_detail: ActRoleCombat; }; @@ -279,7 +279,7 @@ declare namespace TGApp.Game.ActCalendar { * 深渊螺旋 * @since Beta v0.8.0 */ - type ActItemTower = ActItemBase<"ActTypeTower"> & { + type ActItemTower = ActItemBase & { /** 深渊螺旋活动详情 */ tower_detail: ActTower; }; @@ -303,7 +303,7 @@ declare namespace TGApp.Game.ActCalendar { * 双倍活动 * @since Beta v0.8.0 */ - type ActItemDouble = ActItemBase<"ActTypeDouble"> & { + type ActItemDouble = ActItemBase & { /** 双倍活动详情 */ double_detail: ActDouble; }; @@ -323,7 +323,7 @@ declare namespace TGApp.Game.ActCalendar { * 探索活动 * @since Beta v0.8.0 */ - type ActItemExplore = ActItemBase<"ActTypeExplore"> & { + type ActItemExplore = ActItemBase & { /** 探索活动详情 */ explore_detail: ActExplore; }; @@ -343,7 +343,7 @@ declare namespace TGApp.Game.ActCalendar { * 立本活动 * @since Beta v0.9.0 */ - type ActItemLiBen = ActItemBase<"ActTypeLiBen"> & { + type ActItemLiBen = ActItemBase & { /** 立本活动详情 */ liben_detail: ActLiBen; }; @@ -370,7 +370,7 @@ declare namespace TGApp.Game.ActCalendar { * 累登活动 * @since Beta v0.9.0 */ - type ActItemSignIn = ActItemBase<"ActTypeSignIn"> & { + type ActItemSignIn = ActItemBase & { /** 累登活动详情 */ sign_in_detail: ActSignIn; }; @@ -395,7 +395,7 @@ declare namespace TGApp.Game.ActCalendar { * 其他活动 * @since Beta v0.8.0 */ - type ActItemOther = ActItemBase<"ActTypeOther"> & { + type ActItemOther = ActItemBase & { /** 是否完成 */ is_finished: boolean; };