mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-22 21:59:49 +08:00
♻️ 迁移近期活动请求
This commit is contained in:
@@ -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<void> {
|
||||
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<void> {
|
||||
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<TGApp.BBS.Obc.ObcItem<TGApp.BBS.Obc.PositionItem>>,
|
||||
): Array<TGApp.BBS.Obc.PositionItem> {
|
||||
const res: Array<TGApp.BBS.Obc.PositionItem> = [];
|
||||
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 {
|
||||
|
||||
@@ -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<string> =
|
||||
@@ -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<TGApp.Game.ActCalendar.ActRes | TGApp.BBS.Response.Base> {
|
||||
): Promise<TGApp.Game.ActCalendar.ActResp> {
|
||||
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<TGApp.Game.ActCalendar.Response | TGApp.BBS.Response.Base>(
|
||||
`${trgAbu}act_calendar`,
|
||||
{ method: "POST", headers: getRequestHeader(ck, "POST", body), body: JSON.stringify(body) },
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
const resp = await TGHttps.post<TGApp.Game.ActCalendar.ActResp>(`${trgAbu}act_calendar`, {
|
||||
headers: getRequestHeader(ck, "POST", body),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<string> = "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<TGApp.BBS.Obc.ObcItem<TGApp.BBS.Obc.PositionItem>>,
|
||||
): Array<TGApp.BBS.Obc.PositionItem> {
|
||||
const res: Array<TGApp.BBS.Obc.PositionItem> = [];
|
||||
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.Obc.PositionItem> | TGApp.BBS.Response.Base
|
||||
> {
|
||||
const resp = await TGHttp<TGApp.BBS.Obc.PositionResp>(
|
||||
async function getObcHomePosition(): Promise<TGApp.BBS.Obc.PositionResp> {
|
||||
const resp = await TGHttps.get<TGApp.BBS.Obc.PositionResp>(
|
||||
`${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 <TGApp.BBS.Response.Base>resp;
|
||||
const data = resp.data.list;
|
||||
return DfsObc(data);
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
const takumiReq = {
|
||||
|
||||
22
src/types/Game/ActCalendar.d.ts
vendored
22
src/types/Game/ActCalendar.d.ts
vendored
@@ -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<ActRes>;
|
||||
type ActResp = TGApp.BBS.Response.BaseWithData<ActRes>;
|
||||
|
||||
/**
|
||||
* 活动日历返回数据
|
||||
@@ -214,7 +214,7 @@ declare namespace TGApp.Game.ActCalendar {
|
||||
* 幽境危战
|
||||
* @since Beta v0.8.0
|
||||
*/
|
||||
type ActItemHardChallenge = ActItemBase<"ActTypeHardChallenge"> & {
|
||||
type ActItemHardChallenge = ActItemBase<typeof ActType.HardChallenge> & {
|
||||
/** 幽境危战活动详情 */
|
||||
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<typeof ActType.RoleCombat> & {
|
||||
/** 真境剧诗活动详情 */
|
||||
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<typeof ActType.Tower> & {
|
||||
/** 深渊螺旋活动详情 */
|
||||
tower_detail: ActTower;
|
||||
};
|
||||
@@ -303,7 +303,7 @@ declare namespace TGApp.Game.ActCalendar {
|
||||
* 双倍活动
|
||||
* @since Beta v0.8.0
|
||||
*/
|
||||
type ActItemDouble = ActItemBase<"ActTypeDouble"> & {
|
||||
type ActItemDouble = ActItemBase<typeof ActType.Double> & {
|
||||
/** 双倍活动详情 */
|
||||
double_detail: ActDouble;
|
||||
};
|
||||
@@ -323,7 +323,7 @@ declare namespace TGApp.Game.ActCalendar {
|
||||
* 探索活动
|
||||
* @since Beta v0.8.0
|
||||
*/
|
||||
type ActItemExplore = ActItemBase<"ActTypeExplore"> & {
|
||||
type ActItemExplore = ActItemBase<typeof ActType.Explore> & {
|
||||
/** 探索活动详情 */
|
||||
explore_detail: ActExplore;
|
||||
};
|
||||
@@ -343,7 +343,7 @@ declare namespace TGApp.Game.ActCalendar {
|
||||
* 立本活动
|
||||
* @since Beta v0.9.0
|
||||
*/
|
||||
type ActItemLiBen = ActItemBase<"ActTypeLiBen"> & {
|
||||
type ActItemLiBen = ActItemBase<typeof ActType.LiBen> & {
|
||||
/** 立本活动详情 */
|
||||
liben_detail: ActLiBen;
|
||||
};
|
||||
@@ -370,7 +370,7 @@ declare namespace TGApp.Game.ActCalendar {
|
||||
* 累登活动
|
||||
* @since Beta v0.9.0
|
||||
*/
|
||||
type ActItemSignIn = ActItemBase<"ActTypeSignIn"> & {
|
||||
type ActItemSignIn = ActItemBase<typeof ActType.SignIn> & {
|
||||
/** 累登活动详情 */
|
||||
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<typeof ActType.Other> & {
|
||||
/** 是否完成 */
|
||||
is_finished: boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user