Skip to content

Commit

Permalink
🐛 修复数据未即时刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Oct 12, 2024
1 parent d735d0d commit 2e15296
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 27 deletions.
19 changes: 13 additions & 6 deletions src/pages/User/Characters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}] 获取角色列表失败`);
Expand All @@ -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}] 获取角色数据失败`);
Expand Down
5 changes: 3 additions & 2 deletions src/web/request/TGRequest.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* @file web/request/TGRequest.ts
* @description 应用用到的请求函数
* @since Beta v0.6.0
* @since Beta v0.6.1
*/

import { genAuthkey, genAuthkey2 } from "./genAuthkey.js";
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";
Expand Down Expand Up @@ -44,6 +44,7 @@ const TGRequest = {
getAbyss,
getAccounts: getGameAccountsByCookie,
getUserInfo: getUserInfoByCookie,
getAvatarIndex,
getAvatarList,
getAvatarDetail,
},
Expand Down
58 changes: 39 additions & 19 deletions src/web/request/getAvatarDetail.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 2e15296

Please sign in to comment.