refactor(feed): 举报与删除按钮从列表卡片移到帖子详情页
举报和删除针对的是帖子内容本身,放在列表卡片上容易被理解为对整张 卡片操作,也容易误点(卡片本身可点击进入详情)。现统一移到详情页。 - 列表卡片底部只保留回复数,不再有任何按钮 - 详情页新增举报按钮(此前详情页只有置顶 / 编辑 / 删除,反而缺少 举报入口)。按钮仅在登录后显示;提交逻辑仍复用 app.js 中 reportTargetPostId 的既有流程,此处只负责记录目标并打开弹窗 - 移除 feed.js 中随之失效的 .action-report / .action-delete 事件绑定, 避免留下死代码 详情页原有的删除按钮保留,卡片上那份去掉,因此删除入口从两个减为一个。 实测(Puppeteer,1280px 视口): - 首页卡片内按钮总数为 0,底部仅显示「N 条回复」 - 详情页按钮:置顶、举报(编辑与删除仅作者本人可见,测试帖作者为 另一账号,故未出现) - 点击举报按钮后 reportModal 的 class 由 modal 变为 modal active, 计算样式 display 为 flex,reportTargetPostId 正确写入帖子 ID 完整测试套件 25/25 通过。
This commit is contained in:
1 parent
74204f7bb2
commit
17b6ee35ef
2 files changed
+19
-30
No files matched your search
+5
-30
@@ -83,16 +83,8 @@ function renderFeed() {
|
||||
<div class="post-actions">
|
||||
<span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:middle;"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
|
||||
${replyCount}
|
||||
${replyCount} 条回复
|
||||
</span>
|
||||
<button class="action-report" data-postid="${p.id}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:middle;"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
|
||||
举报
|
||||
</button>
|
||||
${currentUser && currentUser.id === p.user_id ? `<button class="action-delete" data-postid="${p.id}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:middle;"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
|
||||
删除
|
||||
</button>` : ''}
|
||||
</div>
|
||||
${signatureHtml}
|
||||
</div>
|
||||
@@ -195,27 +187,10 @@ function renderFeed() {
|
||||
});
|
||||
});
|
||||
|
||||
container.querySelectorAll('.action-report').forEach(btn => {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.stopPropagation();
|
||||
if (!currentUser) { showToast('请先登录', 'warning'); return; }
|
||||
reportTargetPostId = this.dataset.postid;
|
||||
document.getElementById('reportModal').classList.add('active');
|
||||
});
|
||||
});
|
||||
container.querySelectorAll('.action-delete').forEach(btn => {
|
||||
btn.addEventListener('click', async function(e) {
|
||||
e.stopPropagation();
|
||||
const ok = await showConfirm('确定要删除这条帖子吗?', {
|
||||
title: '删除帖子', confirmText: '删除', danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
API.deletePost(this.dataset.postid).then(() => {
|
||||
renderFeed();
|
||||
renderStats();
|
||||
}).catch(err => showToast('删除失败:' + err.message, 'error'));
|
||||
});
|
||||
});
|
||||
// 卡片上不再放举报与删除按钮:这两个操作针对的是帖子内容本身,
|
||||
// 放在卡片上容易被误解为对整张卡片操作,也容易误点。
|
||||
// 它们统一放在帖子详情页,用户点进帖子后操作。
|
||||
// (卡片的点击跳转绑定在上方,此处无需重复绑定。)
|
||||
}).catch(err => {
|
||||
container.innerHTML = '<div style="text-align:center;color:#ef4444;padding:40px 0;">加载失败:' + escapeHTML(err.message) +
|
||||
'</div>';
|
||||
|
||||
Reference in new issue
Block a user