From cd087e993187c79b5ee2e30e965b3dde92aa0eaa Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sun, 12 Apr 2026 18:16:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 前端用户下拉菜单优化 - 改用CSS动画,解决鼠标移动问题 2. 帖子管理增加显示/隐藏开关 3. 帖子详情页可直接删除回复 4. 新增回复管理页面(列表、删除) 5. 用户管理增加编辑功能(用户名、邮箱、手机、简介) 6. 用户管理增加查看帖子按钮 7. 所有页面侧边栏添加回复管理入口 8. 数据库增加 is_hidden 字段 --- admin/templates/index.html | 3 + admin/templates/login.html | 2 +- admin/templates/posts.html | 81 ++++++++++++++------ admin/templates/replies.html | 140 ++++++++++++++++++++++++++++++++++ admin/templates/topics.html | 3 + admin/templates/users.html | 141 ++++++++++++++++++++++++++++++----- backend/app.py | 91 ++++++++++++++++++++++ frontend/index.html | 26 +++++-- models.py | 19 +++++ 9 files changed, 458 insertions(+), 48 deletions(-) create mode 100644 admin/templates/replies.html diff --git a/admin/templates/index.html b/admin/templates/index.html index 3f2e2c8..b4f73a4 100644 --- a/admin/templates/index.html +++ b/admin/templates/index.html @@ -31,6 +31,9 @@ 帖子管理 + + 回复管理 + 主题管理 diff --git a/admin/templates/login.html b/admin/templates/login.html index 3d009e4..3ceaea6 100644 --- a/admin/templates/login.html +++ b/admin/templates/login.html @@ -19,7 +19,7 @@

后台管理系统

-

管理员账号: admin / admin123

+

用户管理员账号: admin / admin123

diff --git a/admin/templates/posts.html b/admin/templates/posts.html index 5104e5b..3e0f515 100644 --- a/admin/templates/posts.html +++ b/admin/templates/posts.html @@ -27,6 +27,9 @@ 帖子管理 + + 回复管理 + 主题管理 @@ -55,17 +58,18 @@ - - - - - - - + + + + + + + + - +
标题类型作者浏览/赞/回复状态发布时间操作标题类型作者浏览/赞/回复状态显示发布时间操作
加载中...
加载中...
@@ -110,38 +114,44 @@ const tbody = document.getElementById('postTable'); if (posts.length === 0) { - tbody.innerHTML = '暂无帖子'; + tbody.innerHTML = '暂无帖子'; return; } tbody.innerHTML = posts.map(p => ` - +

${p.title}

- + - ${p.type === 'discussion' ? '技术交流' : '工具分享'} + ${p.type === 'discussion' ? '交流' : '分享'} - ${p.author} - + ${p.author} + ${p.views} / ${p.likes} / ${p.replies} - + ${p.is_pinned ? '置顶' : '-'} - + + + + ${new Date(p.created_at).toLocaleDateString()} - - - - @@ -149,6 +159,15 @@ `).join(''); } + async function toggleHide(postId, currentHidden) { + const res = await fetch(`/admin/api/posts/${postId}/hide`, { method: 'POST' }); + const data = await res.json(); + + if (data.success) { + loadPosts(); + } + } + async function viewPost(postId) { const res = await fetch(`/admin/api/posts/${postId}`); const post = await res.json(); @@ -183,13 +202,18 @@

回复 (${post.replies.length})

${post.replies.map(r => ` -
- ${r.author}: ${r.content} +
+
+ ${r.author}: ${r.content} +
+
`).join('')}
- ` : ''} + ` : '

暂无回复

'} `; @@ -222,6 +246,17 @@ } } + async function deleteReply(replyId, postId) { + if (!confirm('确定要删除这条回复吗?')) return; + + const res = await fetch(`/admin/api/replies/${replyId}`, { method: 'DELETE' }); + const data = await res.json(); + + if (data.success) { + viewPost(postId); // 重新加载帖子详情 + } + } + loadPosts(); diff --git a/admin/templates/replies.html b/admin/templates/replies.html new file mode 100644 index 0000000..c7f723d --- /dev/null +++ b/admin/templates/replies.html @@ -0,0 +1,140 @@ + + + + + + + 回复管理 - 论坛后台 + + + + +
+ + +
+

回复管理

+ +
+ + + + + + + + + + + + + + +
回复内容作者帖子回复时间操作
加载中...
+
+
+
+ + + + \ No newline at end of file diff --git a/admin/templates/topics.html b/admin/templates/topics.html index 501e9d8..22d23b4 100644 --- a/admin/templates/topics.html +++ b/admin/templates/topics.html @@ -27,6 +27,9 @@ 帖子管理 + + 回复管理 + 主题管理 diff --git a/admin/templates/users.html b/admin/templates/users.html index 2b5c2d9..e92457d 100644 --- a/admin/templates/users.html +++ b/admin/templates/users.html @@ -27,6 +27,9 @@ 帖子管理 + + 回复管理 + 主题管理 @@ -48,23 +51,63 @@ - - - - - - - + + + + + + + + - +
用户名邮箱手机帖子数回复数注册时间操作用户名邮箱手机简介帖子数回复数注册时间操作
加载中...
加载中...
+ +
+ +hModal').classList.remove('hidden'); + document.getElementById('searchModal').classList.add('flex'); + } + }); + + function closeSearchModal() { + document.getElementById('searchModal').classList.add('hidden'); + document.getElementById('searchModal').classList.remove('flex'); + } + + \ No newline at end of file diff --git a/models.py b/models.py index e0155e8..4d1e023 100644 --- a/models.py +++ b/models.py @@ -54,6 +54,7 @@ class Database: likes TEXT DEFAULT '[]', views INTEGER DEFAULT 0, is_pinned INTEGER DEFAULT 0, + is_hidden INTEGER DEFAULT 0, created_at TEXT, updated_at TEXT, FOREIGN KEY (author_id) REFERENCES users(id) @@ -317,6 +318,24 @@ class ReplyModel: reply['likes'] = json.loads(reply['likes'] or '[]') replies.append(reply) return replies + + def delete(self, reply_id): + """删除回复""" + with self.db.get_conn() as conn: + conn.execute('DELETE FROM replies WHERE id = ?', (reply_id,)) + conn.commit() + return True + + def get_all(self, limit=50): + """获取所有回复(后台管理用)""" + with self.db.get_conn() as conn: + rows = conn.execute('SELECT * FROM replies ORDER BY created_at DESC LIMIT ?', (limit,)).fetchall() + replies = [] + for row in rows: + reply = dict(row) + reply['likes'] = json.loads(reply['likes'] or '[]') + replies.append(reply) + return replies class TopicModel: