From 09317afac6d6611bdeabbad42dd1568ca1de4c40 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Fri, 1 Sep 2023 09:39:14 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E7=A5=88=E6=84=BF?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8D=95=E7=8B=AC=E5=A4=87=E4=BB=BD=E3=80=81?= =?UTF-8?q?=E6=81=A2=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/gachaRecord/gro-dataview.vue | 2 + src/pages/User/Gacha.vue | 158 ++++++++++++++++++-- src/pages/common/Config.vue | 30 +--- src/plugins/Sqlite/index.ts | 15 +- 4 files changed, 162 insertions(+), 43 deletions(-) diff --git a/src/components/gachaRecord/gro-dataview.vue b/src/components/gachaRecord/gro-dataview.vue index 9a7f163d..d9f5930c 100644 --- a/src/components/gachaRecord/gro-dataview.vue +++ b/src/components/gachaRecord/gro-dataview.vue @@ -149,6 +149,8 @@ function getTitle(type: "top" | "5" | "4" | "3"): string { if (props.dataType === "weapon") return "武器祈愿"; if (props.dataType === "normal") return "常驻祈愿"; return ""; + } else if (props.dataVal.length === 0) { + return "暂无数据"; } else if (type === "5") { // 5星物品统计 00.00% return `${star5List.value.length} [${((star5List.value.length * 100) / props.dataVal.length) diff --git a/src/pages/User/Gacha.vue b/src/pages/User/Gacha.vue index 570931a7..99403c68 100644 --- a/src/pages/User/Gacha.vue +++ b/src/pages/User/Gacha.vue @@ -2,7 +2,7 @@ @@ -22,6 +24,20 @@ 图表概览 数据概览 +
+ + mdi-cloud-download + 备份 + + + mdi-delete + 删除 + + + mdi-cloud-upload + 恢复 + +
@@ -42,9 +58,9 @@ import ToLoading from "../../components/overlay/to-loading.vue"; import GroEcharts from "../../components/gachaRecord/gro-echarts.vue"; import GroOverview from "../../components/gachaRecord/gro-overview.vue"; // tauri -import { dialog } from "@tauri-apps/api"; +import { dialog, path } from "@tauri-apps/api"; // utils -import { exportUigfData, readUigfData, verifyUigfData } from "../../utils/UIGF"; +import { backupUigfData, exportUigfData, readUigfData, verifyUigfData } from "../../utils/UIGF"; import TGSqlite from "../../plugins/Sqlite"; // loading @@ -80,16 +96,30 @@ onMounted(async () => { }); // 导入按钮点击事件 -async function handleImportBtn(): Promise { - const selectedFile = await dialog.open({ - multiple: false, - filters: [ - { - name: "UIGF", - extensions: ["json"], - }, - ], - }); +async function handleImportBtn(savePath?: string): Promise { + let selectedFile; + if (savePath) { + selectedFile = await dialog.open({ + multiple: false, + filters: [ + { + name: "UIGF", + extensions: ["json"], + }, + ], + defaultPath: savePath, + }); + } else { + selectedFile = await dialog.open({ + multiple: false, + filters: [ + { + name: "UIGF", + extensions: ["json"], + }, + ], + }); + } if (selectedFile) { const check = await verifyUigfData(selectedFile); if (!check) { @@ -125,6 +155,9 @@ async function handleImportBtn(): Promise { showSnackbar({ text: `成功导入 ${remoteData.list.length} 条祈愿数据`, }); + setTimeout(() => { + window.location.reload(); + }, 1000); } } else { showSnackbar({ @@ -180,6 +213,88 @@ async function handleExportBtn(): Promise { }); } +// 恢复UID祈愿数据,相当于导入祈愿数据,不过目录固定 +async function restoreGacha(): Promise { + const backupPath = `${await path.appLocalDataDir()}userData`; + await handleImportBtn(backupPath); +} + +// 备份当前 UID 的祈愿数据 +async function backupGacha(): Promise { + if (gachaListCur.value.length === 0) { + showSnackbar({ + color: "error", + text: `暂无祈愿数据`, + }); + return; + } + const res = await showConfirm({ + title: `是否备份祈愿数据?`, + text: `UID:${uidCur.value},共 ${gachaListCur.value.length} 条数据`, + }); + if (!res) { + showSnackbar({ + color: "grey", + text: `已取消祈愿数据备份`, + }); + return; + } + loadingTitle.value = "正在备份祈愿数据"; + loading.value = true; + await backupUigfData(uidCur.value, gachaListCur.value); + loading.value = false; + showSnackbar({ + text: `已成功备份 ${uidCur.value} 的祈愿数据`, + }); +} + +// 删除当前 UID 的祈愿数据 +async function deleteGacha(): Promise { + if (gachaListCur.value.length === 0) { + showSnackbar({ + color: "error", + text: `暂无祈愿数据`, + }); + return; + } + const firstConfirm = await showConfirm({ + title: `是否删除祈愿数据?`, + text: `UID:${uidCur.value},共 ${gachaListCur.value.length} 条数据`, + }); + if (!firstConfirm) { + showSnackbar({ + color: "grey", + text: `已取消祈愿数据删除`, + }); + return; + } + const uidList = await TGSqlite.getUidList(); + let secondConfirm: string | boolean = ""; + if (uidList.length <= 1) { + secondConfirm = await showConfirm({ + title: "删除后数据库将为空,确定删除?", + text: `UID:${uidCur.value},共 ${gachaListCur.value.length} 条数据`, + }); + } + if (secondConfirm === false) { + showSnackbar({ + color: "grey", + text: `已取消祈愿数据删除`, + }); + return; + } + loadingTitle.value = `正在删除${uidCur.value}的祈愿数据`; + loading.value = true; + await TGSqlite.deleteGachaRecords(uidCur.value); + loading.value = false; + showSnackbar({ + text: `已成功删除 ${uidCur.value} 的祈愿数据`, + }); + setTimeout(() => { + window.location.reload(); + }, 1000); +} + // 监听 UID 变化 watch(uidCur, async (newUid) => { gachaListCur.value = await TGSqlite.getGachaRecords(newUid); @@ -225,6 +340,21 @@ watch(uidCur, async (newUid) => { font-family: var(--font-title); } +.gacha-tab-bottom { + position: absolute; + bottom: 0; + display: flex; + width: 100%; + flex-direction: column; + padding: 10px; + gap: 15px; +} + +.gacha-tab-btn { + background: var(--common-shadow-t-2); + color: var(--common-text-content); +} + .gacha-window { width: 100%; height: 100%; diff --git a/src/pages/common/Config.vue b/src/pages/common/Config.vue index 0f2e2c6a..302a80e4 100644 --- a/src/pages/common/Config.vue +++ b/src/pages/common/Config.vue @@ -196,7 +196,6 @@ import { useAchievementsStore } from "../../store/modules/achievements"; import { useUserStore } from "../../store/modules/user"; // utils import { backupUiafData, restoreUiafData } from "../../utils/UIAF"; -import { backupUigfData, restoreUigfData } from "../../utils/UIGF"; import { backupAbyssData, backupCookieData } from "../../web/utils/backupData"; import { restoreAbyssData, restoreCookieData } from "../../web/utils/restoreData"; import TGSqlite from "../../plugins/Sqlite"; @@ -354,7 +353,7 @@ async function confirmRefreshUser(): Promise { async function confirmBackup(): Promise { const res = await showConfirm({ title: "确认备份数据吗?", - text: "若已备份将会被覆盖", + text: "若已备份将会被覆盖,祈愿数据备份请到对应页面执行", }); if (!res) { showSnackbar({ @@ -377,15 +376,6 @@ async function confirmBackup(): Promise { const abyss = await TGSqlite.getAbyss(); loadingSub.value = "正在备份深渊数据"; await backupAbyssData(abyss); - if (userInfo.value.uid === "-1") { - loadingSub.value = "用户未登录,跳过祈愿数据备份"; - } else { - loadingSub.value = "正在获取祈愿数据"; - const gameUid = userStore.getCurAccount().gameUid; - const gacha = await TGSqlite.getGachaRecords(gameUid); - loadingSub.value = "正在备份祈愿数据"; - await backupUigfData(gameUid, gacha); - } loadingSub.value = ""; loading.value = false; showSnackbar({ text: "数据已备份!" }); @@ -395,7 +385,7 @@ async function confirmBackup(): Promise { async function confirmRestore(): Promise { const resConfirm = await showConfirm({ title: "确认恢复数据吗?", - text: "请确保存在备份数据", + text: "请确保存在备份数据,祈愿数据恢复请到对应页面执行", }); if (!resConfirm) { showSnackbar({ @@ -423,22 +413,6 @@ async function confirmRestore(): Promise { if (!res) { fail.push("深渊数据"); } - if (userInfo.value.uid === "-1") { - showSnackbar({ - color: "grey", - text: "用户未登录,跳过祈愿数据恢复", - }); - await new Promise(() => { - setTimeout(() => {}, 1500); - }); - } else { - loadingSub.value = "正在恢复祈愿数据"; - const gameUid = userStore.getCurAccount().gameUid; - res = await restoreUigfData(gameUid); - if (!res) { - fail.push("祈愿数据"); - } - } fail.length > 0 ? showSnackbar({ text: `${fail.join("、")} 恢复失败!`, color: "error" }) : showSnackbar({ text: "数据已恢复!" }); diff --git a/src/plugins/Sqlite/index.ts b/src/plugins/Sqlite/index.ts index a98255c1..e5db3dd1 100644 --- a/src/plugins/Sqlite/index.ts +++ b/src/plugins/Sqlite/index.ts @@ -2,7 +2,7 @@ * @file plugins Sqlite index.ts * @description Sqlite 数据库操作类 * @author BTMuli - * @since Alpha v0.2.3 + * @since Beta v0.3.0 */ // tauri @@ -497,6 +497,19 @@ class Sqlite { return res; } + /** + * @description 删除指定 uid 的祈愿数据 + * @since Beta v0.3.0 + * @param {string} uid 用户 uid + * @returns {Promise} + */ + public async deleteGachaRecords(uid: string): Promise { + const db = await Database.load(this.dbPath); + const sql = `DELETE FROM GachaRecords WHERE uid = '${uid}'`; + await db.execute(sql); + await db.close(); + } + /** * @description 合并祈愿数据 * @since Alpha v0.2.3