🐛 修复数据未即时刷新

This commit is contained in:
目棃
2024-10-12 10:58:47 +08:00
parent d735d0d098
commit 2e152965df
3 changed files with 55 additions and 27 deletions

View File

@@ -280,11 +280,14 @@ async function refresh(): Promise<void> {
loadData.value = false; loadData.value = false;
return; return;
} }
const cookie = { const indexRes = await TGRequest.User.byCookie.getAvatarIndex(userStore.cookie.value, user.value);
account_id: userStore.cookie.value.account_id, if (indexRes.retcode !== 0) {
cookie_token: userStore.cookie.value.cookie_token, showSnackbar({ text: `[${indexRes.retcode}] ${indexRes.message}` });
}; loading.value = false;
const listRes = await TGRequest.User.byCookie.getAvatarList(cookie, user.value.gameUid); loadData.value = false;
return;
}
const listRes = await TGRequest.User.byCookie.getAvatarList(userStore.cookie.value, user.value);
if (!Array.isArray(listRes)) { if (!Array.isArray(listRes)) {
showSnackbar({ text: `[${listRes.retcode}] ${listRes.message}`, color: "error" }); showSnackbar({ text: `[${listRes.retcode}] ${listRes.message}`, color: "error" });
await TGLogger.Error(`[Character][refreshRoles][${user.value.gameUid}] 获取角色列表失败`); 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()); const idList = listRes.map((i) => i.id.toString());
loadingTitle.value = "正在获取角色数据"; loadingTitle.value = "正在获取角色数据";
loadingSub.value = `${idList.length}个角色`; 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) { if ("retcode" in res) {
showSnackbar({ text: `[${res.retcode}] ${res.message}`, color: "error" }); showSnackbar({ text: `[${res.retcode}] ${res.message}`, color: "error" });
await TGLogger.Error(`[Character][refreshRoles][${user.value.gameUid}] 获取角色数据失败`); await TGLogger.Error(`[Character][refreshRoles][${user.value.gameUid}] 获取角色数据失败`);

View File

@@ -1,7 +1,7 @@
/** /**
* @file web/request/TGRequest.ts * @file web/request/TGRequest.ts
* @description 应用用到的请求函数 * @description 应用用到的请求函数
* @since Beta v0.6.0 * @since Beta v0.6.1
*/ */
import { genAuthkey, genAuthkey2 } from "./genAuthkey.js"; import { genAuthkey, genAuthkey2 } from "./genAuthkey.js";
@@ -9,7 +9,7 @@ import { getAbyss } from "./getAbyss.js";
import { getActionTicketBySToken } from "./getActionTicket.js"; import { getActionTicketBySToken } from "./getActionTicket.js";
import { getAnnoContent, getAnnoList } from "./getAnno.js"; import { getAnnoContent, getAnnoList } from "./getAnno.js";
import getAuthTicket from "./getAuthTicket.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 getCode from "./getCode.js";
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken.js"; import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken.js";
import { getDeviceFp } from "./getDeviceFp.js"; import { getDeviceFp } from "./getDeviceFp.js";
@@ -44,6 +44,7 @@ const TGRequest = {
getAbyss, getAbyss,
getAccounts: getGameAccountsByCookie, getAccounts: getGameAccountsByCookie,
getUserInfo: getUserInfoByCookie, getUserInfo: getUserInfoByCookie,
getAvatarIndex,
getAvatarList, getAvatarList,
getAvatarDetail, getAvatarDetail,
}, },

View File

@@ -1,27 +1,50 @@
/** /**
* @file web/request/getAvatarDetail.ts * @file web/request/getAvatarDetail.ts
* @description 获取角色详情相关请求函数 * @description 获取角色详情相关请求函数
* @since Beta v0.5.3 * @since Beta v0.6.1
*/ */
import TGHttp from "../../utils/TGHttp.js"; import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js"; import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.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 获取角色列表 * @description 获取角色列表
* @since Beta v0.5.3 * @since Beta v0.6.1
* @param {Record<string, string>} cookie Cookie * @param {TGApp.App.Account.Cookie} cookie Cookie
* @param {string} roleId 用户 uid * @param {TGApp.Sqlite.Account.Game} user 用户
* @return {Promise<TGApp.Game.Avatar.Avatar[]|TGApp.BBS.Response.Base>} * @return {Promise<TGApp.Game.Avatar.Avatar[]|TGApp.BBS.Response.Base>}
*/ */
export async function getAvatarList( export async function getAvatarList(
cookie: Record<string, string>, cookie: TGApp.App.Account.Cookie,
roleId: string, user: TGApp.Sqlite.Account.Game,
): Promise<TGApp.Game.Avatar.Avatar[] | TGApp.BBS.Response.Base> { ): Promise<TGApp.Game.Avatar.Avatar[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getAvatarList; const url = TGApi.GameData.byCookie.getAvatarList;
const data = { role_id: roleId, server: TGUtils.Tools.getServerByUid(roleId) }; const data = { role_id: user.gameUid, server: user.region };
const header = TGUtils.User.getHeader(cookie, "POST", data, "common"); 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, { const resp = await TGHttp<TGApp.Game.Avatar.ListResponse | TGApp.BBS.Response.Base>(url, {
method: "POST", method: "POST",
body: JSON.stringify(data), body: JSON.stringify(data),
@@ -33,24 +56,21 @@ export async function getAvatarList(
/** /**
* @description 获取角色详情 * @description 获取角色详情
* @since Beta v0.5.3 * @since Beta v0.6.1
* @param {Record<string, string>} cookie Cookie * @param {TGApp.App.Account.Cookie} cookie Cookie
* @param {string} roleId 用户 uid * @param {TGApp.Sqlite.Account.Game} user 用户
* @param {string[]} avatarIds 角色 id 列表 * @param {string[]} avatarIds 角色 id 列表
* @return {Promise<TGApp.Game.Avatar.AvatarDetail|TGApp.BBS.Response.Base>} * @return {Promise<TGApp.Game.Avatar.AvatarDetail|TGApp.BBS.Response.Base>}
*/ */
export async function getAvatarDetail( export async function getAvatarDetail(
cookie: Record<string, string>, cookie: TGApp.App.Account.Cookie,
roleId: string, user: TGApp.Sqlite.Account.Game,
avatarIds: string[], avatarIds: string[],
): Promise<TGApp.Game.Avatar.AvatarDetail | TGApp.BBS.Response.Base> { ): Promise<TGApp.Game.Avatar.AvatarDetail | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getAvatarDetail; const url = TGApi.GameData.byCookie.getAvatarDetail;
const data = { const data = { role_id: user.gameUid, server: user.region, character_ids: avatarIds };
role_id: roleId, const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
server: TGUtils.Tools.getServerByUid(roleId), const header = TGUtils.User.getHeader(ck, "POST", data, "common");
character_ids: avatarIds,
};
const header = TGUtils.User.getHeader(cookie, "POST", data, "common");
const resp = await TGHttp<TGApp.Game.Avatar.DetailResponse | TGApp.BBS.Response.Base>(url, { const resp = await TGHttp<TGApp.Game.Avatar.DetailResponse | TGApp.BBS.Response.Base>(url, {
method: "POST", method: "POST",
body: JSON.stringify(data), body: JSON.stringify(data),