mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
🐛 修复数据未即时刷新
This commit is contained in:
@@ -280,11 +280,14 @@ async function refresh(): Promise<void> {
|
||||
loadData.value = false;
|
||||
return;
|
||||
}
|
||||
const cookie = {
|
||||
account_id: userStore.cookie.value.account_id,
|
||||
cookie_token: userStore.cookie.value.cookie_token,
|
||||
};
|
||||
const listRes = await TGRequest.User.byCookie.getAvatarList(cookie, user.value.gameUid);
|
||||
const indexRes = await TGRequest.User.byCookie.getAvatarIndex(userStore.cookie.value, user.value);
|
||||
if (indexRes.retcode !== 0) {
|
||||
showSnackbar({ text: `[${indexRes.retcode}] ${indexRes.message}` });
|
||||
loading.value = false;
|
||||
loadData.value = false;
|
||||
return;
|
||||
}
|
||||
const listRes = await TGRequest.User.byCookie.getAvatarList(userStore.cookie.value, user.value);
|
||||
if (!Array.isArray(listRes)) {
|
||||
showSnackbar({ text: `[${listRes.retcode}] ${listRes.message}`, color: "error" });
|
||||
await TGLogger.Error(`[Character][refreshRoles][${user.value.gameUid}] 获取角色列表失败`);
|
||||
@@ -298,7 +301,11 @@ async function refresh(): Promise<void> {
|
||||
const idList = listRes.map((i) => i.id.toString());
|
||||
loadingTitle.value = "正在获取角色数据";
|
||||
loadingSub.value = `共${idList.length}个角色`;
|
||||
const res = await TGRequest.User.byCookie.getAvatarDetail(cookie, user.value.gameUid, idList);
|
||||
const res = await TGRequest.User.byCookie.getAvatarDetail(
|
||||
userStore.cookie.value,
|
||||
user.value,
|
||||
idList,
|
||||
);
|
||||
if ("retcode" in res) {
|
||||
showSnackbar({ text: `[${res.retcode}] ${res.message}`, color: "error" });
|
||||
await TGLogger.Error(`[Character][refreshRoles][${user.value.gameUid}] 获取角色数据失败`);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web/request/TGRequest.ts
|
||||
* @description 应用用到的请求函数
|
||||
* @since Beta v0.6.0
|
||||
* @since Beta v0.6.1
|
||||
*/
|
||||
|
||||
import { genAuthkey, genAuthkey2 } from "./genAuthkey.js";
|
||||
@@ -9,7 +9,7 @@ import { getAbyss } from "./getAbyss.js";
|
||||
import { getActionTicketBySToken } from "./getActionTicket.js";
|
||||
import { getAnnoContent, getAnnoList } from "./getAnno.js";
|
||||
import getAuthTicket from "./getAuthTicket.js";
|
||||
import { getAvatarList, getAvatarDetail } from "./getAvatarDetail.js";
|
||||
import { getAvatarList, getAvatarDetail, getAvatarIndex } from "./getAvatarDetail.js";
|
||||
import getCode from "./getCode.js";
|
||||
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken.js";
|
||||
import { getDeviceFp } from "./getDeviceFp.js";
|
||||
@@ -44,6 +44,7 @@ const TGRequest = {
|
||||
getAbyss,
|
||||
getAccounts: getGameAccountsByCookie,
|
||||
getUserInfo: getUserInfoByCookie,
|
||||
getAvatarIndex,
|
||||
getAvatarList,
|
||||
getAvatarDetail,
|
||||
},
|
||||
|
||||
@@ -1,27 +1,50 @@
|
||||
/**
|
||||
* @file web/request/getAvatarDetail.ts
|
||||
* @description 获取角色详情相关请求函数
|
||||
* @since Beta v0.5.3
|
||||
* @since Beta v0.6.1
|
||||
*/
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 手动刷新角色数据
|
||||
* @since Beta v0.6.1
|
||||
* @param {TGApp.App.Account.Cookie} cookie Cookie
|
||||
* @param {TGApp.Sqlite.Account.Game} user 用户
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function getAvatarIndex(
|
||||
cookie: TGApp.App.Account.Cookie,
|
||||
user: TGApp.Sqlite.Account.Game,
|
||||
): Promise<TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.getUserBase;
|
||||
const params = { avatar_list_type: 1, role_id: user.gameUid, server: user.region };
|
||||
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
|
||||
const header = TGUtils.User.getHeader(ck, "GET", params, "common");
|
||||
return await TGHttp<TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取角色列表
|
||||
* @since Beta v0.5.3
|
||||
* @param {Record<string, string>} cookie Cookie
|
||||
* @param {string} roleId 用户 uid
|
||||
* @since Beta v0.6.1
|
||||
* @param {TGApp.App.Account.Cookie} cookie Cookie
|
||||
* @param {TGApp.Sqlite.Account.Game} user 用户
|
||||
* @return {Promise<TGApp.Game.Avatar.Avatar[]|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getAvatarList(
|
||||
cookie: Record<string, string>,
|
||||
roleId: string,
|
||||
cookie: TGApp.App.Account.Cookie,
|
||||
user: TGApp.Sqlite.Account.Game,
|
||||
): Promise<TGApp.Game.Avatar.Avatar[] | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.byCookie.getAvatarList;
|
||||
const data = { role_id: roleId, server: TGUtils.Tools.getServerByUid(roleId) };
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", data, "common");
|
||||
const data = { role_id: user.gameUid, server: user.region };
|
||||
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
|
||||
const header = TGUtils.User.getHeader(ck, "POST", data, "common");
|
||||
const resp = await TGHttp<TGApp.Game.Avatar.ListResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
@@ -33,24 +56,21 @@ export async function getAvatarList(
|
||||
|
||||
/**
|
||||
* @description 获取角色详情
|
||||
* @since Beta v0.5.3
|
||||
* @param {Record<string, string>} cookie Cookie
|
||||
* @param {string} roleId 用户 uid
|
||||
* @since Beta v0.6.1
|
||||
* @param {TGApp.App.Account.Cookie} cookie Cookie
|
||||
* @param {TGApp.Sqlite.Account.Game} user 用户
|
||||
* @param {string[]} avatarIds 角色 id 列表
|
||||
* @return {Promise<TGApp.Game.Avatar.AvatarDetail|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getAvatarDetail(
|
||||
cookie: Record<string, string>,
|
||||
roleId: string,
|
||||
cookie: TGApp.App.Account.Cookie,
|
||||
user: TGApp.Sqlite.Account.Game,
|
||||
avatarIds: string[],
|
||||
): Promise<TGApp.Game.Avatar.AvatarDetail | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.byCookie.getAvatarDetail;
|
||||
const data = {
|
||||
role_id: roleId,
|
||||
server: TGUtils.Tools.getServerByUid(roleId),
|
||||
character_ids: avatarIds,
|
||||
};
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", data, "common");
|
||||
const data = { role_id: user.gameUid, server: user.region, character_ids: avatarIds };
|
||||
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
|
||||
const header = TGUtils.User.getHeader(ck, "POST", data, "common");
|
||||
const resp = await TGHttp<TGApp.Game.Avatar.DetailResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
|
||||
Reference in New Issue
Block a user