From 7e81d97742c699836b3c9677672e9a7debadca71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=89=91=E6=9C=AF?= <864822121@qq.com> Date: Wed, 4 Jun 2025 12:45:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加isLogined函数以简化登录状态检查 - 更新usePageAuth函数,使用isLogined来判断用户是否已登录 --- src/hooks/usePageAuth.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hooks/usePageAuth.ts b/src/hooks/usePageAuth.ts index e8431c5..5ce7ff3 100644 --- a/src/hooks/usePageAuth.ts +++ b/src/hooks/usePageAuth.ts @@ -4,7 +4,10 @@ import { useUserStore } from '@/store' const loginRoute = import.meta.env.VITE_LOGIN_URL const isDev = import.meta.env.DEV - +const isLogined = () => { + const userStore = useUserStore() + return !!userStore.userInfo.username +} // 检查当前页面是否需要登录 export function usePageAuth() { onLoad((options) => { @@ -27,11 +30,9 @@ export function usePageAuth() { return } - // 检查是否已登录 - const userStore = useUserStore() - const hasLogin = userStore.isLogined + const hasLogin = isLogined() if (hasLogin) { - return + return true } // 构建重定向URL