diff --git a/js/user.js b/js/user.js
index 5a54008..50fea44 100644
--- a/js/user.js
+++ b/js/user.js
@@ -7,7 +7,7 @@ async function renderUserProfile(username) {
container.innerHTML = '
加载中...
';
try {
- // 1. 获取用户信息(通过 username 参数)
+ // 1. 获取用户信息
const users = await apiFetch('/users?username=' + encodeURIComponent(username));
const user = users && users.length > 0 ? users[0] : null;
@@ -18,7 +18,7 @@ async function renderUserProfile(username) {
document.getElementById('userPageTitle').textContent = '👤 ' + user.username;
- // 2. 获取该用户的帖子(通过 user_id 筛选)
+ // 2. 获取该用户的帖子
const posts = await apiFetch('/posts?user_id=' + user.id);
const avatar = user.avatar_url || 'https://ui-avatars.com/api/?name=' + encodeURIComponent(user.username) + '&background=6366f1&color=fff&size=128';
@@ -33,6 +33,12 @@ async function renderUserProfile(username) {
📝 发了 ${posts.length} 个帖子
${user.role === 'admin' ? '🛡️ 管理员' : ''}
+ ${currentUser && currentUser.id !== user.id ? `
+
+ ` : ''}
📝 发布的帖子
`;
@@ -54,6 +60,14 @@ async function renderUserProfile(username) {
container.innerHTML = html;
+ // 绑定私信按钮
+ const dmBtn = document.getElementById('dmBtn');
+ if (dmBtn) {
+ dmBtn.addEventListener('click', function() {
+ openPrivateChat(user.id, user.username);
+ });
+ }
+
} catch (err) {
container.innerHTML = '加载失败:' + err.message + '
';
}