add automatic login

This commit is contained in:
landaiqing
2024-08-14 20:04:57 +08:00
parent 48d2f61223
commit cab3b1ee96
18 changed files with 136 additions and 63 deletions

View File

@@ -1,10 +1,20 @@
import {useAuthStore} from '@/store/modules/userStore.ts';
import {useThemeStore} from "@/store/modules/themeStore.ts";
import {langStore} from "@/store/modules/langStore.ts";
import {useAuthSessionStore} from "@/store/modules/userSessionStore.ts";
export default function useStore() {
// 是否自动登录 默认自动化登录
function isAutoLogin() {
const result: string | null = localStorage.getItem('auto_login');
if (result) {
return result === 'true';
}
return true;
}
return {
user: useAuthStore(),
user: isAutoLogin() ? useAuthStore() : useAuthSessionStore(), // 自动登录时使用 useAuthStore否则使用 useAuthSessionStore
theme: useThemeStore(),
lang: langStore()
};