diff --git a/src/App.vue b/src/App.vue index b03e85bb..db9fe321 100644 --- a/src/App.vue +++ b/src/App.vue @@ -14,15 +14,16 @@ // vue import { onBeforeMount, onMounted, ref } from "vue"; import { useRouter } from "vue-router"; +import showSnackbar from "./components/func/snackbar"; import TSidebar from "./components/app/t-sidebar.vue"; import TBackTop from "./components/app/t-backTop.vue"; // tauri import { app, event, fs, tauri, window as TauriWindow } from "@tauri-apps/api"; // store import { useAppStore } from "./store/modules/app"; +import { useUserStore } from "./store/modules/user"; // utils import { getEmojis } from "./plugins/Mys/request/getEmojis"; -import showSnackbar from "./components/func/snackbar"; import TGSqlite from "./plugins/Sqlite"; const appStore = useAppStore(); @@ -40,7 +41,8 @@ onBeforeMount(async () => { await getDeepLink(); await win.setTitle(title); await emojiLoad(); - await checkLoad(); + await checkAppLoad(); + await checkUserLoad(); } }); @@ -75,7 +77,7 @@ async function emojiLoad(): Promise { } } -async function checkLoad(): Promise { +async function checkAppLoad(): Promise { if (appStore.loading) { console.info("数据已加载!"); return; @@ -86,6 +88,41 @@ async function checkLoad(): Promise { console.info("数据加载完成!"); } +// 检测 ck,info 数据 +async function checkUserLoad(): Promise { + const userStore = useUserStore(); + const ckLocal = userStore.cookie; + const ckDB = await TGSqlite.getCookie(); + if (JSON.stringify(ckLocal) !== JSON.stringify(ckDB)) { + userStore.cookie = ckDB; + console.info("cookie 数据已更新!"); + } else if (JSON.stringify(ckLocal) === "{}") { + await new Promise((resolve) => { + setTimeout(() => { + showSnackbar({ + text: "请先登录!", + color: "error", + timeout: 3000, + }); + resolve(true); + }, 3000); + }); + } else { + console.info("cookie 数据已加载!"); + } + const infoLocal = userStore.briefInfo; + const appData = await TGSqlite.getAppData(); + const infoDB = appData.find((item) => item.key === "userInfo")?.value; + if (infoDB === undefined && JSON.stringify(infoLocal) !== "{}") { + await TGSqlite.saveAppData("userInfo", JSON.stringify(infoLocal)); + } else if (infoDB !== undefined && infoLocal !== JSON.parse(infoDB)) { + userStore.setBriefInfo(JSON.parse(infoDB)); + console.info("briefInfo 数据已更新!"); + } else { + console.info("briefInfo 数据已加载!"); + } +} + // 创建数据文件夹 async function createDataDir(): Promise { if (!(await fs.exists("userData", { dir: fs.BaseDirectory.AppLocalData }))) { diff --git a/src/pages/common/Config.vue b/src/pages/common/Config.vue index 90ff6728..4c08f07c 100644 --- a/src/pages/common/Config.vue +++ b/src/pages/common/Config.vue @@ -270,7 +270,7 @@ async function confirmRefreshUser(): Promise { return; } const ck = userStore.cookie; - if (Object.keys(ck).length < 1) { + if (JSON.stringify(ck) === "{}") { showSnackbar({ color: "error", text: "扫码登录后才能刷新用户信息!", @@ -314,6 +314,7 @@ async function confirmRefreshUser(): Promise { failCount++; } else { userStore.setBriefInfo(infoRes); + await TGSqlite.saveAppData("userInfo", JSON.stringify(infoRes)); loadingTitle.value = "获取成功!正在获取用户游戏账号信息"; } const accountRes = await TGRequest.User.byCookie.getAccounts(ck.cookie_token, ck.account_id);