// ============================================================
// 📋 帖子列表
// ============================================================
let currentSort = 'latest';
let totalPages = 1;
const PAGE_SIZE = 20;
function renderFeed() {
const container = document.getElementById('postList');
container.innerHTML = '
加载中...
';
API.getPosts(currentSort, currentPageNum, PAGE_SIZE).then(result => {
const posts = result.data || [];
const pagination = result.pagination || { total: 0, totalPages: 1, page: 1 };
totalPages = pagination.totalPages || 1;
currentPageNum = pagination.page || 1;
if (posts.length === 0 && currentPageNum === 1) {
container.innerHTML =
'';
shown.forEach(img => {
imagesHtml += '
) +
')
';
});
// 多于 3 张时,在末张右下角叠加剩余数量
if (rest > 0) {
imagesHtml += '
+' + rest + '';
}
imagesHtml += '
';
}
const replyCount = p.reply_count || 0;
const renderedContent = renderMarkdown(p.content || '');
// 签名渲染
let signatureHtml = '';
if (p.signature) {
const sigContent = renderMarkdown(p.signature);
signatureHtml = `
${p.is_pinned ? '
📌 置顶
' : ''}
${escapeHTML(p.title || '无标题')}
${renderedContent}
${imagesHtml}
${replyCount}
${currentUser && currentUser.id === p.user_id ? `
` : ''}
${signatureHtml}
`;
});
container.innerHTML = sanitizeHTML(html);
// 分页控件
if (totalPages > 1) {
let paginationHtml = `