Skip to content

Commit

Permalink
🚸 全量刷新时提升加载速度
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Jan 8, 2025
1 parent 98dea9d commit c7b1398
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pages/User/Gacha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ async function refreshGachaPool(
let endId = "0";
let reqId = "0";
let gachaDataMap: Record<string, string[]> | undefined = undefined;
let page = 0;
await showLoading.start(`正在刷新${label}数据`);
if (!force) endId = (await TSUserGacha.getGachaCheck(account.value.gameUid, type)) ?? "0";
while (true) {
page++;
const gachaRes = await Hk4eApi.gacha(authkey.value, type, reqId);
if (!Array.isArray(gachaRes)) {
showSnackbar.error(`[${type}][${gachaRes.retcode}] ${gachaRes.message}`);
Expand All @@ -186,6 +188,7 @@ async function refreshGachaPool(
await TGLogger.Error(
`[UserGacha][${account.value.gameUid}][refreshGachaPool] ${gachaRes.retcode} ${gachaRes.message}`,
);
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
break;
}
if (gachaRes.length === 0) {
Expand All @@ -198,8 +201,11 @@ async function refreshGachaPool(
break;
}
const uigfList: TGApp.Plugins.UIGF.GachaItem[] = [];
if (force) await showLoading.update(`[${label}] 第${page}页,${gachaRes.length}条`);
for (const item of gachaRes) {
await showLoading.update(`[${item.item_type}][${item.time}] ${item.name}`);
if (!force) {
await showLoading.update(`[${item.item_type}][${item.time}] ${item.name}`);
}
const tempItem: TGApp.Plugins.UIGF.GachaItem = {
gacha_type: item.gacha_type,
item_id: item.item_id,
Expand Down Expand Up @@ -228,6 +234,7 @@ async function refreshGachaPool(
await TSUserGacha.mergeUIGF(account.value.gameUid, uigfList);
if (!force && gachaRes.some((i) => i.id.toString() === endId.toString())) break;
reqId = gachaRes[gachaRes.length - 1].id.toString();
if (force) await new Promise<void>((resolve) => setTimeout(resolve, 1000));
}
}
Expand Down

0 comments on commit c7b1398

Please sign in to comment.