添加 isLogin,用以判断是否登录

This commit is contained in:
BTMuli
2023-11-28 15:15:36 +08:00
parent 91fd375263
commit 26d1883d98
5 changed files with 62 additions and 25 deletions

View File

@@ -99,14 +99,19 @@ async function checkAppLoad(): Promise<void> {
color: "error", color: "error",
timeout: 3000, timeout: 3000,
}); });
await createDataDir();
} else {
appStore.loading = true;
console.info("数据库已加载!");
} }
await createDataDir();
appStore.loading = true;
console.info("数据加载完成!");
} }
// 检测 ck,info 数据 // 检测 ck,info 数据
async function checkUserLoad(): Promise<void> { async function checkUserLoad(): Promise<void> {
if (!appStore.isLogin) {
console.info("未登录!");
return;
}
const userStore = useUserStore(); const userStore = useUserStore();
const ckLocal = userStore.cookie; const ckLocal = userStore.cookie;
const ckDB = await TGSqlite.getCookie(); const ckDB = await TGSqlite.getCookie();
@@ -205,6 +210,7 @@ async function getDeepLink(): Promise<void> {
// 检测更新 // 检测更新
async function checkUpdate(): Promise<void> { async function checkUpdate(): Promise<void> {
if (!appStore.loading) return;
const isProdEnv = import.meta.env.MODE === "production"; const isProdEnv = import.meta.env.MODE === "production";
const needUpdate = await TGSqlite.checkUpdate(); const needUpdate = await TGSqlite.checkUpdate();
if (needUpdate && isProdEnv) { if (needUpdate && isProdEnv) {

View File

@@ -166,11 +166,18 @@ const userStore = useUserStore();
const isDevEnv = ref<boolean>(import.meta.env.MODE === "development"); const isDevEnv = ref<boolean>(import.meta.env.MODE === "development");
const userInfo = computed(() => { const userInfo = computed(() => {
const info = userStore.getBriefInfo(); if (appStore.isLogin) {
return { const info = userStore.getBriefInfo();
nickname: info?.nickname ?? "未登录", return {
avatar: info?.avatar ?? "/source/UI/defaultUser.webp", nickname: info.nickname,
}; avatar: info.avatar,
};
} else {
return {
nickname: "未登录",
avatar: "/source/UI/defaultUser.webp",
};
}
}); });
const rail = ref(appStore.sidebar.collapse); const rail = ref(appStore.sidebar.collapse);
// theme // theme
@@ -217,8 +224,11 @@ async function switchTheme(): Promise<void> {
} }
async function openClient(func: string): Promise<void> { async function openClient(func: string): Promise<void> {
if (userStore.cookie.game_token === "") return login(); if (appStore.isLogin) {
await mhyClient.open(func); await mhyClient.open(func);
} else {
login();
}
} }
function login(): void { function login(): void {

View File

@@ -7,6 +7,7 @@
<span>{{ dateNow }}</span> <span>{{ dateNow }}</span>
<!-- 如果是某人生日礼物图标颜色为红色 --> <!-- 如果是某人生日礼物图标颜色为红色 -->
<span <span
v-if="birthInfo.isLogin"
@click="toBirthday" @click="toBirthday"
class="calendar-title-gift" class="calendar-title-gift"
:style="{ :style="{
@@ -76,6 +77,7 @@ import { computed, onMounted, ref } from "vue";
import { AppCalendarData } from "../../data"; import { AppCalendarData } from "../../data";
import TGSqlite from "../../plugins/Sqlite"; import TGSqlite from "../../plugins/Sqlite";
import { useAppStore } from "../../store/modules/app";
import TGClient from "../../utils/TGClient"; import TGClient from "../../utils/TGClient";
import { generateShareImg } from "../../utils/TGShare"; import { generateShareImg } from "../../utils/TGShare";
import TibCalendarItem from "../itembox/tib-calendar-item.vue"; import TibCalendarItem from "../itembox/tib-calendar-item.vue";
@@ -103,6 +105,7 @@ const selectedType = ref<"avatar" | "weapon">("avatar");
// birthday // birthday
const birthInfo = ref({ const birthInfo = ref({
isLogin: true,
active: false, active: false,
text: "点击前往留影叙佳期", text: "点击前往留影叙佳期",
}); });
@@ -145,12 +148,15 @@ defineExpose({
}); });
onMounted(async () => { onMounted(async () => {
const birthRes = await TGSqlite.isBirthday(); const appStore = useAppStore();
if (birthRes !== false) { if (appStore.isLogin) {
birthInfo.value = { const birthRes = await TGSqlite.isBirthday();
active: true, if (birthRes !== false) {
text: `今天是${birthRes}的生日,\n快去送上祝福吧`, birthInfo.value.active = true;
}; birthInfo.value.text = `今天是 ${birthRes} 的生日!`;
}
} else {
birthInfo.value.isLogin = false;
} }
const dayNow = new Date().getDay() === 0 ? 7 : new Date().getDay(); const dayNow = new Date().getDay() === 0 ? 7 : new Date().getDay();
const week = <{ week: number; text: string }>btnText.find((item) => item.week === dayNow); const week = <{ week: number; text: string }>btnText.find((item) => item.week === dayNow);

View File

@@ -203,13 +203,22 @@ const showReset = ref<boolean>(false);
// data // data
const showHome = ref<string[]>(homeStore.getShowValue()); const showHome = ref<string[]>(homeStore.getShowValue());
const userInfo = computed(() => { const userInfo = computed(() => {
const info = userStore.getBriefInfo(); if (!appStore.isLogin) {
return { return {
nickname: info.nickname || "未登录", nickname: "未登录",
uid: info.uid || "-1", uid: "-1",
desc: info.desc || "未登录", desc: "请扫码登录",
avatar: info.avatar || "/source/UI/defaultUser.webp", 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(() => { const vuetifyTheme = computed(() => {
return appStore.theme === "dark" ? "dark" : "light"; return appStore.theme === "dark" ? "dark" : "light";
@@ -278,6 +287,7 @@ async function confirmRefreshUser(): Promise<void> {
color: "error", color: "error",
text: "扫码登录后才能刷新用户信息!", text: "扫码登录后才能刷新用户信息!",
}); });
appStore.isLogin = false;
return; return;
} }
const deviceInfo = appStore.deviceInfo; const deviceInfo = appStore.deviceInfo;
@@ -349,6 +359,7 @@ async function confirmRefreshUser(): Promise<void> {
}); });
} else { } else {
showSnackbar({ text: "刷新成功!" }); showSnackbar({ text: "刷新成功!" });
appStore.isLogin = true;
} }
} }
@@ -554,7 +565,7 @@ async function tryShowReset(): Promise<void> {
} }
const time = getBuildTime(); const time = getBuildTime();
const code = time.startsWith("dev.") ? "dev" : time; const code = time.startsWith("dev.") ? "dev" : time;
if (res === code) { if (res === code || res === "reset1128") {
showReset.value = true; showReset.value = true;
showSnackbar({ showSnackbar({
text: "已开启重置数据库选项", text: "已开启重置数据库选项",

View File

@@ -36,6 +36,8 @@ export const useAppStore = defineStore(
const devMode = ref(false); const devMode = ref(false);
// 应用主题 // 应用主题
const theme = ref("default"); const theme = ref("default");
// 是否登录
const isLogin = ref(false);
const dataPath = reactive({ const dataPath = reactive({
userDataDir, userDataDir,
@@ -56,6 +58,7 @@ export const useAppStore = defineStore(
wiki: false, wiki: false,
}; };
theme.value = "default"; theme.value = "default";
isLogin.value = false;
initDevice(); initDevice();
} }
@@ -83,6 +86,7 @@ export const useAppStore = defineStore(
dataPath, dataPath,
userPath, userPath,
deviceInfo, deviceInfo,
isLogin,
init, init,
getSubmenu, getSubmenu,
changeTheme, changeTheme,
@@ -98,7 +102,7 @@ export const useAppStore = defineStore(
{ {
key: "app", key: "app",
storage: window.localStorage, storage: window.localStorage,
paths: ["devMode", "loading", "buildTime"], paths: ["devMode", "loading", "buildTime", "isLogin"],
}, },
{ {
key: "sidebar", key: "sidebar",