Skip to content

Commit

Permalink
🎨 完善 ck,briefInfo 获取
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Oct 8, 2023
1 parent 66ecd9a commit 7841ea4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
43 changes: 40 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -40,7 +41,8 @@ onBeforeMount(async () => {
await getDeepLink();
await win.setTitle(title);
await emojiLoad();
await checkLoad();
await checkAppLoad();
await checkUserLoad();
}
});
Expand Down Expand Up @@ -75,7 +77,7 @@ async function emojiLoad(): Promise<void> {
}
}
async function checkLoad(): Promise<void> {
async function checkAppLoad(): Promise<void> {
if (appStore.loading) {
console.info("数据已加载!");
return;
Expand All @@ -86,6 +88,41 @@ async function checkLoad(): Promise<void> {
console.info("数据加载完成!");
}
// 检测 ck,info 数据
async function checkUserLoad(): Promise<void> {
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<void> {
if (!(await fs.exists("userData", { dir: fs.BaseDirectory.AppLocalData }))) {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/common/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async function confirmRefreshUser(): Promise<void> {
return;
}
const ck = userStore.cookie;
if (Object.keys(ck).length < 1) {
if (JSON.stringify(ck) === "{}") {
showSnackbar({
color: "error",
text: "扫码登录后才能刷新用户信息!",
Expand Down Expand Up @@ -314,6 +314,7 @@ async function confirmRefreshUser(): Promise<void> {
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);
Expand Down

0 comments on commit 7841ea4

Please sign in to comment.