🐛 修复首页启动卡数据库加载

fix #79
This commit is contained in:
目棃
2024-01-17 12:15:25 +08:00
parent ffd0651ea4
commit 802b9de645
2 changed files with 29 additions and 18 deletions

View File

@@ -81,23 +81,34 @@ async function listenOnInit(): Promise<void> {
}
async function checkAppLoad(): Promise<void> {
const checkDB = await TGSqlite.check();
if (!appStore.loading) {
await resetDB();
return;
}
let checkDB = false;
try {
checkDB = await TGSqlite.check();
} catch (error) {
console.error(error);
}
if (!checkDB) {
appStore.loading = false;
await TGSqlite.reset();
showSnackbar({
text: "检测到数据库不完整!已重置数据库!",
color: "error",
timeout: 3000,
});
await createDataDir();
router.go(0);
await resetDB();
} else {
appStore.loading = true;
console.info("数据库已加载!");
}
}
async function resetDB(): Promise<void> {
await TGSqlite.reset();
showSnackbar({
text: "检测到数据库不完整!已重置数据库!",
color: "error",
timeout: 3000,
});
await createDataDir();
appStore.loading = true;
}
// 检测 deviceFp
async function checkDeviceFp(): Promise<void> {
const appData = await TGSqlite.getAppData();
@@ -161,11 +172,13 @@ async function checkUserLoad(): Promise<void> {
const accountLocal = userStore.account.value;
const accountDB = await TGSqlite.getCurAccount();
if (accountDB === false) {
showSnackbar({
text: "获取 GameAccount 失败!请尝试更新数据库!",
color: "error",
timeout: 3000,
});
if (appStore.isLogin) {
showSnackbar({
text: "获取 GameAccount 失败!请尝试更新数据库!",
color: "error",
timeout: 3000,
});
}
return;
}
if (accountDB !== accountLocal) {

View File

@@ -36,7 +36,6 @@ function readLoading(): void {
let loadingMap = itemRefs.value.map((item) => {
return item.loading ? item.name : null;
});
if (!appStore.loading) loadingMap.push("数据库");
loadingSubtitle.value = "正在加载 " + loadingMap.filter((item) => item)?.join("、");
if (loadingMap.every((item) => !item)) {
loading.value = false;
@@ -45,7 +44,6 @@ function readLoading(): void {
onMounted(async () => {
loadingTitle.value = "正在加载首页";
loading.value = true;
const isProdEnv = import.meta.env.MODE === "production";
// 获取当前环境
if (isProdEnv && appStore.devMode) {