♻️ 重构战绩数据请求逻辑,完善错误处理,适配新版本地图数据

This commit is contained in:
BTMuli
2026-04-09 01:39:56 +08:00
parent 6d34b7cb65
commit 2e8ec962b6
7 changed files with 208 additions and 70 deletions

View File

@@ -144,6 +144,7 @@ import { generateShareImg } from "@utils/TGShare.js";
import { storeToRefs } from "pinia";
import { onMounted, ref, shallowRef, watch } from "vue";
import { useRouter } from "vue-router";
import TGHttps from "@utils/TGHttps.js";
const router = useRouter();
const hutaoStore = useHutaoStore();
@@ -426,12 +427,25 @@ async function refreshAvatars(
ac: TGApp.Sqlite.Account.Game,
): Promise<boolean> {
await showLoading.update("正在更新角色数据");
const idxRes = await recordReq.index(ck, ac, 1);
if ("retcode" in idxRes) {
await showLoading.update("角色更新失败");
showSnackbar.error(`[${idxRes.retcode}] ${idxRes.message}`);
await TGLogger.Error(JSON.stringify(idxRes));
await showLoading.end();
// 更新战绩数据
let indexResp: TGApp.Game.Record.Resp | undefined;
try {
indexResp = await recordReq.index(ck, ac, 1);
if (indexResp.retcode !== 0) {
await showLoading.update("角色更新失败");
showSnackbar.error(`[${indexResp.retcode}] ${indexResp.message}`);
await TGLogger.Warn(`[Abyss][refreshAvatars] ${indexResp.retcode}-${indexResp.message}`);
await showLoading.end();
return false;
}
} catch (e) {
let errMsg = String(e);
if (TGHttps.isHttpErr(e)) {
errMsg = e.status ? `[${e.status}] ${e.statusText}` : e.message;
}
showSnackbar.error(`获取战绩数据异常: ${errMsg}`);
await TGLogger.Error(`[Record][refreshRecord] 获取战绩异常`);
await TGLogger.Error(`${e}`);
return false;
}
await showLoading.update("正在更新角色列表");

View File

@@ -175,6 +175,7 @@ import { storeToRefs } from "pinia";
import { computed, onMounted, ref, shallowRef, triggerRef, watch } from "vue";
import { AppCharacterData } from "@/data/index.js";
import TGHttps from "@utils/TGHttps.js";
type TabItem = { label: string; value: string };
type OverviewItem = { element: string; cnt: number; label: string };
@@ -420,13 +421,28 @@ async function refresh(): Promise<void> {
await TGLogger.Info(`[Character][refresh][${rfAccount.gameUid}] 正在更新角色数据`);
await showLoading.start(`正在更新${rfAccount.gameUid}的角色数据`);
loadData.value = true;
// 刷新战绩数据
await showLoading.update("正在刷新首页数据");
const indexRes = await recordReq.index(rfCk!, rfAccount, 1);
console.log(indexRes);
if ("retcode" in indexRes) {
showSnackbar.error(`[${indexRes.retcode}] ${indexRes.message}`);
await TGLogger.Error(JSON.stringify(indexRes));
let indexResp: TGApp.Game.Record.Resp | undefined;
try {
indexResp = await recordReq.index(rfCk!, rfAccount, 1);
console.debug("recordIndexResp", indexResp);
if (indexResp.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${indexResp.retcode}] ${indexResp.message}`);
await TGLogger.Warn(`[Characters] ${indexResp.retcode}-${indexResp.message}`);
loadData.value = false;
return;
}
} catch (e) {
await showLoading.end();
let errMsg = String(e);
if (TGHttps.isHttpErr(e)) {
errMsg = e.status ? `[${e.status}] ${e.statusText}` : e.message;
}
showSnackbar.error(`获取战绩数据异常: ${errMsg}`);
await TGLogger.Error(`[Characters][refresh] 获取战绩异常`);
await TGLogger.Error(`${e}`);
loadData.value = false;
return;
}

View File

@@ -89,6 +89,7 @@ import TGLogger from "@utils/TGLogger.js";
import { generateShareImg } from "@utils/TGShare.js";
import { storeToRefs } from "pinia";
import { onMounted, ref, shallowRef, watch } from "vue";
import TGHttps from "@utils/TGHttps.js";
const userStore = useUserStore();
const { account, cookie } = storeToRefs(userStore);
@@ -146,22 +147,37 @@ async function refreshRecord(): Promise<void> {
await showLoading.start(`正在刷新${rfAccount.gameUid}的战绩数据`);
await TGLogger.Info(`[UserRecord][refresh][${rfAccount.gameUid}] 刷新战绩数据`);
isRefresh.value = true;
const resp = await recordReq.index(rfCk!, rfAccount);
console.log(resp);
if ("retcode" in resp) {
await showLoading.end();
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await TGLogger.Error(`[UserRecord][refresh][${rfAccount.gameUid}] 获取战绩数据失败`);
await TGLogger.Error(
`[UserRecord][refresh][${rfAccount.gameUid}] ${resp.retcode} ${resp.message}`,
);
// 刷新战绩数据
let indexResp: TGApp.Game.Record.Resp | undefined;
try {
indexResp = await recordReq.index(rfCk!, rfAccount);
console.debug("recordIndexResp", indexResp);
if (indexResp.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${indexResp.retcode}] ${indexResp.message}`);
await TGLogger.Warn(`[UserRecord][refresh][${rfAccount.gameUid}] 获取战绩数据失败`);
await TGLogger.Warn(
`[UserRecord][refresh][${rfAccount.gameUid}] ${indexResp.retcode} ${indexResp.message}`,
);
isRefresh.value = false;
return;
}
} catch (e) {
let errMsg = String(e);
if (TGHttps.isHttpErr(e)) {
errMsg = e.status ? `[${e.status}] ${e.statusText}` : e.message;
}
showSnackbar.error(`获取战绩数据异常: ${errMsg}`);
await TGLogger.Error(`[Record][refreshRecord] 获取战绩异常`);
await TGLogger.Error(`${e}`);
isRefresh.value = false;
return;
}
if (!indexResp) return;
await TGLogger.Info(`[UserRecord][refresh][${rfAccount.gameUid}] 获取战绩数据成功`);
await TGLogger.Info(`[UserRecord][refresh][${rfAccount.gameUid}]`, false);
await showLoading.update("正在保存战绩数据");
await TSUserRecord.saveRecord(Number(rfAccount.gameUid), resp);
await TSUserRecord.saveRecord(Number(rfAccount.gameUid), indexResp.data);
await showLoading.update("正在加载战绩数据");
await loadUid(rfAccount.gameUid);
await loadRecord();