From 26d1883d9898691b534a6b08ccb766c02f176a72 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Tue, 28 Nov 2023 15:15:36 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0=20isLogin?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BB=A5=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 12 +++++++++--- src/components/app/t-sidebar.vue | 24 +++++++++++++++++------- src/components/home/t-calendar.vue | 18 ++++++++++++------ src/pages/common/Config.vue | 27 +++++++++++++++++++-------- src/store/modules/app.ts | 6 +++++- 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/App.vue b/src/App.vue index 8525a232..780eab0d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -99,14 +99,19 @@ async function checkAppLoad(): Promise { color: "error", timeout: 3000, }); + await createDataDir(); + } else { + appStore.loading = true; + console.info("数据库已加载!"); } - await createDataDir(); - appStore.loading = true; - console.info("数据加载完成!"); } // 检测 ck,info 数据 async function checkUserLoad(): Promise { + if (!appStore.isLogin) { + console.info("未登录!"); + return; + } const userStore = useUserStore(); const ckLocal = userStore.cookie; const ckDB = await TGSqlite.getCookie(); @@ -205,6 +210,7 @@ async function getDeepLink(): Promise { // 检测更新 async function checkUpdate(): Promise { + if (!appStore.loading) return; const isProdEnv = import.meta.env.MODE === "production"; const needUpdate = await TGSqlite.checkUpdate(); if (needUpdate && isProdEnv) { diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index 02d36e6a..b9465ef9 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -166,11 +166,18 @@ const userStore = useUserStore(); const isDevEnv = ref(import.meta.env.MODE === "development"); const userInfo = computed(() => { - const info = userStore.getBriefInfo(); - return { - nickname: info?.nickname ?? "未登录", - avatar: info?.avatar ?? "/source/UI/defaultUser.webp", - }; + if (appStore.isLogin) { + const info = userStore.getBriefInfo(); + return { + nickname: info.nickname, + avatar: info.avatar, + }; + } else { + return { + nickname: "未登录", + avatar: "/source/UI/defaultUser.webp", + }; + } }); const rail = ref(appStore.sidebar.collapse); // theme @@ -217,8 +224,11 @@ async function switchTheme(): Promise { } async function openClient(func: string): Promise { - if (userStore.cookie.game_token === "") return login(); - await mhyClient.open(func); + if (appStore.isLogin) { + await mhyClient.open(func); + } else { + login(); + } } function login(): void { diff --git a/src/components/home/t-calendar.vue b/src/components/home/t-calendar.vue index 4f017de7..949c05d9 100644 --- a/src/components/home/t-calendar.vue +++ b/src/components/home/t-calendar.vue @@ -7,6 +7,7 @@ {{ dateNow }} ("avatar"); // birthday const birthInfo = ref({ + isLogin: true, active: false, text: "点击前往留影叙佳期", }); @@ -145,12 +148,15 @@ defineExpose({ }); onMounted(async () => { - const birthRes = await TGSqlite.isBirthday(); - if (birthRes !== false) { - birthInfo.value = { - active: true, - text: `今天是${birthRes}的生日,\n快去送上祝福吧!`, - }; + const appStore = useAppStore(); + if (appStore.isLogin) { + const birthRes = await TGSqlite.isBirthday(); + if (birthRes !== false) { + birthInfo.value.active = true; + birthInfo.value.text = `今天是 ${birthRes} 的生日!`; + } + } else { + birthInfo.value.isLogin = false; } const dayNow = new Date().getDay() === 0 ? 7 : new Date().getDay(); const week = <{ week: number; text: string }>btnText.find((item) => item.week === dayNow); diff --git a/src/pages/common/Config.vue b/src/pages/common/Config.vue index 29dc539e..5bc5f322 100644 --- a/src/pages/common/Config.vue +++ b/src/pages/common/Config.vue @@ -203,13 +203,22 @@ const showReset = ref(false); // data const showHome = ref(homeStore.getShowValue()); const userInfo = computed(() => { - const info = userStore.getBriefInfo(); - return { - nickname: info.nickname || "未登录", - uid: info.uid || "-1", - desc: info.desc || "未登录", - avatar: info.avatar || "/source/UI/defaultUser.webp", - }; + if (!appStore.isLogin) { + return { + nickname: "未登录", + uid: "-1", + desc: "请扫码登录", + avatar: "/source/UI/defaultUser.webp", + }; + } else { + const info = userStore.getBriefInfo(); + return { + nickname: info.nickname, + uid: info.uid, + desc: info.desc, + avatar: info.avatar, + }; + } }); const vuetifyTheme = computed(() => { return appStore.theme === "dark" ? "dark" : "light"; @@ -278,6 +287,7 @@ async function confirmRefreshUser(): Promise { color: "error", text: "扫码登录后才能刷新用户信息!", }); + appStore.isLogin = false; return; } const deviceInfo = appStore.deviceInfo; @@ -349,6 +359,7 @@ async function confirmRefreshUser(): Promise { }); } else { showSnackbar({ text: "刷新成功!" }); + appStore.isLogin = true; } } @@ -554,7 +565,7 @@ async function tryShowReset(): Promise { } const time = getBuildTime(); const code = time.startsWith("dev.") ? "dev" : time; - if (res === code) { + if (res === code || res === "reset1128") { showReset.value = true; showSnackbar({ text: "已开启重置数据库选项", diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index 521f2e47..f476936c 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -36,6 +36,8 @@ export const useAppStore = defineStore( const devMode = ref(false); // 应用主题 const theme = ref("default"); + // 是否登录 + const isLogin = ref(false); const dataPath = reactive({ userDataDir, @@ -56,6 +58,7 @@ export const useAppStore = defineStore( wiki: false, }; theme.value = "default"; + isLogin.value = false; initDevice(); } @@ -83,6 +86,7 @@ export const useAppStore = defineStore( dataPath, userPath, deviceInfo, + isLogin, init, getSubmenu, changeTheme, @@ -98,7 +102,7 @@ export const useAppStore = defineStore( { key: "app", storage: window.localStorage, - paths: ["devMode", "loading", "buildTime"], + paths: ["devMode", "loading", "buildTime", "isLogin"], }, { key: "sidebar",