mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-19 10:23:21 +08:00
♻️ showConfirm重构
This commit is contained in:
@@ -59,7 +59,7 @@ import { writeTextFile } from "@tauri-apps/plugin-fs";
|
||||
import { onMounted, ref, watch, computed, onUnmounted } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
import showConfirm from "../../components/func/confirm.js";
|
||||
import showDialog from "../../components/func/dialog.js";
|
||||
import showSnackbar from "../../components/func/snackbar.js";
|
||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||
import TuaAchiList from "../../components/userAchi/tua-achi-list.vue";
|
||||
@@ -151,12 +151,7 @@ async function importJson(): Promise<void> {
|
||||
}
|
||||
const check = await verifyUiafData(selectedFile);
|
||||
if (!check) return;
|
||||
let uidInput = await showConfirm({
|
||||
mode: "input",
|
||||
title: "请输入存档UID",
|
||||
text: "UID:",
|
||||
input: uidCur.value.toString(),
|
||||
});
|
||||
let uidInput = await showDialog.input("请输入存档UID", "UID:", uidCur.value.toString());
|
||||
if (uidInput === false) {
|
||||
showSnackbar.cancel("已取消存档导入");
|
||||
return;
|
||||
@@ -211,25 +206,16 @@ async function exportJson(): Promise<void> {
|
||||
|
||||
async function handleImportOuter(app: string): Promise<void> {
|
||||
await TGLogger.Info(`[Achievements][handleImportOuter] 导入来源:${app}`);
|
||||
const confirm = await showConfirm({
|
||||
title: "是否导入祈愿数据?",
|
||||
text: `来源APP:${app}`,
|
||||
});
|
||||
if (!confirm) {
|
||||
const importCheck = await showDialog.check("是否导入祈愿数据?", `来源APP:${app}`);
|
||||
if (!importCheck) {
|
||||
showSnackbar.cancel("已取消导入");
|
||||
await TGLogger.Info("[Achievements][handleImportOuter] 已取消导入");
|
||||
return;
|
||||
}
|
||||
// 读取 剪贴板
|
||||
const clipboard = await window.navigator.clipboard.readText();
|
||||
const check = await verifyUiafDataClipboard();
|
||||
if (!check) return;
|
||||
let uidInput = await showConfirm({
|
||||
mode: "input",
|
||||
title: "请输入存档UID",
|
||||
text: "UID:",
|
||||
input: uidCur.value.toString(),
|
||||
});
|
||||
let uidInput = await showDialog.input("请输入存档UID", "UID:", uidCur.value.toString());
|
||||
if (uidInput === false) {
|
||||
showSnackbar.cancel("已取消存档导入");
|
||||
return;
|
||||
@@ -250,11 +236,7 @@ async function handleImportOuter(app: string): Promise<void> {
|
||||
}
|
||||
|
||||
async function createUid(): Promise<void> {
|
||||
const uidInput = await showConfirm({
|
||||
mode: "input",
|
||||
title: "请输入新存档UID",
|
||||
text: "UID:",
|
||||
});
|
||||
const uidInput = await showDialog.input("请输入新存档UID", "UID:");
|
||||
if (uidInput === undefined || uidInput === false) {
|
||||
showSnackbar.cancel("已取消");
|
||||
return;
|
||||
@@ -273,11 +255,11 @@ async function createUid(): Promise<void> {
|
||||
}
|
||||
|
||||
async function deleteUid(): Promise<void> {
|
||||
const uidInput = await showConfirm({
|
||||
title: "确定删除该存档?",
|
||||
text: `确认则清空存档-${uidCur.value}对应数据`,
|
||||
});
|
||||
if (uidInput === undefined || !uidInput) {
|
||||
const delCheck = await showDialog.check(
|
||||
"确定删除该存档?",
|
||||
`确认则清空存档-${uidCur.value}对应数据`,
|
||||
);
|
||||
if (!delCheck) {
|
||||
showSnackbar.cancel("已取消删除存档");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ import TcDataDir from "../../components/config/tc-dataDir.vue";
|
||||
import TcGameBadge from "../../components/config/tc-gameBadge.vue";
|
||||
import TcInfo from "../../components/config/tc-info.vue";
|
||||
import TcUserBadge from "../../components/config/tc-userBadge.vue";
|
||||
import showConfirm from "../../components/func/confirm.js";
|
||||
import showDialog from "../../components/func/dialog.js";
|
||||
import showSnackbar from "../../components/func/snackbar.js";
|
||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||
import TGSqlite from "../../plugins/Sqlite/index.js";
|
||||
@@ -162,16 +162,13 @@ onMounted(async () => {
|
||||
|
||||
// 备份数据
|
||||
async function confirmBackup(): Promise<void> {
|
||||
const res = await showConfirm({
|
||||
title: "是否备份到默认路径",
|
||||
text: "取消则自选路径,点击外部不做处理",
|
||||
});
|
||||
if (res === undefined) {
|
||||
const bcCheck = await showDialog.check("是否备份到默认路径", "取消则自选路径,点击外部不做处理");
|
||||
if (bcCheck === undefined) {
|
||||
showSnackbar.cancel("已取消备份");
|
||||
return;
|
||||
}
|
||||
let saveDir = appStore.userDir;
|
||||
if (!res) {
|
||||
if (!bcCheck) {
|
||||
const dir: string | null = await open({
|
||||
directory: true,
|
||||
defaultPath: saveDir,
|
||||
@@ -196,16 +193,13 @@ async function confirmBackup(): Promise<void> {
|
||||
|
||||
// 恢复数据
|
||||
async function confirmRestore(): Promise<void> {
|
||||
const resConfirm = await showConfirm({
|
||||
title: "是否从默认路径恢复",
|
||||
text: "取消则自选路径,点击外部不做处理",
|
||||
});
|
||||
if (resConfirm === undefined) {
|
||||
const rsCheck = await showDialog.check("是否从默认路径恢复", "取消则自选路径,点击外部不做处理");
|
||||
if (rsCheck === undefined) {
|
||||
showSnackbar.cancel("已取消恢复");
|
||||
return;
|
||||
}
|
||||
let saveDir = appStore.userDir;
|
||||
if (!resConfirm) {
|
||||
if (!rsCheck) {
|
||||
const dir: string | null = await open({
|
||||
directory: true,
|
||||
defaultPath: saveDir,
|
||||
@@ -231,8 +225,8 @@ async function confirmRestore(): Promise<void> {
|
||||
|
||||
// 更新数据
|
||||
async function confirmUpdate(title?: string): Promise<void> {
|
||||
const res = await showConfirm({ title: title ?? "确认更新数据吗?", text: "请确保存在备份数据" });
|
||||
if (!res) {
|
||||
const updateCheck = await showDialog.check(title ?? "确认更新数据吗?");
|
||||
if (!updateCheck) {
|
||||
showSnackbar.cancel("已取消更新数据库");
|
||||
return;
|
||||
}
|
||||
@@ -250,11 +244,11 @@ async function confirmUpdate(title?: string): Promise<void> {
|
||||
async function confirmUpdateDevice(force?: boolean): Promise<void> {
|
||||
if (force !== undefined && force) {
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice][force] 开始强制更新设备信息");
|
||||
const resF = await showConfirm({
|
||||
title: "确认强制更新设备信息吗?",
|
||||
text: `DeviceFp:${appStore.deviceInfo.device_fp}`,
|
||||
});
|
||||
if (!resF) {
|
||||
const forceCheck = await showDialog.check(
|
||||
"确认强制更新设备信息吗?",
|
||||
`DeviceFp:${appStore.deviceInfo.device_fp}`,
|
||||
);
|
||||
if (!forceCheck) {
|
||||
showSnackbar.cancel("已取消强制更新设备信息");
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice][force] 取消强制更新设备信息");
|
||||
return;
|
||||
@@ -274,8 +268,8 @@ async function confirmUpdateDevice(force?: boolean): Promise<void> {
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice] 开始更新设备信息");
|
||||
const localFp = getDeviceInfo("device_fp");
|
||||
if (localFp !== "0000000000000") {
|
||||
const res = await showConfirm({ title: "确认更新设备信息吗?", text: `DeviceFp:${localFp}` });
|
||||
if (!res) {
|
||||
const updateCheck = await showDialog.check("确认更新设备信息吗?", `DeviceFp:${localFp}`);
|
||||
if (!updateCheck) {
|
||||
showSnackbar.cancel("已取消更新设备信息");
|
||||
await TGLogger.Info("[Config][confirmUpdateDevice] 取消更新设备信息");
|
||||
return;
|
||||
@@ -312,11 +306,11 @@ async function confirmDelCache(): Promise<void> {
|
||||
}
|
||||
cacheSize.value = cacheBSize;
|
||||
loading.value = false;
|
||||
const res = await showConfirm({
|
||||
title: "确认清除缓存吗?",
|
||||
text: `当前缓存大小为 ${bytesToSize(cacheBSize)}`,
|
||||
});
|
||||
if (!res) {
|
||||
const delCheck = await showDialog.check(
|
||||
"确认清除缓存吗?",
|
||||
`当前缓存大小为 ${bytesToSize(cacheBSize)}`,
|
||||
);
|
||||
if (!delCheck) {
|
||||
showSnackbar.cancel("已取消清除缓存");
|
||||
await TGLogger.Info("[Config][confirmDelCache] 取消清除缓存");
|
||||
return;
|
||||
@@ -335,8 +329,8 @@ async function confirmDelCache(): Promise<void> {
|
||||
// 恢复默认设置
|
||||
async function confirmResetApp(): Promise<void> {
|
||||
await TGLogger.Info("[Config][confirmResetApp] 开始恢复默认设置");
|
||||
const res = await showConfirm({ title: "确认恢复默认设置吗?" });
|
||||
if (!res) {
|
||||
const resetCheck = await showDialog.check("确认恢复默认设置吗?");
|
||||
if (!resetCheck) {
|
||||
showSnackbar.cancel("已取消恢复默认设置");
|
||||
await TGLogger.Info("[Config][confirmResetApp] 取消恢复默认设置");
|
||||
return;
|
||||
@@ -350,18 +344,14 @@ async function confirmResetApp(): Promise<void> {
|
||||
|
||||
// 前置
|
||||
async function tryShowReset(): Promise<void> {
|
||||
const res = await showConfirm({
|
||||
title: "请输入验证 Code",
|
||||
text: "请联系开发者获取",
|
||||
mode: "input",
|
||||
});
|
||||
if (!res) {
|
||||
const codeInput = await showDialog.input("请输入验证 Code", "请联系开发者获取");
|
||||
if (!codeInput) {
|
||||
showSnackbar.cancel("已取消");
|
||||
return;
|
||||
}
|
||||
const time = getBuildTime();
|
||||
const code = time.startsWith("dev.") ? "dev" : time;
|
||||
if (res === code || res === "reset1128") {
|
||||
if (codeInput === code || codeInput === "reset1128") {
|
||||
showReset.value = true;
|
||||
showSnackbar.success("已开启重置数据库选项");
|
||||
return;
|
||||
@@ -372,11 +362,11 @@ async function tryShowReset(): Promise<void> {
|
||||
// 重置数据库
|
||||
async function confirmResetDB(title?: string): Promise<void> {
|
||||
await TGLogger.Info("[Config][confirmResetDB] 开始重置数据库");
|
||||
const res = await showConfirm({
|
||||
title: title ?? "确认重置数据库吗?",
|
||||
text: "请确认已经备份关键数据",
|
||||
});
|
||||
if (!res) {
|
||||
const resetCheck = await showDialog.check(
|
||||
title ?? "确认重置数据库吗?",
|
||||
"请确认已经备份关键数据",
|
||||
);
|
||||
if (!resetCheck) {
|
||||
showSnackbar.cancel("已取消重置数据库");
|
||||
await TGLogger.Info("[Config][confirmResetDB] 取消重置数据库");
|
||||
return;
|
||||
|
||||
@@ -95,7 +95,7 @@ import { UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
|
||||
import showConfirm from "../../components/func/confirm.js";
|
||||
import showDialog from "../../components/func/dialog.js";
|
||||
import showSnackbar from "../../components/func/snackbar.js";
|
||||
import TPostCard from "../../components/main/t-postcard.vue";
|
||||
import ToCollectPost from "../../components/overlay/to-collectPost.vue";
|
||||
@@ -188,11 +188,7 @@ function toSelect() {
|
||||
|
||||
async function addCollect(): Promise<void> {
|
||||
let title, desc;
|
||||
const titleC = await showConfirm({
|
||||
mode: "input",
|
||||
title: "新建分类",
|
||||
text: "请输入分类名称",
|
||||
});
|
||||
const titleC = await showDialog.input("新建分类", "分类名称:");
|
||||
if (titleC === undefined || titleC === false) return;
|
||||
if (titleC === "未分类") {
|
||||
showSnackbar.warn("分类名不可为未分类");
|
||||
@@ -203,11 +199,7 @@ async function addCollect(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
title = titleC;
|
||||
const descC = await showConfirm({
|
||||
mode: "input",
|
||||
title: "新建分类",
|
||||
text: "请输入分类描述",
|
||||
});
|
||||
const descC = await showDialog.input("新建分类", "分类描述:");
|
||||
if (descC === false) return;
|
||||
if (descC === undefined) desc = title;
|
||||
else desc = descC;
|
||||
@@ -226,12 +218,7 @@ async function toEdit(): Promise<void> {
|
||||
showSnackbar.warn("未找到合集信息");
|
||||
return;
|
||||
}
|
||||
let cTc = await showConfirm({
|
||||
title: "修改分类标题",
|
||||
mode: "input",
|
||||
text: "请输入分类标题",
|
||||
input: collect.title,
|
||||
});
|
||||
let cTc = await showDialog.input("修改分类标题", "分类标题:", collect.title);
|
||||
if (cTc === false) {
|
||||
showSnackbar.cancel("取消修改分类信息");
|
||||
return;
|
||||
@@ -245,14 +232,9 @@ async function toEdit(): Promise<void> {
|
||||
showSnackbar.warn("分类名称重复");
|
||||
return;
|
||||
}
|
||||
let cTd = await showConfirm({
|
||||
title: "修改分类描述",
|
||||
mode: "input",
|
||||
text: "请输入分类描述",
|
||||
input: collect.desc,
|
||||
});
|
||||
let cTd = await showDialog.input("修改分类描述", "分类描述:", collect.desc);
|
||||
if (typeof cTd !== "string") cTd = collect.desc;
|
||||
const cc = await showConfirm({ title: "确定修改?", text: `[${cTc}] ${cTd}` });
|
||||
const cc = await showDialog.check("确定修改?", `[${cTc}] ${cTd}`);
|
||||
if (!cc) {
|
||||
showSnackbar.cancel("取消修改分类信息");
|
||||
return;
|
||||
@@ -280,11 +262,8 @@ async function deletePost(force: boolean = false): Promise<void> {
|
||||
return;
|
||||
}
|
||||
const title = force ? "删除帖子" : "移除帖子分类";
|
||||
const res = await showConfirm({
|
||||
title: `确定${title}?`,
|
||||
text: `共 ${selectedPost.value.length} 条帖子`,
|
||||
});
|
||||
if (!res) {
|
||||
const check = await showDialog.check(`确定${title}?`, `共 ${selectedPost.value.length} 条帖子`);
|
||||
if (!check) {
|
||||
showSnackbar.cancel("取消操作");
|
||||
return;
|
||||
}
|
||||
@@ -311,11 +290,11 @@ async function deleteCollect(force: boolean): Promise<void> {
|
||||
return;
|
||||
}
|
||||
const title = force ? "删除分类" : "清空分类";
|
||||
const res = await showConfirm({
|
||||
title: `确定${title}?`,
|
||||
text: `该分类下${selected.value.length}条帖子将被${force ? "删除" : "移除分类(未分类将被删除)"}`,
|
||||
});
|
||||
if (!res) {
|
||||
const check = await showDialog.check(
|
||||
`确定${title}?`,
|
||||
`该分类下 ${selected.value.length} 条帖子将被${force ? "删除" : "移除分类(未分类将被删除)"}`,
|
||||
);
|
||||
if (!check) {
|
||||
showSnackbar.cancel("取消操作");
|
||||
return;
|
||||
}
|
||||
@@ -377,17 +356,13 @@ watch(
|
||||
);
|
||||
|
||||
async function freshOther(): Promise<void> {
|
||||
const input = await showConfirm({
|
||||
mode: "input",
|
||||
title: "导入其他用户收藏",
|
||||
text: "请输入用户米游社UID",
|
||||
});
|
||||
if (typeof input === "string") {
|
||||
if (isNaN(Number(input))) {
|
||||
const uidInput = await showDialog.input("导入其他用户收藏", "米游社UID:");
|
||||
if (typeof uidInput === "string") {
|
||||
if (isNaN(Number(uidInput))) {
|
||||
showSnackbar.warn("UID 格式错误,请输入数字");
|
||||
return;
|
||||
}
|
||||
await freshUser(input);
|
||||
await freshUser(uidInput);
|
||||
return;
|
||||
}
|
||||
showSnackbar.cancel("取消导入");
|
||||
|
||||
Reference in New Issue
Block a user