fix: 修复后台管理页面API路径和链接

- users/posts/topics页面API改为/admin/api/xxx
- 页面链接改为/admin/xxx
- 添加登录验证检查和退出登录按钮
This commit is contained in:
2026-04-12 17:43:17 +08:00
parent e6805d0b75
commit b585adefc9
3 changed files with 106 additions and 34 deletions

View File

@@ -17,19 +17,27 @@
</h1>
</div>
<nav class="mt-6">
<a href="/" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<a href="/admin" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/users" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<a href="/admin/users" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-user-line"></i><span>用户管理</span>
</a>
<a href="/posts" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<a href="/admin/posts" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-file-text-line"></i><span>帖子管理</span>
</a>
<a href="/topics" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<a href="/admin/topics" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-tools-line"></i><span>主题管理</span>
</a>
</nav>
<div class="absolute bottom-0 left-0 right-0 p-4 border-t border-slate-700">
<a href="/" target="_blank" class="text-slate-400 hover:text-white text-sm flex items-center gap-2">
<i class="ri-external-link-line"></i> 访问前台
</a>
<button onclick="logout()" class="mt-2 text-slate-400 hover:text-red-400 text-sm flex items-center gap-2">
<i class="ri-logout-box-line"></i> 退出登录
</button>
</div>
</aside>
<main class="ml-64 flex-1 p-8">
@@ -57,8 +65,24 @@
</div>
<script>
// 检查登录状态
async function checkAuth() {
const res = await fetch('/admin/api/check-auth');
const data = await res.json();
if (!data.logged_in) {
window.location.href = '/admin/login';
}
}
checkAuth();
// 退出登录
async function logout() {
await fetch('/admin/api/logout', { method: 'POST' });
window.location.href = '/admin/login';
}
async function loadUsers() {
const res = await fetch('/api/users');
const res = await fetch('/admin/api/users');
const users = await res.json();
const tbody = document.getElementById('userTable');
@@ -94,13 +118,13 @@
async function deleteUser(userId) {
if (!confirm('确定要删除这个用户吗?这将同时删除该用户的所有帖子!')) return;
const res = await fetch(`/api/users/${userId}`, { method: 'DELETE' });
const res = await fetch(`/admin/api/users/${userId}`, { method: 'DELETE' });
const data = await res.json();
if (data.success) {
loadUsers();
} else {
alert('删除失败');
alert('删除失败: ' + (data.error || '未知错误'));
}
}