新增后台管理系统
功能模块: - 仪表盘: 用户统计、帖子统计、帖子类型分布、热门标签、最新帖子 - 用户管理: 查看用户列表、删除用户 - 帖子管理: 查看/删除帖子、置顶功能、帖子详情预览 - 主题管理: 查看/删除主题、主题详情预览 端口: 19005
This commit is contained in:
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>
|
||||
Reference in New Issue
Block a user