新增后台管理系统

功能模块:
- 仪表盘: 用户统计、帖子统计、帖子类型分布、热门标签、最新帖子
- 用户管理: 查看用户列表、删除用户
- 帖子管理: 查看/删除帖子、置顶功能、帖子详情预览
- 主题管理: 查看/删除主题、主题详情预览

端口: 19005
This commit is contained in:
2026-04-08 13:47:13 +08:00
parent 7f8fbc9605
commit 301c286b8e
6 changed files with 1042 additions and 4 deletions

110
admin/templates/users.html Normal file
View File

@@ -0,0 +1,110 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用户管理 - 论坛后台</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
</head>
<body class="bg-gray-50 min-h-screen">
<div class="flex">
<aside class="w-64 bg-slate-800 min-h-screen fixed left-0 top-0">
<div class="p-6">
<h1 class="text-white text-xl font-bold flex items-center gap-2">
<i class="ri-code-s-slash-line text-2xl text-blue-400"></i>
论坛后台
</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">
<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">
<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">
<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">
<i class="ri-tools-line"></i><span>主题管理</span>
</a>
</nav>
</aside>
<main class="ml-64 flex-1 p-8">
<h1 class="text-2xl font-bold text-gray-800 mb-6">用户管理</h1>
<div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
<table class="w-full">
<thead class="bg-gray-50 border-b border-gray-100">
<tr>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">用户名</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">邮箱</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">手机</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">帖子数</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">回复数</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">注册时间</th>
<th class="px-6 py-3 text-left text-sm font-medium text-gray-500">操作</th>
</tr>
</thead>
<tbody id="userTable">
<tr><td colspan="7" class="px-6 py-8 text-center text-gray-500">加载中...</td></tr>
</tbody>
</table>
</div>
</main>
</div>
<script>
async function loadUsers() {
const res = await fetch('/api/users');
const users = await res.json();
const tbody = document.getElementById('userTable');
if (users.length === 0) {
tbody.innerHTML = '<tr><td colspan="7" class="px-6 py-8 text-center text-gray-500">暂无用户</td></tr>';
return;
}
tbody.innerHTML = users.map(u => `
<tr class="border-b border-gray-50 hover:bg-gray-50">
<td class="px-6 py-4 font-medium text-gray-800">${u.username}</td>
<td class="px-6 py-4 text-gray-600">${u.email || '-'}</td>
<td class="px-6 py-4 text-gray-600">${u.phone || '-'}</td>
<td class="px-6 py-4">
<span class="px-2 py-1 bg-blue-100 text-blue-700 rounded text-xs">${u.posts_count}</span>
</td>
<td class="px-6 py-4">
<span class="px-2 py-1 bg-green-100 text-green-700 rounded text-xs">${u.replies_count}</span>
</td>
<td class="px-6 py-4 text-sm text-gray-500">
${u.created_at ? new Date(u.created_at).toLocaleString() : '-'}
</td>
<td class="px-6 py-4">
<button onclick="deleteUser('${u.id}')" class="text-red-500 hover:text-red-700">
<i class="ri-delete-bin-line"></i> 删除
</button>
</td>
</tr>
`).join('');
}
async function deleteUser(userId) {
if (!confirm('确定要删除这个用户吗?这将同时删除该用户的所有帖子!')) return;
const res = await fetch(`/api/users/${userId}`, { method: 'DELETE' });
const data = await res.json();
if (data.success) {
loadUsers();
} else {
alert('删除失败');
}
}
loadUsers();
</script>
</body>
</html>