mobile.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <title>钢包视频监测</title>
  8. <link rel="icon" href="/logo.png" type="image/png">
  9. <style>
  10. *{margin:0;padding:0;box-sizing:border-box;-webkit-tap-highlight-color:transparent}
  11. body{font-family:system-ui,sans-serif;background:#0b1220;color:#e8e8e8;height:100vh;overflow:hidden}
  12. .hidden{display:none!important}
  13. /* 登录 */
  14. #loginPage{display:flex;flex-direction:column;justify-content:center;align-items:center;height:100vh;padding:24px;background:#0b1220}
  15. #loginPage .logo{width:64px;height:64px;margin-bottom:16px}
  16. #loginPage h1{font-size:20px;margin-bottom:24px;color:#e94560}
  17. #loginPage input{width:100%;max-width:320px;padding:12px 14px;margin-bottom:12px;border:1px solid #0f3460;background:#0e1426;color:#eee;font-size:16px;border-radius:6px}
  18. #loginPage button{width:100%;max-width:320px;padding:12px;background:#e94560;color:#fff;border:none;font-size:16px;border-radius:6px;cursor:pointer}
  19. #loginErr{color:#e94560;font-size:13px;margin-bottom:12px;min-height:18px}
  20. /* 主界面 */
  21. #appPage{display:flex;flex-direction:column;height:100vh}
  22. .topbar{display:flex;align-items:center;padding:10px 12px;background:#0e1426;border-bottom:1px solid #0f3460;flex-shrink:0}
  23. .topbar h2{font-size:16px;flex:1;color:#eee}
  24. .topbar .tab{display:flex;gap:4px}
  25. .topbar .tab button{padding:6px 12px;background:transparent;border:none;color:#8892a8;font-size:14px;cursor:pointer;border-radius:4px}
  26. .topbar .tab button.active{background:#182242;color:#e94560;font-weight:bold}
  27. /* 视频页 */
  28. #videoPage{flex:1;display:flex;flex-direction:column;overflow:hidden}
  29. #videoWrap{flex:1;position:relative;background:#000;min-height:0}
  30. #videoWrap img{width:100%;height:100%;object-fit:contain;display:block}
  31. #videoLoader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);color:#888}
  32. .chSwitcher{display:flex;overflow-x:auto;padding:8px;background:#0e1426;border-top:1px solid #0f3460;flex-shrink:0}
  33. .chSwitcher button{padding:8px 14px;margin-right:8px;background:#0f3460;border:none;color:#eee;border-radius:4px;font-size:13px;white-space:nowrap;cursor:pointer}
  34. .chSwitcher button.active{background:#e94560}
  35. /* 报警页 */
  36. #alarmPage{flex:1;overflow-y:auto;padding:12px}
  37. .filterBar{display:flex;gap:8px;margin-bottom:12px;flex-wrap:wrap}
  38. .filterBar select,.filterBar input{padding:8px;background:#0e1426;border:1px solid #0f3460;color:#eee;font-size:13px;border-radius:4px}
  39. .filterBar select{flex:1;min-width:100px}
  40. .filterBar input[type=datetime-local]{flex:1;min-width:130px}
  41. .alarmItem{display:flex;gap:10px;padding:10px;margin-bottom:10px;background:#0e1426;border:1px solid #0f3460;border-left:4px solid #e94560;border-radius:6px}
  42. .alarmItem img{width:72px;height:54px;object-fit:cover;border-radius:4px;flex-shrink:0}
  43. .alarmItem .info{flex:1;min-width:0}
  44. .alarmItem .time{font-size:11px;color:#888;margin-bottom:4px}
  45. .alarmItem .type{font-size:14px;font-weight:bold;margin-bottom:2px}
  46. .alarmItem .meta{font-size:12px;color:#aaa}
  47. .alarmItem .conf{font-size:12px;color:#27ae60}
  48. /* 详情弹窗 */
  49. .modal{position:fixed;inset:0;background:rgba(0,0,0,.9);z-index:50;display:none;flex-direction:column}
  50. .modal.show{display:flex}
  51. .modal img{flex:1;object-fit:contain;min-height:0}
  52. .modal .mbar{display:flex;align-items:center;padding:10px 14px;background:#0e1426;border-top:1px solid #0f3460}
  53. .modal .mbar .minfo{flex:1;font-size:13px}
  54. .modal .mbar button{padding:8px 16px;background:#e94560;border:none;color:#fff;border-radius:4px;font-size:14px}
  55. .toast{position:fixed;top:20px;left:50%;transform:translateX(-50%);background:rgba(233,69,96,.95);color:#fff;padding:10px 18px;border-radius:6px;font-size:14px;z-index:99;display:none}
  56. .empty-tip{text-align:center;color:#666;padding:40px 0;font-size:14px}
  57. </style>
  58. </head>
  59. <body>
  60. <div id="loginPage">
  61. <img class="logo" src="/logo.png">
  62. <h1>钢包视频监测</h1>
  63. <div id="loginErr"></div>
  64. <input type="text" id="loginUser" placeholder="用户名" value="admin">
  65. <input type="password" id="loginPass" placeholder="密码" value="admin">
  66. <button onclick="doLogin()">登 录</button>
  67. </div>
  68. <div id="appPage" class="hidden">
  69. <div class="topbar">
  70. <h2 id="pageTitle">视频监控</h2>
  71. <div class="tab">
  72. <button id="tabVideo" class="active" onclick="switchTab('video')">视频</button>
  73. <button id="tabAlarm" onclick="switchTab('alarm')">报警</button>
  74. </div>
  75. </div>
  76. <div id="videoPage">
  77. <div id="videoWrap">
  78. <img id="video" alt="">
  79. <div id="videoLoader">加载中...</div>
  80. </div>
  81. <div class="chSwitcher" id="chSwitcher"></div>
  82. </div>
  83. <div id="alarmPage" class="hidden">
  84. <div class="filterBar">
  85. <select id="fltType" onchange="loadAlarms()">
  86. <option value="">全部类型</option>
  87. <option value="fence">围栏报警</option>
  88. <option value="pose">姿态报警</option>
  89. </select>
  90. <select id="fltCh" onchange="loadAlarms()"><option value="">全部通道</option></select>
  91. <input type="datetime-local" id="fltStart">
  92. <input type="datetime-local" id="fltEnd">
  93. <button onclick="loadAlarms()" style="padding:8px 12px;background:#e94560;border:none;color:#fff;border-radius:4px">查询</button>
  94. </div>
  95. <div id="alarmList"></div>
  96. </div>
  97. </div>
  98. <div class="modal" id="detailModal">
  99. <img id="detailImg" alt="">
  100. <div class="mbar">
  101. <div class="minfo" id="detailInfo"></div>
  102. <button onclick="closeDetail()">关闭</button>
  103. </div>
  104. </div>
  105. <div class="toast" id="toast"></div>
  106. <script>
  107. let channels = [];
  108. let curChannel = 0;
  109. let curType = '';
  110. function toast(msg) {
  111. const t = document.getElementById('toast');
  112. t.textContent = msg;
  113. t.style.display = 'block';
  114. setTimeout(() => t.style.display = 'none', 2500);
  115. }
  116. async function doLogin() {
  117. const u = document.getElementById('loginUser').value;
  118. const p = document.getElementById('loginPass').value;
  119. try {
  120. const r = await fetch('/api/login', {
  121. method: 'POST',
  122. headers: {'Content-Type': 'application/json'},
  123. body: JSON.stringify({username: u, password: p})
  124. });
  125. const d = await r.json();
  126. if (d.ok) {
  127. document.getElementById('loginPage').classList.add('hidden');
  128. document.getElementById('appPage').classList.remove('hidden');
  129. init();
  130. } else {
  131. document.getElementById('loginErr').textContent = d.error || '登录失败';
  132. }
  133. } catch (e) {
  134. document.getElementById('loginErr').textContent = '网络错误';
  135. }
  136. }
  137. async function init() {
  138. await loadChannels();
  139. renderChSwitcher();
  140. switchChannel(0);
  141. }
  142. async function loadChannels() {
  143. try {
  144. const r = await fetch('/api/status');
  145. if (r.status === 401) { location.reload(); return; }
  146. const d = await r.json();
  147. channels = d.channels || [];
  148. const sel = document.getElementById('fltCh');
  149. sel.innerHTML = '<option value="">全部通道</option>' +
  150. channels.map(c => `<option value="${c.id}">CH${c.id} ${c.name||''}</option>`).join('');
  151. } catch (e) {}
  152. }
  153. function renderChSwitcher() {
  154. const sw = document.getElementById('chSwitcher');
  155. sw.innerHTML = channels.map(c =>
  156. `<button data-ch="${c.id}" class="${c.id===curChannel?'active':''}" onclick="switchChannel(${c.id})">CH${c.id} ${c.name||''}</button>`).join('');
  157. }
  158. function switchChannel(id) {
  159. curChannel = id;
  160. renderChSwitcher();
  161. const v = document.getElementById('video');
  162. v.src = '/mjpeg/' + id + '?t=' + Date.now();
  163. document.getElementById('videoLoader').style.display = 'block';
  164. v.onload = () => { document.getElementById('videoLoader').style.display = 'none'; };
  165. v.onerror = () => {
  166. document.getElementById('videoLoader').textContent = '视频加载失败';
  167. // 3秒后自动重试
  168. setTimeout(() => {
  169. if (curChannel === id) {
  170. document.getElementById('videoLoader').textContent = '重试中...';
  171. v.src = '/mjpeg/' + id + '?t=' + Date.now();
  172. }
  173. }, 3000);
  174. };
  175. }
  176. function switchTab(tab) {
  177. document.getElementById('tabVideo').classList.toggle('active', tab==='video');
  178. document.getElementById('tabAlarm').classList.toggle('active', tab==='alarm');
  179. document.getElementById('videoPage').classList.toggle('hidden', tab!=='video');
  180. document.getElementById('alarmPage').classList.toggle('hidden', tab!=='alarm');
  181. if (tab === 'alarm') loadAlarms();
  182. }
  183. function poseColor(a) {
  184. const m = {'跌倒':'#e94560','倒地':'#e94560','举手呼救':'#f39c12','异常蹲坐':'#3498db','半躺':'#9b59b6','手近嘴部':'#e67e22','疲劳瞌睡':'#8e44ad','长时间静止':'#2c3e50','疑似离岗':'#c0392b'};
  185. return m[a] || '#8892a8';
  186. }
  187. async function loadAlarms() {
  188. const type = document.getElementById('fltType').value;
  189. const ch = document.getElementById('fltCh').value;
  190. const st = document.getElementById('fltStart').value.replace('T',' ');
  191. const en = document.getElementById('fltEnd').value.replace('T',' ');
  192. const qs = new URLSearchParams();
  193. if (ch) qs.set('channel', ch);
  194. if (st) qs.set('start', st + ':00');
  195. if (en) qs.set('end', en + ':59');
  196. try {
  197. const [fr, pr] = await Promise.all([
  198. fetch('/api/alarms' + (qs ? '?' + qs : '')),
  199. fetch('/api/pose/alarms' + (qs ? '?' + qs : ''))
  200. ]);
  201. const fd = await fr.json(), pd = await pr.json();
  202. const fence = (fd.items||[]).map(a => ({t:'围栏', ts:a.timestamp, ch:a.channel, label:a.fence_name, detail:a.class_name, conf:a.confidence, img:a.screenshot, color:'#27ae60'}));
  203. const pose = (pd.items||[]).map(a => ({t:a.action, ts:a.timestamp, ch:a.channel, label:a.action, detail:'姿态', conf:a.score, img:a.screenshot, color:poseColor(a.action)}));
  204. let items = type==='fence' ? fence : type==='pose' ? pose : [...fence, ...pose];
  205. items.sort((a,b) => b.ts.localeCompare(a.ts));
  206. const list = document.getElementById('alarmList');
  207. if (!items.length) { list.innerHTML = '<div class="empty-tip">暂无报警记录</div>'; return; }
  208. list.innerHTML = items.slice(0,100).map(a => `
  209. <div class="alarmItem" style="border-left-color:${a.color}" onclick="showDetail('${a.img}','${a.ts}','${a.label}','${a.detail}',${a.conf},${a.ch})">
  210. <img src="/${a.img}" loading="lazy">
  211. <div class="info">
  212. <div class="time">${a.ts} · CH${a.ch}</div>
  213. <div class="type" style="color:${a.color}">${a.label}</div>
  214. <div class="meta">${a.detail}</div>
  215. <div class="conf">${(a.conf*100).toFixed(0)}%</div>
  216. </div>
  217. </div>`).join('');
  218. } catch (e) {}
  219. }
  220. function showDetail(img, ts, label, detail, conf, ch) {
  221. document.getElementById('detailImg').src = '/' + img;
  222. document.getElementById('detailInfo').innerHTML =
  223. `<b>${label}</b> ${(conf*100).toFixed(0)}%<br>时间: ${ts}<br>通道: CH${ch}<br>详情: ${detail}`;
  224. document.getElementById('detailModal').classList.add('show');
  225. }
  226. function closeDetail() { document.getElementById('detailModal').classList.remove('show'); }
  227. // 每10秒刷新报警
  228. setInterval(() => {
  229. if (!document.getElementById('alarmPage').classList.contains('hidden')) loadAlarms();
  230. }, 10000);
  231. </script>
  232. </body>
  233. </html>