Skip to content

Commit

Permalink
🐛 应用初次加载也加载数据库,完善数据库 load #40
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Sep 15, 2023
1 parent a7dd069 commit 0c2d4d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useAppStore } from "./store/modules/app";
// utils
import { getEmojis } from "./plugins/Mys/request/getEmojis";
import showSnackbar from "./components/func/snackbar";
import TGSqlite from "./plugins/Sqlite";
const appStore = useAppStore();
const isMain = ref<boolean>(false);
Expand Down Expand Up @@ -76,6 +77,7 @@ async function checkLoad(): Promise<void> {
return;
}
await createDataDir();
await initData();
appStore.loading = true;
console.info("数据加载完成!");
}
Expand All @@ -89,6 +91,14 @@ async function createDataDir(): Promise<void> {
}
console.info("数据文件夹创建完成!");
}
// 初始化数据库
async function initData(): Promise<void> {
await TGSqlite.reset();
showSnackbar({
text: "已成功初始化数据库!",
});
}
</script>
<style lang="css">
.app-container {
Expand Down
10 changes: 9 additions & 1 deletion src/pages/common/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ onMounted(async () => {
loadingSub.value = "正在获取系统版本";
osVersion.value = await os.version();
loadingSub.value = "正在获取数据库信息";
dbInfo.value = await TGSqlite.getAppData();
try {
dbInfo.value = await TGSqlite.getAppData();
} catch (e) {
showSnackbar({
text: "加载数据库错误,请重置数据库!",
color: "error",
});
}
loadingSub.value = "";
loading.value = false;
});
Expand Down Expand Up @@ -385,6 +392,7 @@ async function confirmRestore(): Promise<void> {
}
loadingSub.value = "正在恢复祈愿数据";
res = await restoreCookieData();
userStore.cookie = await TGSqlite.getCookie();
if (!res) {
fail.push("Cookie");
}
Expand Down

0 comments on commit 0c2d4d0

Please sign in to comment.