diff --git a/src/pages/User/Gacha.vue b/src/pages/User/Gacha.vue
index 25851a63..ef229f2e 100644
--- a/src/pages/User/Gacha.vue
+++ b/src/pages/User/Gacha.vue
@@ -4,7 +4,12 @@
祈愿记录
- 刷新
+ 增量刷新
+ 全量刷新
导入
导出
@@ -99,7 +104,7 @@ onMounted(async () => {
});
// 刷新按钮点击事件
-async function confirmRefresh(): Promise {
+async function confirmRefresh(force: boolean = false): Promise {
await TGLogger.Info(`[UserGacha][${account.gameUid}][confirmRefresh] 刷新祈愿数据`);
const confirmRes = await showConfirm({
title: "是否刷新祈愿数据?",
@@ -145,18 +150,34 @@ async function confirmRefresh(): Promise {
loading.value = false;
return;
}
+ let checkList: Array = [
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ ];
+ if (force) {
+ loadingTitle.value = "正在获取数据库祈愿最新 ID";
+ checkList[0] = await TGSqlite.getGachaCheck(account.gameUid, "200");
+ checkList[1] = await TGSqlite.getGachaCheck(account.gameUid, "301");
+ checkList[2] = await TGSqlite.getGachaCheck(account.gameUid, "400");
+ checkList[3] = await TGSqlite.getGachaCheck(account.gameUid, "302");
+ checkList[4] = await TGSqlite.getGachaCheck(account.gameUid, "500");
+ }
+ console.log(checkList);
loadingTitle.value = "正在刷新新手祈愿数据";
- await getGachaLogs("100");
+ await getGachaLogs("100", "0", undefined);
loadingTitle.value = "正在刷新常驻祈愿数据";
- await getGachaLogs("200");
+ await getGachaLogs("200", "0", checkList[0]);
loadingTitle.value = "正在刷新角色祈愿数据";
- await getGachaLogs("301");
+ await getGachaLogs("301", "0", checkList[1]);
loadingTitle.value = "正在刷新角色祈愿2数据";
- await getGachaLogs("400");
+ await getGachaLogs("400", "0", checkList[2]);
loadingTitle.value = "正在刷新武器祈愿数据";
- await getGachaLogs("302");
+ await getGachaLogs("302", "0", checkList[3]);
loadingTitle.value = "正在刷新集录祈愿数据";
- await getGachaLogs("500");
+ await getGachaLogs("500", "0", checkList[4]);
loadingTitle.value = "数据获取完成,即将刷新页面";
loadingSub.value = "";
loading.value = false;
@@ -166,11 +187,15 @@ async function confirmRefresh(): Promise {
}, 1000);
});
await TGLogger.Info(`[UserGacha][${account.gameUid}][confirmRefresh] 刷新祈愿数据完成`);
- window.location.reload();
+ // window.location.reload();
}
// 获取祈愿数据并写入数据库
-async function getGachaLogs(pool: string, endId: string = "0"): Promise {
+async function getGachaLogs(
+ pool: string,
+ endId: string = "0",
+ check: string | undefined,
+): Promise {
await TGLogger.Info(
`[UserGacha][${account.gameUid}][getGachaLogs] 获取祈愿数据,pool:${pool},endId:${endId}`,
);
@@ -180,6 +205,14 @@ async function getGachaLogs(pool: string, endId: string = "0"): Promise {
await TGLogger.Info(
`[UserGacha][${account.gameUid}][getGachaLogs] 成功获取到 ${gachaRes.length} 条祈愿数据`,
);
+ if (gachaRes.length === 0) {
+ await new Promise((resolve) => {
+ setTimeout(() => {
+ resolve("");
+ }, 1000);
+ });
+ return;
+ }
const uigfList: TGApp.Plugins.UIGF.GachaItem[] = [];
gachaRes.forEach((item) => {
loadingSub.value = `[${item.item_type}][${item.time}] ${item.name}`;
@@ -204,13 +237,21 @@ async function getGachaLogs(pool: string, endId: string = "0"): Promise {
uigfList.push(tempItem);
});
await TGSqlite.mergeUIGF(account.gameUid, uigfList);
+ if (check !== undefined && gachaRes.some((i) => i.id === check)) {
+ await new Promise((resolve) => {
+ setTimeout(() => {
+ resolve("");
+ }, 1000);
+ });
+ return;
+ }
if (gachaRes.length === 20) {
await new Promise((resolve) => {
setTimeout(() => {
resolve("");
}, 1000);
});
- await getGachaLogs(pool, gachaRes[gachaRes.length - 1].id);
+ await getGachaLogs(pool, gachaRes[gachaRes.length - 1].id, check);
}
} else {
showSnackbar({
diff --git a/src/plugins/Sqlite/index.ts b/src/plugins/Sqlite/index.ts
index 26b79594..1b518c5d 100644
--- a/src/plugins/Sqlite/index.ts
+++ b/src/plugins/Sqlite/index.ts
@@ -471,6 +471,26 @@ class Sqlite {
if (res.length === 0) return false;
return res.map((item) => item.name).join("、");
}
+
+ /**
+ * @description 用于检测祈愿增量更新的 gacha id
+ * @since Beta v0.4.4
+ * @param {string} uid 用户 uid
+ * @param {string} type 卡池类型
+ * @returns {Promise}
+ */
+ async getGachaCheck(uid: string, type: string): Promise {
+ const db = await this.getDB();
+ const sql = `SELECT id
+ FROM GachaRecords
+ WHERE uid = '${uid}'
+ AND gachaType = '${type}'
+ ORDER BY id DESC
+ LIMIT 1;`;
+ const res: Array<{ id: string }> = await db.select(sql);
+ if (res.length === 0) return undefined;
+ return res[0].id;
+ }
}
const TGSqlite = new Sqlite();