新增后台管理系统
功能模块: - 仪表盘: 用户统计、帖子统计、帖子类型分布、热门标签、最新帖子 - 用户管理: 查看用户列表、删除用户 - 帖子管理: 查看/删除帖子、置顶功能、帖子详情预览 - 主题管理: 查看/删除主题、主题详情预览 端口: 19005
This commit is contained in:
206
admin/templates/index.html
Normal file
206
admin/templates/index.html
Normal file
@@ -0,0 +1,206 @@
|
||||
<!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">
|
||||
<style>
|
||||
.gradient-bg { background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%); }
|
||||
</style>
|
||||
</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 bg-slate-700 text-white">
|
||||
<i class="ri-dashboard-line"></i><span>仪表盘</span>
|
||||
</a>
|
||||
<a href="/users" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover: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>
|
||||
<div class="absolute bottom-0 left-0 right-0 p-4 border-t border-slate-700">
|
||||
<a href="http://localhost:19004" target="_blank" class="text-slate-400 hover:text-white text-sm flex items-center gap-2">
|
||||
<i class="ri-external-link-line"></i> 访问前台
|
||||
</a>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- 主内容 -->
|
||||
<main class="ml-64 flex-1 p-8">
|
||||
<!-- 统计卡片 -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
|
||||
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-gray-500 text-sm">用户总数</p>
|
||||
<p class="text-3xl font-bold text-gray-800 mt-2" id="stat-users">-</p>
|
||||
</div>
|
||||
<div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
|
||||
<i class="ri-user-line text-2xl text-blue-600"></i>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-xs text-gray-400 mt-2">今日新增: <span id="stat-today-users">0</span></p>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-gray-500 text-sm">帖子总数</p>
|
||||
<p class="text-3xl font-bold text-gray-800 mt-2" id="stat-posts">-</p>
|
||||
</div>
|
||||
<div class="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center">
|
||||
<i class="ri-file-text-line text-2xl text-green-600"></i>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-xs text-gray-400 mt-2">今日发布: <span id="stat-today-posts">0</span></p>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-gray-500 text-sm">主题总数</p>
|
||||
<p class="text-3xl font-bold text-gray-800 mt-2" id="stat-topics">-</p>
|
||||
</div>
|
||||
<div class="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center">
|
||||
<i class="ri-tools-line text-2xl text-purple-600"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-gray-500 text-sm">消息总数</p>
|
||||
<p class="text-3xl font-bold text-gray-800 mt-2" id="stat-messages">-</p>
|
||||
</div>
|
||||
<div class="w-12 h-12 bg-orange-100 rounded-lg flex items-center justify-center">
|
||||
<i class="ri-message-3-line text-2xl text-orange-600"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 帖子类型分布 & 热门标签 -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
|
||||
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
|
||||
<i class="ri-pie-chart-line text-blue-500"></i>
|
||||
帖子类型分布
|
||||
</h2>
|
||||
<div id="typeChart" class="flex items-center justify-center gap-8 py-8">
|
||||
<div class="text-center">
|
||||
<div class="text-3xl font-bold text-blue-600" id="discussion-count">0</div>
|
||||
<div class="text-sm text-gray-500">技术交流</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-3xl font-bold text-purple-600" id="share-count">0</div>
|
||||
<div class="text-sm text-gray-500">工具分享</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
|
||||
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
|
||||
<i class="ri-price-tag-3-line text-green-500"></i>
|
||||
热门标签
|
||||
</h2>
|
||||
<div id="tagsList" class="flex flex-wrap gap-2">
|
||||
<p class="text-gray-500">加载中...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 最新帖子 -->
|
||||
<div class="mt-6 bg-white rounded-xl shadow-sm border border-gray-100 p-6">
|
||||
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
|
||||
<i class="ri-time-line text-purple-500"></i>
|
||||
最新帖子
|
||||
</h2>
|
||||
<div id="recentPosts" class="space-y-3">
|
||||
<p class="text-gray-500">加载中...</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
async function loadStats() {
|
||||
const res = await fetch('/api/stats');
|
||||
const data = await res.json();
|
||||
|
||||
document.getElementById('stat-users').textContent = data.users_count;
|
||||
document.getElementById('stat-posts').textContent = data.posts_count;
|
||||
document.getElementById('stat-topics').textContent = data.topics_count;
|
||||
document.getElementById('stat-messages').textContent = data.messages_count;
|
||||
document.getElementById('stat-today-users').textContent = data.today_users;
|
||||
document.getElementById('stat-today-posts').textContent = data.today_posts;
|
||||
document.getElementById('discussion-count').textContent = data.discussion_count;
|
||||
document.getElementById('share-count').textContent = data.share_count;
|
||||
}
|
||||
|
||||
async function loadTags() {
|
||||
const res = await fetch('/api/tags');
|
||||
const tags = await res.json();
|
||||
|
||||
const container = document.getElementById('tagsList');
|
||||
if (tags.length === 0) {
|
||||
container.innerHTML = '<p class="text-gray-500">暂无标签</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = tags.map(tag => `
|
||||
<span class="px-3 py-1 bg-gray-100 text-gray-700 rounded-full text-sm">
|
||||
${tag.name} (${tag.count})
|
||||
</span>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async function loadRecentPosts() {
|
||||
const res = await fetch('/api/posts');
|
||||
const posts = await res.json();
|
||||
|
||||
const container = document.getElementById('recentPosts');
|
||||
if (posts.length === 0) {
|
||||
container.innerHTML = '<p class="text-gray-500">暂无帖子</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = posts.slice(0, 5).map(p => `
|
||||
<div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="px-2 py-0.5 rounded text-xs ${p.type === 'discussion' ? 'bg-blue-100 text-blue-600' : 'bg-purple-100 text-purple-600'}">
|
||||
${p.type === 'discussion' ? '交流' : '分享'}
|
||||
</span>
|
||||
<span class="font-medium text-gray-800">${p.title}</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-4 text-sm text-gray-500">
|
||||
<span>${p.author}</span>
|
||||
<span>${new Date(p.created_at).toLocaleDateString()}</span>
|
||||
<span><i class="ri-eye-line"></i> ${p.views}</span>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
loadStats();
|
||||
loadTags();
|
||||
loadRecentPosts();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
203
admin/templates/posts.html
Normal file
203
admin/templates/posts.html
Normal file
@@ -0,0 +1,203 @@
|
||||
<!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 text-slate-300 hover:bg-slate-700 hover:text-white">
|
||||
<i class="ri-user-line"></i><span>用户管理</span>
|
||||
</a>
|
||||
<a href="/posts" class="flex items-center gap-3 px-6 py-3 bg-slate-700 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">
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-2xl font-bold text-gray-800">帖子管理</h1>
|
||||
<select id="typeFilter" onchange="loadPosts()" class="px-4 py-2 border border-gray-200 rounded-lg">
|
||||
<option value="">全部类型</option>
|
||||
<option value="discussion">技术交流</option>
|
||||
<option value="share">工具分享</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<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="postTable">
|
||||
<tr><td colspan="7" class="px-6 py-8 text-center text-gray-500">加载中...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<div id="detailModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50 p-4">
|
||||
<div class="bg-white rounded-xl w-full max-w-2xl max-h-[80vh] overflow-hidden flex flex-col">
|
||||
<div class="p-6 border-b flex justify-between items-center">
|
||||
<h2 class="text-xl font-bold text-gray-800" id="modalTitle">帖子详情</h2>
|
||||
<button onclick="closeModal()" class="text-gray-400"><i class="ri-close-line text-2xl"></i></button>
|
||||
</div>
|
||||
<div class="p-6 overflow-auto flex-1" id="modalContent"></div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
async function loadPosts() {
|
||||
const type = document.getElementById('typeFilter').value;
|
||||
const url = type ? `/api/posts?type=${type}` : '/api/posts';
|
||||
|
||||
const res = await fetch(url);
|
||||
const posts = await res.json();
|
||||
|
||||
const tbody = document.getElementById('postTable');
|
||||
|
||||
if (posts.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="7" class="px-6 py-8 text-center text-gray-500">暂无帖子</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = posts.map(p => `
|
||||
<tr class="border-b border-gray-50 hover:bg-gray-50">
|
||||
<td class="px-6 py-4">
|
||||
<p class="font-medium text-gray-800 truncate max-w-xs">${p.title}</p>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<span class="px-2 py-1 rounded text-xs ${p.type === 'discussion' ? 'bg-blue-100 text-blue-600' : 'bg-purple-100 text-purple-600'}">
|
||||
${p.type === 'discussion' ? '技术交流' : '工具分享'}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-600">${p.author}</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-500">
|
||||
${p.views} / ${p.likes} / ${p.replies}
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
${p.is_pinned ? '<span class="px-2 py-1 bg-red-100 text-red-600 rounded text-xs">置顶</span>' : '-'}
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-500">
|
||||
${new Date(p.created_at).toLocaleDateString()}
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<button onclick="viewPost('${p.id}')" class="text-blue-500 hover:text-blue-700 mr-3">
|
||||
<i class="ri-eye-line"></i>
|
||||
</button>
|
||||
<button onclick="pinPost('${p.id}')" class="text-yellow-500 hover:text-yellow-700 mr-3">
|
||||
<i class="ri-pushpin-line"></i>
|
||||
</button>
|
||||
<button onclick="deletePost('${p.id}')" class="text-red-500 hover:text-red-700">
|
||||
<i class="ri-delete-bin-line"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async function viewPost(postId) {
|
||||
const res = await fetch(`/api/posts/${postId}`);
|
||||
const post = await res.json();
|
||||
|
||||
document.getElementById('modalTitle').textContent = post.title;
|
||||
document.getElementById('modalContent').innerHTML = `
|
||||
<div class="space-y-4">
|
||||
<div class="grid grid-cols-3 gap-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div>
|
||||
<p class="text-sm text-gray-500">作者</p>
|
||||
<p class="font-medium">${post.author}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-500">类型</p>
|
||||
<p class="font-medium">${post.type === 'discussion' ? '技术交流' : '工具分享'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-500">浏览/赞</p>
|
||||
<p class="font-medium">${post.views} / ${post.likes}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="text-sm text-gray-500 mb-2">内容</p>
|
||||
<div class="p-4 bg-gray-50 rounded-lg text-sm text-gray-700 whitespace-pre-wrap max-h-60 overflow-auto">
|
||||
${post.content}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${post.replies.length > 0 ? `
|
||||
<div>
|
||||
<p class="text-sm text-gray-500 mb-2">回复 (${post.replies.length})</p>
|
||||
<div class="space-y-2 max-h-40 overflow-auto">
|
||||
${post.replies.map(r => `
|
||||
<div class="p-2 bg-gray-50 rounded text-sm">
|
||||
<span class="font-medium">${r.author}</span>: ${r.content}
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.getElementById('detailModal').classList.remove('hidden');
|
||||
document.getElementById('detailModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
document.getElementById('detailModal').classList.add('hidden');
|
||||
document.getElementById('detailModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
async function pinPost(postId) {
|
||||
const res = await fetch(`/api/posts/${postId}/pin`, { method: 'POST' });
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
loadPosts();
|
||||
}
|
||||
}
|
||||
|
||||
async function deletePost(postId) {
|
||||
if (!confirm('确定要删除这个帖子吗?')) return;
|
||||
|
||||
const res = await fetch(`/api/posts/${postId}`, { method: 'DELETE' });
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
loadPosts();
|
||||
}
|
||||
}
|
||||
|
||||
loadPosts();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
181
admin/templates/topics.html
Normal file
181
admin/templates/topics.html
Normal file
@@ -0,0 +1,181 @@
|
||||
<!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 text-slate-300 hover:bg-slate-700 hover: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 bg-slate-700 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="topicTable">
|
||||
<tr><td colspan="7" class="px-6 py-8 text-center text-gray-500">加载中...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<div id="detailModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50 p-4">
|
||||
<div class="bg-white rounded-xl w-full max-w-2xl max-h-[80vh] overflow-hidden flex flex-col">
|
||||
<div class="p-6 border-b flex justify-between items-center">
|
||||
<h2 class="text-xl font-bold text-gray-800" id="modalTitle">主题详情</h2>
|
||||
<button onclick="closeModal()" class="text-gray-400"><i class="ri-close-line text-2xl"></i></button>
|
||||
</div>
|
||||
<div class="p-6 overflow-auto flex-1" id="modalContent"></div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
async function loadTopics() {
|
||||
const res = await fetch('/api/topics');
|
||||
const topics = await res.json();
|
||||
|
||||
const tbody = document.getElementById('topicTable');
|
||||
|
||||
if (topics.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="7" class="px-6 py-8 text-center text-gray-500">暂无主题</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = topics.map(t => `
|
||||
<tr class="border-b border-gray-50 hover:bg-gray-50">
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-2xl">${t.icon}</span>
|
||||
<span class="font-medium text-gray-800">${t.name}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-600">${t.author}</td>
|
||||
<td class="px-6 py-4">
|
||||
<span class="px-2 py-1 bg-blue-100 text-blue-700 rounded text-xs">${t.sub_topics_count}</span>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<span class="px-2 py-1 bg-green-100 text-green-700 rounded text-xs">${t.questions_count}</span>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<span class="px-2 py-1 bg-purple-100 text-purple-700 rounded text-xs">${t.followers_count}</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-500">
|
||||
${new Date(t.created_at).toLocaleDateString()}
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<button onclick="viewTopic('${t.id}')" class="text-blue-500 hover:text-blue-700 mr-3">
|
||||
<i class="ri-eye-line"></i>
|
||||
</button>
|
||||
<button onclick="deleteTopic('${t.id}')" class="text-red-500 hover:text-red-700">
|
||||
<i class="ri-delete-bin-line"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async function viewTopic(topicId) {
|
||||
const res = await fetch(`/api/topics/${topicId}`);
|
||||
const topic = await res.json();
|
||||
|
||||
document.getElementById('modalTitle').textContent = topic.name;
|
||||
document.getElementById('modalContent').innerHTML = `
|
||||
<div class="space-y-4">
|
||||
<div class="p-4 bg-gray-50 rounded-lg">
|
||||
<p class="text-sm text-gray-500">描述</p>
|
||||
<p class="text-gray-800">${topic.description || '暂无描述'}</p>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<div class="p-4 bg-blue-50 rounded-lg text-center">
|
||||
<div class="text-2xl font-bold text-blue-600">${topic.sub_topics.length}</div>
|
||||
<div class="text-sm text-gray-500">子主题</div>
|
||||
</div>
|
||||
<div class="p-4 bg-green-50 rounded-lg text-center">
|
||||
<div class="text-2xl font-bold text-green-600">${topic.questions.length}</div>
|
||||
<div class="text-sm text-gray-500">问题</div>
|
||||
</div>
|
||||
<div class="p-4 bg-purple-50 rounded-lg text-center">
|
||||
<div class="text-2xl font-bold text-purple-600">${topic.followers_count}</div>
|
||||
<div class="text-sm text-gray-500">关注</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${topic.questions.length > 0 ? `
|
||||
<div>
|
||||
<p class="text-sm text-gray-500 mb-2">最新问题</p>
|
||||
<div class="space-y-2 max-h-40 overflow-auto">
|
||||
${topic.questions.slice(0, 5).map(q => `
|
||||
<div class="p-2 bg-gray-50 rounded text-sm">
|
||||
<p class="font-medium">${q.title}</p>
|
||||
<p class="text-gray-500 text-xs">${q.answers.length} 回答</p>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.getElementById('detailModal').classList.remove('hidden');
|
||||
document.getElementById('detailModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
document.getElementById('detailModal').classList.add('hidden');
|
||||
document.getElementById('detailModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
async function deleteTopic(topicId) {
|
||||
if (!confirm('确定要删除这个主题吗?')) return;
|
||||
|
||||
const res = await fetch(`/api/topics/${topicId}`, { method: 'DELETE' });
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
loadTopics();
|
||||
}
|
||||
}
|
||||
|
||||
loadTopics();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
110
admin/templates/users.html
Normal file
110
admin/templates/users.html
Normal 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>
|
||||
Reference in New Issue
Block a user