|  |  | 
 |  |  |  | 
 |  |  | <body> | 
 |  |  |   <div id="app"> | 
 |  |  |     <div class="search-bar"> | 
 |  |  |     <div class="search-bar" style="display: none;"> | 
 |  |  |       <input class="search-input" type="text" placeholder="请输入房间号查询" id="searchRoomInput"> | 
 |  |  |       <button class="search-btn" id="searchRoomBtn">查询</button> | 
 |  |  |     </div> | 
 |  |  |  | 
 |  |  |     <div class="header"> | 
 |  |  |     <div class="header" style="display: none;"> | 
 |  |  |       <div class="clinic-title">心电图诊间叫号系统</div> | 
 |  |  |       <div class="clinic-info"> | 
 |  |  |         <div class="room-name" id="roomName">诊间加载中...</div> | 
 |  |  | 
 |  |  |  | 
 |  |  |     <div class="main-content"> | 
 |  |  |       <div class="panel"> | 
 |  |  |         <div class="panel-header">检查队列</div> | 
 |  |  |         <div class="panel-header">等待队列</div> | 
 |  |  |         <div class="patient-list" id="checkPatientList"> | 
 |  |  |           <div class="empty-state"> | 
 |  |  |             暂无等待检查的患者 | 
 |  |  | 
 |  |  |       </div> | 
 |  |  |     </div> | 
 |  |  |  | 
 |  |  |     <div class="footer"> | 
 |  |  |     <div class="footer" style="display: none;"> | 
 |  |  |       <div class="announcement" id="announcementText"> | 
 |  |  |         系统运行中... | 
 |  |  |       </div> | 
 |  |  | 
 |  |  |     // 页面加载完成后初始化 | 
 |  |  |     // 页面加载完成后初始化 | 
 |  |  |     document.addEventListener('DOMContentLoaded', function () { | 
 |  |  |        // 从URL获取roomId参数 | 
 |  |  |   const urlParams = new URLSearchParams(window.location.search); | 
 |  |  |   const roomId = urlParams.get('roomId') || '1'; // 默认值1 | 
 |  |  |    | 
 |  |  |   // 设置到搜索框(可选) | 
 |  |  |   document.getElementById('searchRoomInput').value = roomId; | 
 |  |  |       // 初始化事件监听 | 
 |  |  |       document.getElementById('searchRoomBtn').addEventListener('click', searchRoom); | 
 |  |  |       document.getElementById('callBtn').addEventListener('click', initiateSpeak); | 
 |  |  | 
 |  |  |       document.getElementById('changeRoomBtn').addEventListener('click', changeRoom); | 
 |  |  |  | 
 |  |  |       // 初始化数据 | 
 |  |  |       getRoomByIp(); | 
 |  |  |       getRoomByIp(roomId); | 
 |  |  |       startScrolling(); | 
 |  |  |  | 
 |  |  |       // 初始化语音合成 | 
 |  |  | 
 |  |  |       xhr.send(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     function getRoomByIp() { | 
 |  |  |       var searchInput = document.getElementById('searchRoomInput').value.trim(); | 
 |  |  |     function getRoomByIp(roomId) { | 
 |  |  |   // 如果未传递roomId,尝试从输入框获取 | 
 |  |  |   if (!roomId) { | 
 |  |  |     roomId = document.getElementById('searchRoomInput').value.trim() || '1'; | 
 |  |  |   } | 
 |  |  |  | 
 |  |  |       var xhr = new XMLHttpRequest(); | 
 |  |  |       xhr.open('GET', appState.apiBaseUrl + '/ecg/screen/room-screen-data?roomId=' + encodeURIComponent(searchInput), true); | 
 |  |  |       xhr.onreadystatechange = function () { | 
 |  |  |         if (xhr.readyState === 4) { | 
 |  |  |           if (xhr.status === 200) { | 
 |  |  |             try { | 
 |  |  |               var response = JSON.parse(xhr.responseText); | 
 |  |  |               appState.roomProfile = response.data || response; | 
 |  |  |               updateRoomInfo(); | 
 |  |  |   var xhr = new XMLHttpRequest(); | 
 |  |  |   xhr.open('GET', appState.apiBaseUrl + '/ecg/screen/room-screen-data?roomId=' + encodeURIComponent(roomId), true); | 
 |  |  |   xhr.onreadystatechange = function() { | 
 |  |  |     if (xhr.readyState === 4) { | 
 |  |  |       if (xhr.status === 200) { | 
 |  |  |         try { | 
 |  |  |           var response = JSON.parse(xhr.responseText); | 
 |  |  |           appState.roomProfile = response.data || response; | 
 |  |  |           updateRoomInfo(); | 
 |  |  |  | 
 |  |  |               // 检查是否有需要叫号的患者 | 
 |  |  |               if (response.data && response.data.called === 0) { | 
 |  |  |                 appState.curSpeakPat = response.data; | 
 |  |  |                 speak('请' + response.data.patName + '到' + appState.roomProfile.roomName + '装机'); | 
 |  |  |               } | 
 |  |  |             } catch (e) { | 
 |  |  |               console.error('解析响应失败:', e); | 
 |  |  |               // 使用模拟数据作为后备 | 
 |  |  |               appState.roomProfile = { | 
 |  |  |                 roomName: '心电图诊室 ' + (appState.roomId + 1), | 
 |  |  |                 callingScreenType: [40, 10, 30][appState.roomId % 3] | 
 |  |  |               }; | 
 |  |  |               updateRoomInfo(); | 
 |  |  |             } | 
 |  |  |           } else { | 
 |  |  |             console.error('获取房间信息失败:', xhr.status); | 
 |  |  |             // 使用模拟数据作为后备 | 
 |  |  |             appState.roomProfile = { | 
 |  |  |               roomName: '心电图诊室 ' + (appState.roomId + 1), | 
 |  |  |               callingScreenType: [40, 10, 30][appState.roomId % 3] | 
 |  |  |             }; | 
 |  |  |             updateRoomInfo(); | 
 |  |  |           // 更新当前roomId状态 | 
 |  |  |           appState.roomId = roomId; | 
 |  |  |  | 
 |  |  |           // 检查是否需要叫号 | 
 |  |  |           if (response.data && response.data.called === 0) { | 
 |  |  |             appState.curSpeakPat = response.data; | 
 |  |  |             speak('请' + response.data.patName + '到' + appState.roomProfile.roomName + '装机'); | 
 |  |  |           } | 
 |  |  |         } catch (e) { | 
 |  |  |           console.error('解析响应失败:', e); | 
 |  |  |           fallbackRoomData(roomId); | 
 |  |  |         } | 
 |  |  |       }; | 
 |  |  |       xhr.send(); | 
 |  |  |       } else { | 
 |  |  |         console.error('获取房间信息失败:', xhr.status); | 
 |  |  |         fallbackRoomData(roomId); | 
 |  |  |       } | 
 |  |  |     } | 
 |  |  |   }; | 
 |  |  |   xhr.send(); | 
 |  |  | } | 
 |  |  |  | 
 |  |  | // 后备数据函数 | 
 |  |  | function fallbackRoomData(roomId) { | 
 |  |  |   appState.roomProfile = { | 
 |  |  |     roomName: '心电图诊室 ' + roomId, | 
 |  |  |     callingScreenType: [40, 10, 30][roomId % 3] | 
 |  |  |   }; | 
 |  |  |   updateRoomInfo(); | 
 |  |  | } | 
 |  |  |  | 
 |  |  |     // 更新房间信息显示 | 
 |  |  |     function updateRoomInfo() { | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 切换房间 | 
 |  |  |     function changeRoom() { | 
 |  |  |       appState.roomId = (appState.roomId + 1) % 3; | 
 |  |  |       getRoomByIp(); | 
 |  |  |       updateAnnouncement('正在切换诊间...'); | 
 |  |  |     } | 
 |  |  |   function changeRoom() { | 
 |  |  |   // 轮换roomId(示例:1→2→3→1) | 
 |  |  |   const newRoomId = (parseInt(appState.roomId) % 3) + 1; | 
 |  |  |    | 
 |  |  |   // 更新URL但不刷新页面 | 
 |  |  |   window.history.pushState({}, '', `?roomId=${newRoomId}`); | 
 |  |  |    | 
 |  |  |   // 重新加载数据 | 
 |  |  |   getRoomByIp(newRoomId.toString()); | 
 |  |  |   updateAnnouncement('正在切换到诊间 ' + newRoomId); | 
 |  |  | } | 
 |  |  |   </script> | 
 |  |  | </body> | 
 |  |  |  |