// ============================================================
// 📋 帖子列表
// ============================================================
let currentSort = 'latest';
function renderFeed() {
const container = document.getElementById('postList');
container.innerHTML = '
加载中...
';
API.getPosts(currentSort).then(posts => {
if (!posts || posts.length === 0) {
container.innerHTML =
'';
p.images.forEach(img => {
imagesHtml += '

';
});
imagesHtml += '
';
}
const replyCount = p.reply_count || 0;
html += `
${p.title || '无标题'}
${(p.content || '').replace(/\n/g, '
')}
${imagesHtml}
${replyCount}
${currentUser && currentUser.id === p.user_id ? `
` : ''}
`;
});
container.innerHTML = html;
container.querySelectorAll('.post-card').forEach(card => {
card.addEventListener('click', function(e) {
if (e.target.closest('button')) return;
const postId = this.dataset.postid;
switchToPost(postId);
});
});
container.querySelectorAll('.action-report').forEach(btn => {
btn.addEventListener('click', function(e) {
e.stopPropagation();
if (!currentUser) { alert('请先登录'); return; }
reportTargetPostId = this.dataset.postid;
document.getElementById('reportModal').classList.add('active');
});
});
container.querySelectorAll('.action-delete').forEach(btn => {
btn.addEventListener('click', function(e) {
e.stopPropagation();
if (confirm('确定要删除这条帖子吗?')) {
API.deletePost(this.dataset.postid).then(() => {
renderFeed();
renderStats();
}).catch(err => alert('删除失败:' + err.message));
}
});
});
}).catch(err => {
container.innerHTML = '