功能:好友面板昵称后显示在线离线状态
后端: - ChatStateService 新增 getAllOnlineUsernames(),跨房间聚合在线用户名 - FriendController::index() 为每位好友/待回加用户附加 is_online 字段 - 在线好友自动排在列表前面 前端: - 昵称后显示 🟢 在线 / ⚫ 离线 徽标 - .fp-status-online 绿底绿字,.fp-status-offline 灰底灰字
This commit is contained in:
@@ -221,6 +221,28 @@
|
||||
font-size: 12px;
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
/* 在线状态小圆点 */
|
||||
.fp-status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
padding: 1px 6px;
|
||||
border-radius: 10px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.fp-status-online {
|
||||
background: #dcfce7;
|
||||
color: #15803d;
|
||||
}
|
||||
|
||||
.fp-status-offline {
|
||||
background: #f1f5f9;
|
||||
color: #94a3b8;
|
||||
}
|
||||
</style>
|
||||
|
||||
{{-- ════ HTML ════ --}}
|
||||
@@ -400,6 +422,11 @@
|
||||
name.className = 'fp-name';
|
||||
name.textContent = f.username;
|
||||
|
||||
// 在线状态标记(映名后)
|
||||
const status = document.createElement('span');
|
||||
status.className = 'fp-status ' + (f.is_online ? 'fp-status-online' : 'fp-status-offline');
|
||||
status.textContent = f.is_online ? '🟢 在线' : '⚫ 离线';
|
||||
|
||||
const badge = document.createElement('span');
|
||||
badge.className = 'fp-badge ' + (f.mutual ? 'fp-badge-mutual' : 'fp-badge-onesided');
|
||||
badge.textContent = f.mutual ? '💚 互相好友' : '👤 单向关注';
|
||||
@@ -413,7 +440,7 @@
|
||||
btn.textContent = '删除';
|
||||
btn.onclick = () => friendAction('remove', f.username, btn);
|
||||
|
||||
row.append(avatar, name, badge, date, btn);
|
||||
row.append(avatar, name, status, badge, date, btn);
|
||||
return row;
|
||||
}
|
||||
|
||||
@@ -436,6 +463,11 @@
|
||||
name.className = 'fp-name';
|
||||
name.textContent = p.username;
|
||||
|
||||
// 在线状态标记
|
||||
const status = document.createElement('span');
|
||||
status.className = 'fp-status ' + (p.is_online ? 'fp-status-online' : 'fp-status-offline');
|
||||
status.textContent = p.is_online ? '🟢 在线' : '⚫ 离线';
|
||||
|
||||
const date = document.createElement('span');
|
||||
date.className = 'fp-date';
|
||||
date.textContent = p.added_at ? '他于 ' + p.added_at + ' 添加了我' : '';
|
||||
@@ -445,7 +477,7 @@
|
||||
btn.textContent = '➕ 回加';
|
||||
btn.onclick = () => friendAction('add', p.username, btn);
|
||||
|
||||
row.append(avatar, name, date, btn);
|
||||
row.append(avatar, name, status, date, btn);
|
||||
return row;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user