diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php
index 62e3cb3..092329e 100644
--- a/app/Http/Controllers/ChatController.php
+++ b/app/Http/Controllers/ChatController.php
@@ -552,6 +552,31 @@ class ChatController extends Controller
]);
}
+ /**
+ * 返回所有房间的在线人数,供右侧房间面板轮询使用。
+ *
+ * 合并 rooms 数据库记录与 Redis 在线名单,
+ * 返回 [{ id, name, online, permit_level, door_open }] 数组。
+ */
+ public function roomsOnlineStatus(): JsonResponse
+ {
+ $rooms = Room::orderBy('id')->get(['id', 'room_name', 'permit_level', 'door_open']);
+
+ $data = $rooms->map(function (Room $room) {
+ $onlineCount = Redis::hlen("room:{$room->id}:users");
+
+ return [
+ 'id' => $room->id,
+ 'name' => $room->room_name,
+ 'online' => (int) $onlineCount,
+ 'permit_level' => $room->permit_level ?? 0,
+ 'door_open' => (bool) $room->door_open,
+ ];
+ });
+
+ return response()->json(['rooms' => $data]);
+ }
+
/**
* 离开房间 (等同于原版 LEAVE.ASP)
*
diff --git a/resources/views/chat/partials/right-panel.blade.php b/resources/views/chat/partials/right-panel.blade.php
index 1333d50..d99809a 100644
--- a/resources/views/chat/partials/right-panel.blade.php
+++ b/resources/views/chat/partials/right-panel.blade.php
@@ -55,8 +55,15 @@
{{-- 房间列表面板 --}}
-
-
打开大厅查看房间列表
+ {{-- 顶部标题栏 --}}
+
+
+ {{-- 房间列表容器 --}}
+
diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php
index ae479bb..11c898c 100644
--- a/resources/views/chat/partials/scripts.blade.php
+++ b/resources/views/chat/partials/scripts.blade.php
@@ -31,7 +31,7 @@
// 切换名单/房间/贴图/酷库 面板
['users', 'rooms', 'emoji', 'action'].forEach(t => {
document.getElementById('panel-' + t).style.display = t === tab ? 'block' : 'none';
- document.getElementById('tab-' + t).classList.toggle('active', t === tab);
+ document.getElementById('tab-' + t)?.classList.toggle('active', t === tab);
});
// 贴图 Tab 懒加载
if (tab === 'emoji') {
@@ -40,6 +40,64 @@
img.removeAttribute('data-src');
});
}
+ // 房间 Tab:拉取在线人数列表
+ if (tab === 'rooms') {
+ loadRoomsOnlineStatus();
+ }
+ }
+
+ /**
+ * 拉取所有房间在线人数并渲染到右侧面板
+ */
+ const _currentRoomId = {{ $room->id }};
+
+ function loadRoomsOnlineStatus() {
+ const container = document.getElementById('rooms-online-list');
+ if (!container) {
+ return;
+ }
+
+ fetch('{{ route('chat.rooms-online-status') }}')
+ .then(r => r.json())
+ .then(data => {
+ if (!data.rooms || !data.rooms.length) {
+ container.innerHTML =
+ '
暂无房间
';
+ return;
+ }
+ container.innerHTML = data.rooms.map(room => {
+ const isCurrent = room.id === _currentRoomId;
+ const closed = !room.door_open;
+ const bg = isCurrent ? '#ecf4ff' : '#fff';
+ const border = isCurrent ? '#aac5f0' : '#e0eaf5';
+ const nameColor = isCurrent ? '#336699' : (closed ? '#bbb' : '#444');
+ const badge = room.online > 0 ?
+ `
${room.online} 人` :
+ `
空`;
+ const currentTag = isCurrent ?
+ `
当前` :
+ '';
+ const clickHandler = isCurrent ? '' : `onclick="location.href='/room/${room.id}'"`;
+
+ return `
+
+ ${room.name}${currentTag}
+
+ ${badge}
+
`;
+ }).join('');
+ })
+ .catch(() => {
+ container.innerHTML =
+ '
加载失败
';
+ });
}
// ── 分屏切换 ──────────────────────────────────────
diff --git a/routes/web.php b/routes/web.php
index 43cddc1..2bb1366 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -147,6 +147,9 @@ Route::middleware(['chat.auth'])->group(function () {
// 退出房间
Route::post('/room/{id}/leave', [ChatController::class, 'leave'])->name('chat.leave');
+ // 所有房间在线人数(右侧房间面板用)
+ Route::get('/rooms/online-status', [ChatController::class, 'roomsOnlineStatus'])->name('chat.rooms-online-status');
+
// 头像列表(供选择)
Route::get('/headface/list', [ChatController::class, 'headfaceList'])->name('headface.list');