// ============================================================
// 👤 用户主页
// ============================================================
async function renderUserProfile(username) {
const container = document.getElementById('userProfileContent');
container.innerHTML = Skeleton.userProfile();
try {
// 使用公开接口 /users/profile/:username
const user = await apiFetch('/users/profile/' + encodeURIComponent(username));
if (user.error || !user.id) {
container.innerHTML = '
${escapeHTML(user.username)}
${escapeHTML(user.bio || '这个人很懒,什么都没写')}
📅 加入于 ${user.created_at ? new Date(user.created_at).toLocaleDateString('zh-CN') : '未知'}
📝 发了 ${posts.length} 个帖子
${user.role === 'admin' ? '🛡️ 管理员' : ''}
${currentUser && currentUser.id !== user.id ? `
` : ''}
${escapeHTML(p.title || '无标题')}
${escapeHTML((p.content || '').substring(0, 100))}${(p.content || '').length > 100 ? '...' : ''}
${time}
`;
});
}
container.innerHTML = sanitizeHTML(html);
container.querySelectorAll('.post-card[data-postid]').forEach(card => {
card.addEventListener('click', function() {
switchToPost(this.dataset.postid);
});
});
const dmBtn = document.getElementById('dmBtn');
if (dmBtn) {
dmBtn.addEventListener('click', function() {
openPrivateChat(user.id, user.username);
});
}
} catch (err) {
container.innerHTML = '