cd /root/forumlify
cat > js/user.js << 'EOF'
// ============================================================
// 👤 用户主页
// ============================================================
async function renderUserProfile(username) {
const container = document.getElementById('userProfileContent');
container.innerHTML = '
加载中...
';
try {
// 1. 获取用户信息
const users = await apiFetch('/users?username=' + encodeURIComponent(username));
const user = users && users.length > 0 ? users[0] : null;
if (!user) {
container.innerHTML = '
${user.username}
${user.bio || '这个人很懒,什么都没写'}
📅 加入于 ${user.created_at ? new Date(user.created_at).toLocaleDateString('zh-CN') : '未知'}
📝 发了 ${posts.length} 个帖子
${user.role === 'admin' ? '🛡️ 管理员' : ''}
${currentUser && currentUser.id !== user.id ? `
` : ''}
${p.title || '无标题'}
${(p.content || '').substring(0, 100)}${(p.content || '').length > 100 ? '...' : ''}
${time}
`;
});
}
container.innerHTML = html;
// 绑定私信按钮
const dmBtn = document.getElementById('dmBtn');
if (dmBtn) {
dmBtn.addEventListener('click', function() {
openPrivateChat(user.id, user.username);
});
}
} catch (err) {
container.innerHTML = '