Parcourir la source

feat: 优化页面权限控制逻辑

- 添加isLogined函数以简化登录状态检查
- 更新usePageAuth函数,使用isLogined来判断用户是否已登录
陈剑术 il y a 11 mois
Parent
commit
7e81d97742
1 fichiers modifiés avec 6 ajouts et 5 suppressions
  1. 6 5
      src/hooks/usePageAuth.ts

+ 6 - 5
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