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

- 添加isLogined函数以简化登录状态检查
- 更新usePageAuth函数,使用isLogined来判断用户是否已登录
This commit is contained in:
陈剑术 2025-06-04 12:45:33 +08:00
parent dcae738e69
commit 7e81d97742

View File

@ -4,7 +4,10 @@ import { useUserStore } from '@/store'
const loginRoute = import.meta.env.VITE_LOGIN_URL const loginRoute = import.meta.env.VITE_LOGIN_URL
const isDev = import.meta.env.DEV const isDev = import.meta.env.DEV
const isLogined = () => {
const userStore = useUserStore()
return !!userStore.userInfo.username
}
// 检查当前页面是否需要登录 // 检查当前页面是否需要登录
export function usePageAuth() { export function usePageAuth() {
onLoad((options) => { onLoad((options) => {
@ -27,11 +30,9 @@ export function usePageAuth() {
return return
} }
// 检查是否已登录 const hasLogin = isLogined()
const userStore = useUserStore()
const hasLogin = userStore.isLogined
if (hasLogin) { if (hasLogin) {
return return true
} }
// 构建重定向URL // 构建重定向URL