fix: 修复普通用户无法正常读取用户信息的问题

This commit is contained in:
2025-07-12 18:54:10 +08:00
parent 28af2df093
commit 15c6eefe30
2 changed files with 43 additions and 6 deletions

View File

@@ -18,6 +18,10 @@
<div v-if="activePage === 1">
<UserInfo />
</div>
<div v-else-if="activePage === 2">
<!-- 添加对应的组件或内容 -->
<div>Item 2 内容</div>
</div>
<div v-else-if="activePage === 100">
<BoardTable />
</div>
@@ -37,11 +41,37 @@ const isAdmin = ref(false);
function setActivePage(event: Event) {
const target = event.currentTarget as HTMLLinkElement;
activePage.value = toNumber(target.id);
const newPage = toNumber(target.id);
// 如果用户不是管理员但试图访问管理员页面,则忽略
if (newPage === 100 && !isAdmin.value) {
return;
}
activePage.value = newPage;
}
onMounted(async () => {
isAdmin.value = await AuthManager.verifyAdminAuth();
try {
// 首先验证用户是否已登录
const isAuthenticated = await AuthManager.isAuthenticated();
if (!isAuthenticated) {
// 如果未登录,重定向到登录页面
// 这里可以使用路由跳转
return;
}
// 验证管理员权限
isAdmin.value = await AuthManager.verifyAdminAuth();
// 如果当前页面是管理员页面但用户不是管理员,切换到用户信息页面
if (activePage.value === 100 && !isAdmin.value) {
activePage.value = 1;
}
} catch (error) {
console.error('用户认证检查失败:', error);
// 可以在这里处理错误,比如显示错误信息或重定向到登录页面
}
});
</script>