lukehuang6666 commited on
Commit
4d944f2
·
verified ·
1 Parent(s): 7ff08a1

Upload 7 files

Browse files
.gitattributes CHANGED
@@ -59,3 +59,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
  gengyishi2/model/person.engine filter=lfs diff=lfs merge=lfs -text
 
 
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
  gengyishi2/model/person.engine filter=lfs diff=lfs merge=lfs -text
62
+ handwash-show-0.0.1-SNAPSHOT.jar filter=lfs diff=lfs merge=lfs -text
application.properties ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ spring.datasource.url=jdbc:mysql://127.0.0.1:3306/procedure?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
2
+ spring.datasource.username=root
3
+ spring.datasource.password=123456
4
+ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
5
+
6
+ # 洗手/沾尘后端(handwash-show)
7
+ server.address=0.0.0.0
8
+ server.port=8082
9
+
10
+ mybatis.type-aliases-package=com.ofilm.procedure.handwashshow.model
11
+ mybatis.mapper-locations=classpath*:mapper/*.xml
12
+ mybatis.configuration.map-underscore-to-camel-case=true
13
+
14
+ app.websocket.allowed-origins=*
15
+ app.summary.push-ms=5000
16
+ logging.level.com.ofilm.procedure=INFO
17
+
18
+ # 回放文件声明:回放 MP4 在算法端,本 Web 端不存储 clips,也不对外提供 /clips/
19
+ clip.base-dir=
20
+ clip.retention-days=7
21
+
gengyishi2/analytics.html ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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">
6
+ <title>数据分析 - A2栋1F-COB无尘管理监控 洗手/沾尘</title>
7
+ <link rel="stylesheet" href="styles.css">
8
+ <!-- 内网环境可能无法访问 CDN,这里改为本地引用 -->
9
+ <script src="chart.umd.min.js"></script>
10
+ </head>
11
+ <body class="page">
12
+ <!-- 临时访问控制:未登录时遮罩并阻止查看页面内容(仅前端校验,适合临时管控) -->
13
+ <div class="auth-mask auth-hide" id="auth-mask">
14
+ <div class="auth-card">
15
+ <div class="auth-title">访问验证</div>
16
+ <div class="auth-desc">请输入账号密码后查看页面内容</div>
17
+ <div class="auth-row">
18
+ <div class="auth-field">
19
+ <label for="auth-user">账号</label>
20
+ <input class="auth-input" id="auth-user" autocomplete="username" />
21
+ </div>
22
+ <div class="auth-field">
23
+ <label for="auth-pass">密码</label>
24
+ <input class="auth-input" id="auth-pass" type="password" autocomplete="current-password" />
25
+ </div>
26
+ </div>
27
+ <div class="auth-error" id="auth-err"></div>
28
+ <div class="auth-actions">
29
+ <button class="btn" id="auth-login-btn">登录</button>
30
+ </div>
31
+ </div>
32
+ </div>
33
+
34
+ <div id="app-root" class="auth-hide">
35
+ <header class="header">
36
+ <div>
37
+ <h1>数据分析</h1>
38
+ <div class="muted">洗手 / 沾尘(趋势 + 分布)</div>
39
+ </div>
40
+ <div class="status">
41
+ <button class="btn" id="back-btn">返回主页</button>
42
+ <span class="dot dot-ok" id="ana-dot"></span>
43
+ <span id="ana-status">就绪</span>
44
+ </div>
45
+ </header>
46
+
47
+ <div class="ana-tabs">
48
+ <button class="ana-tab" id="tab-wash" data-tab="wash">洗手</button>
49
+ <button class="ana-tab" id="tab-dust" data-tab="dust">沾尘</button>
50
+ </div>
51
+
52
+ <section class="ana-grid">
53
+ <!-- 日趋势 -->
54
+ <div class="panel ana-panel">
55
+ <div class="panel-header">
56
+ <div>
57
+ <div class="title" id="daily-title">按日趋势</div>
58
+ <div class="muted">柱:总/OK/NG(含 UNKNOWN)|线:合格率(OK/(OK+NG))</div>
59
+ </div>
60
+ <div class="ana-controls">
61
+ <label>开始 <input type="date" id="daily-start"></label>
62
+ <button class="btn ana-iconbtn" id="daily-start-pick" title="打开日期选择器">📅</button>
63
+ <label>结束 <input type="date" id="daily-end"></label>
64
+ <button class="btn ana-iconbtn" id="daily-end-pick" title="打开日期选择器">📅</button>
65
+ <button class="btn" id="daily-refresh">刷新</button>
66
+ <div class="ana-quick">
67
+ <button class="btn" id="daily-quick-today">今天</button>
68
+ <button class="btn" id="daily-quick-yesterday">昨天</button>
69
+ <button class="btn" id="daily-quick-7d">近7天</button>
70
+ </div>
71
+ </div>
72
+ </div>
73
+ <div class="ana-chart">
74
+ <canvas id="daily-chart"></canvas>
75
+ </div>
76
+ </div>
77
+
78
+ <!-- 小时趋势 -->
79
+ <div class="panel ana-panel">
80
+ <div class="panel-header">
81
+ <div>
82
+ <div class="title" id="hourly-title">按小时趋势</div>
83
+ <div class="muted">同上口径</div>
84
+ </div>
85
+ <div class="ana-controls">
86
+ <label>日期 <input type="date" id="hourly-date"></label>
87
+ <button class="btn ana-iconbtn" id="hourly-date-pick" title="打开日期选择器">📅</button>
88
+ <button class="btn" id="hourly-refresh">刷新</button>
89
+ <div class="ana-quick">
90
+ <button class="btn" id="hourly-quick-today">今天</button>
91
+ <button class="btn" id="hourly-quick-yesterday">昨天</button>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ <div class="ana-chart">
96
+ <canvas id="hourly-chart"></canvas>
97
+ </div>
98
+ </div>
99
+
100
+ <!-- 分桶饼图 -->
101
+ <div class="panel ana-panel ana-panel-wide">
102
+ <div class="panel-header">
103
+ <div>
104
+ <div class="title" id="bucket-title">时长分布(时间范围)</div>
105
+ <div class="muted">次数 + 占比:未洗手/未沾尘、2s以下、3-5s、5-10s、10s以上、追踪失败-遮挡</div>
106
+ </div>
107
+ <div class="ana-controls">
108
+ <label>开始 <input type="datetime-local" id="bucket-start"></label>
109
+ <button class="btn ana-iconbtn" id="bucket-start-pick" title="打开时间选择器">🕒</button>
110
+ <label>结束 <input type="datetime-local" id="bucket-end"></label>
111
+ <button class="btn ana-iconbtn" id="bucket-end-pick" title="打开时间选择器">🕒</button>
112
+ <button class="btn" id="bucket-refresh">刷新</button>
113
+ <div class="ana-quick">
114
+ <button class="btn" id="bucket-quick-today-0">今天00:00~现在</button>
115
+ <button class="btn" id="bucket-quick-yesterday-0">昨天00:00~现在</button>
116
+ </div>
117
+ </div>
118
+ </div>
119
+ <div class="ana-split">
120
+ <div class="ana-chart">
121
+ <canvas id="bucket-chart"></canvas>
122
+ </div>
123
+ <div class="ana-legend">
124
+ <div class="muted" id="bucket-total">总数:0</div>
125
+ <div class="ana-table" id="bucket-table"></div>
126
+ </div>
127
+ </div>
128
+ </div>
129
+ </section>
130
+
131
+ <script>
132
+ // =============================
133
+ // 临时访问控制配置(只做“管控”,不做真正安全)
134
+ // =============================
135
+ const ACCESS_GUARD_ENABLED = false;
136
+ const ACCESS_GUARD_TTL_MS = 8 * 60 * 60 * 1000; // 登录有效期:8小时
137
+ const ACCESS_GUARD_USERS = [
138
+ { user: 'N231310', pass: 'Ahh123321' },
139
+ { user: 'H012F', pass: 'As123456' },
140
+ { user: 'T10929', pass: 'As123456' },
141
+ ];
142
+ const ACCESS_GUARD_KEY = 'handwash_guard_ok_gengyishi2';
143
+
144
+ function guardIsOk() {
145
+ try {
146
+ const raw = localStorage.getItem(ACCESS_GUARD_KEY);
147
+ if (!raw) return false;
148
+ const v = JSON.parse(raw);
149
+ if (!v || !v.ok || !v.ts) return false;
150
+ return (Date.now() - v.ts) <= ACCESS_GUARD_TTL_MS;
151
+ } catch {
152
+ return false;
153
+ }
154
+ }
155
+ function guardSetOk() {
156
+ try { localStorage.setItem(ACCESS_GUARD_KEY, JSON.stringify({ ok: true, ts: Date.now() })); } catch {}
157
+ }
158
+ function guardShowLogin() {
159
+ const mask = document.getElementById('auth-mask');
160
+ const root = document.getElementById('app-root');
161
+ if (mask) mask.classList.remove('auth-hide');
162
+ if (root) root.classList.add('auth-hide');
163
+ }
164
+ function guardShowApp() {
165
+ const mask = document.getElementById('auth-mask');
166
+ const root = document.getElementById('app-root');
167
+ if (mask) mask.classList.add('auth-hide');
168
+ if (root) root.classList.remove('auth-hide');
169
+ }
170
+ function guardTryLogin() {
171
+ const u = (document.getElementById('auth-user')?.value || '').trim();
172
+ const p = (document.getElementById('auth-pass')?.value || '');
173
+ const err = document.getElementById('auth-err');
174
+ const ok = ACCESS_GUARD_USERS.some(x => x.user === u && x.pass === p);
175
+ if (!ok) {
176
+ if (err) err.textContent = '账号或密码错误';
177
+ return false;
178
+ }
179
+ if (err) err.textContent = '';
180
+ guardSetOk();
181
+ guardShowApp();
182
+ return true;
183
+ }
184
+
185
+ const apiProto = (location.protocol === 'https:') ? 'https:' : 'http:';
186
+ const qs = new URLSearchParams(location.search);
187
+ // 后端统计接口固定走 151;可通过 ?backendOrigin= 覆盖
188
+ const BACKEND_ORIGIN = (() => {
189
+ const v = (qs.get('backendOrigin') || '').trim();
190
+ if (v) return v.replace(/\/+$/, '');
191
+ if (location.host) return `${apiProto}//${location.host}`;
192
+ return 'http://192.168.55.36:8088';
193
+ })();
194
+ const PROJECT_KEY = (qs.get('project') || 'gengyishi2').trim();
195
+ function withProject(url) {
196
+ if (!PROJECT_KEY) return url;
197
+ const join = url.includes('?') ? '&' : '?';
198
+ return `${url}${join}project=${encodeURIComponent(PROJECT_KEY)}`;
199
+ }
200
+ // 更衣室2:洗手=相机3,沾尘=相机4
201
+ const CAMERA_IDS = '3,4';
202
+ function withCameraIds(url) {
203
+ const join = url.includes('?') ? '&' : '?';
204
+ return `${url}${join}cameraIds=${encodeURIComponent(CAMERA_IDS)}`;
205
+ }
206
+ const API_WASH = `${BACKEND_ORIGIN}/gengyishi/api/wash`;
207
+ const API_DUST = `${BACKEND_ORIGIN}/gengyishi/api/dust`;
208
+
209
+ // const qs = new URLSearchParams(location.search);
210
+ let currentTab = (qs.get('tab') || 'wash').toLowerCase();
211
+ if (currentTab !== 'wash' && currentTab !== 'dust') currentTab = 'wash';
212
+
213
+ const els = {
214
+ status: document.getElementById('ana-status'),
215
+ back: document.getElementById('back-btn'),
216
+ tabWash: document.getElementById('tab-wash'),
217
+ tabDust: document.getElementById('tab-dust'),
218
+ dailyStart: document.getElementById('daily-start'),
219
+ dailyEnd: document.getElementById('daily-end'),
220
+ dailyStartPick: document.getElementById('daily-start-pick'),
221
+ dailyEndPick: document.getElementById('daily-end-pick'),
222
+ dailyRefresh: document.getElementById('daily-refresh'),
223
+ dailyQuickToday: document.getElementById('daily-quick-today'),
224
+ dailyQuickYesterday: document.getElementById('daily-quick-yesterday'),
225
+ dailyQuick7d: document.getElementById('daily-quick-7d'),
226
+ hourlyDate: document.getElementById('hourly-date'),
227
+ hourlyDatePick: document.getElementById('hourly-date-pick'),
228
+ hourlyRefresh: document.getElementById('hourly-refresh'),
229
+ hourlyQuickToday: document.getElementById('hourly-quick-today'),
230
+ hourlyQuickYesterday: document.getElementById('hourly-quick-yesterday'),
231
+ bucketStart: document.getElementById('bucket-start'),
232
+ bucketEnd: document.getElementById('bucket-end'),
233
+ bucketStartPick: document.getElementById('bucket-start-pick'),
234
+ bucketEndPick: document.getElementById('bucket-end-pick'),
235
+ bucketRefresh: document.getElementById('bucket-refresh'),
236
+ bucketQuickToday0: document.getElementById('bucket-quick-today-0'),
237
+ bucketQuickYesterday0: document.getElementById('bucket-quick-yesterday-0'),
238
+ bucketTotal: document.getElementById('bucket-total'),
239
+ bucketTable: document.getElementById('bucket-table'),
240
+ };
241
+
242
+ function setStatus(t) { els.status.textContent = t; }
243
+
244
+ function pad2(n){ return n < 10 ? '0'+n : ''+n; }
245
+ function toDateInput(d){ return `${d.getFullYear()}-${pad2(d.getMonth()+1)}-${pad2(d.getDate())}`; }
246
+ function toDateTimeLocal(d){ return `${toDateInput(d)}T${pad2(d.getHours())}:${pad2(d.getMinutes())}`; }
247
+
248
+ function showNativePicker(inputEl) {
249
+ if (!inputEl) return;
250
+ // Chromium 支持 showPicker;不支持就 focus,让浏览器尽量弹出原生选择器
251
+ try {
252
+ if (typeof inputEl.showPicker === 'function') {
253
+ inputEl.showPicker();
254
+ return;
255
+ }
256
+ } catch {}
257
+ try { inputEl.focus(); } catch {}
258
+ try { inputEl.click(); } catch {}
259
+ }
260
+
261
+ // 默认:最近 7 天;小时:今天;分桶:今天 08:00~现在
262
+ const now = new Date();
263
+ const d7 = new Date(now);
264
+ d7.setDate(now.getDate() - 6);
265
+ els.dailyStart.value = toDateInput(d7);
266
+ els.dailyEnd.value = toDateInput(now);
267
+ els.hourlyDate.value = toDateInput(now);
268
+ const b0 = new Date(now); b0.setHours(8,0,0,0);
269
+ els.bucketStart.value = toDateTimeLocal(b0);
270
+ els.bucketEnd.value = toDateTimeLocal(now);
271
+
272
+ els.back.addEventListener('click', () => {
273
+ const proj = PROJECT_KEY ? `?project=${encodeURIComponent(PROJECT_KEY)}` : '';
274
+ location.href = `index.html${proj}`;
275
+ });
276
+
277
+ function apiBase() { return currentTab === 'wash' ? API_WASH : API_DUST; }
278
+
279
+ function setActiveTab() {
280
+ els.tabWash.className = 'ana-tab' + (currentTab === 'wash' ? ' active' : '');
281
+ els.tabDust.className = 'ana-tab' + (currentTab === 'dust' ? ' active' : '');
282
+ document.title = (currentTab === 'wash') ? '数据分析 - 洗手' : '数据分析 - 沾尘';
283
+ }
284
+ els.tabWash.addEventListener('click', () => { currentTab = 'wash'; setActiveTab(); refreshAll(); });
285
+ els.tabDust.addEventListener('click', () => { currentTab = 'dust'; setActiveTab(); refreshAll(); });
286
+
287
+ // 无键盘:原生选择器按钮
288
+ if (els.dailyStartPick) els.dailyStartPick.addEventListener('click', () => showNativePicker(els.dailyStart));
289
+ if (els.dailyEndPick) els.dailyEndPick.addEventListener('click', () => showNativePicker(els.dailyEnd));
290
+ if (els.hourlyDatePick) els.hourlyDatePick.addEventListener('click', () => showNativePicker(els.hourlyDate));
291
+ if (els.bucketStartPick) els.bucketStartPick.addEventListener('click', () => showNativePicker(els.bucketStart));
292
+ if (els.bucketEndPick) els.bucketEndPick.addEventListener('click', () => showNativePicker(els.bucketEnd));
293
+
294
+ // 无键盘:快捷区间
295
+ const setDailyRange = (startDate, endDate) => {
296
+ els.dailyStart.value = toDateInput(startDate);
297
+ els.dailyEnd.value = toDateInput(endDate);
298
+ refreshDaily().catch(e => setStatus('拉取失败:' + e.message));
299
+ };
300
+ if (els.dailyQuickToday) els.dailyQuickToday.addEventListener('click', () => setDailyRange(new Date(now), new Date(now)));
301
+ if (els.dailyQuickYesterday) els.dailyQuickYesterday.addEventListener('click', () => {
302
+ const y = new Date(now); y.setDate(now.getDate() - 1);
303
+ setDailyRange(y, y);
304
+ });
305
+ if (els.dailyQuick7d) els.dailyQuick7d.addEventListener('click', () => {
306
+ const s = new Date(now); s.setDate(now.getDate() - 6);
307
+ setDailyRange(s, new Date(now));
308
+ });
309
+
310
+ const setHourlyDate = (d) => {
311
+ els.hourlyDate.value = toDateInput(d);
312
+ refreshHourly().catch(e => setStatus('拉取失败:' + e.message));
313
+ };
314
+ if (els.hourlyQuickToday) els.hourlyQuickToday.addEventListener('click', () => setHourlyDate(new Date(now)));
315
+ if (els.hourlyQuickYesterday) els.hourlyQuickYesterday.addEventListener('click', () => {
316
+ const y = new Date(now); y.setDate(now.getDate() - 1);
317
+ setHourlyDate(y);
318
+ });
319
+
320
+ const setBucketRange = (startDt, endDt) => {
321
+ els.bucketStart.value = toDateTimeLocal(startDt);
322
+ els.bucketEnd.value = toDateTimeLocal(endDt);
323
+ refreshBuckets().catch(e => setStatus('拉取失败:' + e.message));
324
+ };
325
+ if (els.bucketQuickToday0) els.bucketQuickToday0.addEventListener('click', () => {
326
+ const s = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
327
+ setBucketRange(s, new Date());
328
+ });
329
+ if (els.bucketQuickYesterday0) els.bucketQuickYesterday0.addEventListener('click', () => {
330
+ const e = new Date();
331
+ const y = new Date(e);
332
+ y.setDate(e.getDate() - 1);
333
+ const s = new Date(y.getFullYear(), y.getMonth(), y.getDate(), 0, 0, 0);
334
+ setBucketRange(s, e);
335
+ });
336
+
337
+ let dailyChart = null;
338
+ let hourlyChart = null;
339
+ let bucketChart = null;
340
+
341
+ function destroyChart(c){ try { if (c) c.destroy(); } catch {} }
342
+
343
+ // ====================
344
+ // Chart.js 数值直显(无需悬停)
345
+ // ====================
346
+ // 轻量自定义插件:给柱状图显示数值(默认只显示“总检查”),给折线显示合格率%
347
+ const ValueLabelsPlugin = {
348
+ id: 'valueLabels',
349
+ afterDatasetsDraw(chart, args, pluginOptions) {
350
+ try {
351
+ const opts = pluginOptions || {};
352
+ const showTotalsOnly = opts.showTotalsOnly !== true; // 默认 true
353
+ const showYield = opts.showYield !== false; // 默认 true
354
+ const fontSize = opts.fontSize || 10;
355
+ const color = opts.color || '#e2e8f0';
356
+ const ctx = chart.ctx;
357
+ ctx.save();
358
+ ctx.font = `600 ${fontSize}px Segoe UI, Arial`;
359
+ ctx.fillStyle = color;
360
+ ctx.textAlign = 'center';
361
+ ctx.textBaseline = 'bottom';
362
+
363
+ chart.data.datasets.forEach((ds, i) => {
364
+ const meta = chart.getDatasetMeta(i);
365
+ if (!meta || meta.hidden) return;
366
+
367
+ // 折线:合格率(%) 贴在点上方
368
+ if (ds.type === 'line') {
369
+ if (!showYield) return;
370
+ meta.data.forEach((pt, idx) => {
371
+ const v = ds.data?.[idx];
372
+ if (v === null || v === undefined || v === '') return;
373
+ const txt = `${Number(v).toFixed(1)}%`;
374
+ const x = pt.x;
375
+ const y = pt.y - 2;
376
+ ctx.fillText(txt, x, y);
377
+ });
378
+ return;
379
+ }
380
+
381
+ // 柱状:默认只显示“总检查”,避免过于拥挤
382
+ if (showTotalsOnly && (ds.label || '') !== '总检查') return;
383
+ meta.data.forEach((bar, idx) => {
384
+ const v = ds.data?.[idx];
385
+ if (v === null || v === undefined) return;
386
+ const n = Number(v);
387
+ if (!isFinite(n)) return;
388
+ // 0 不显示,避免一堆 0 挤在一起
389
+ if (n === 0) return;
390
+ const txt = String(n);
391
+ const x = bar.x;
392
+ const y = bar.y - 2;
393
+ ctx.fillText(txt, x, y);
394
+ });
395
+ });
396
+
397
+ ctx.restore();
398
+ } catch {}
399
+ }
400
+ };
401
+ try { Chart.register(ValueLabelsPlugin); } catch {}
402
+
403
+ function makeMixedChart(canvasId, labels, totals, oks, ngs, yields) {
404
+ const ctx = document.getElementById(canvasId);
405
+ return new Chart(ctx, {
406
+ type: 'bar',
407
+ data: {
408
+ labels,
409
+ datasets: [
410
+ { label: '总检查', data: totals, backgroundColor: 'rgba(96,165,250,0.35)', borderColor: 'rgba(96,165,250,0.9)', borderWidth: 1 },
411
+ { label: 'OK', data: oks, backgroundColor: 'rgba(74,222,128,0.35)', borderColor: 'rgba(74,222,128,0.9)', borderWidth: 1 },
412
+ { label: 'NG', data: ngs, backgroundColor: 'rgba(248,113,113,0.35)', borderColor: 'rgba(248,113,113,0.9)', borderWidth: 1 },
413
+ { label: '合格率(%)', data: yields, type: 'line', yAxisID: 'y1', borderColor: 'rgba(250,204,21,0.95)', backgroundColor: 'rgba(250,204,21,0.2)', tension: 0.25, pointRadius: 2 }
414
+ ]
415
+ },
416
+ options: {
417
+ responsive: true,
418
+ maintainAspectRatio: false,
419
+ interaction: { mode: 'index', intersect: false },
420
+ scales: {
421
+ y: { beginAtZero: true, ticks: { color: '#cbd5e1' }, grid: { color: 'rgba(148,163,184,0.15)' } },
422
+ y1: { beginAtZero: true, position: 'right', min: 0, max: 100, ticks: { color: '#cbd5e1', callback: (v)=> v+'%' }, grid: { drawOnChartArea: false } },
423
+ x: { ticks: { color: '#cbd5e1' }, grid: { color: 'rgba(148,163,184,0.08)' } }
424
+ },
425
+ plugins: {
426
+ legend: { labels: { color: '#e2e8f0' } },
427
+ tooltip: { callbacks: { label: (ctx) => `${ctx.dataset.label}: ${ctx.parsed.y}` } },
428
+ // 数值直显(默认:柱只显示总检查,线显示合格率)
429
+ valueLabels: { showTotalsOnly: true, showYield: true, fontSize: 10 }
430
+ }
431
+ }
432
+ });
433
+ }
434
+
435
+ async function fetchJson(url) {
436
+ const res = await fetch(url);
437
+ if (!res.ok) {
438
+ const t = await res.text();
439
+ throw new Error(`http=${res.status} ${t}`);
440
+ }
441
+ return await res.json();
442
+ }
443
+
444
+ async function refreshDaily() {
445
+ const s = els.dailyStart.value;
446
+ const e = els.dailyEnd.value;
447
+ if (!s || !e) return;
448
+ setStatus('拉取日趋势…');
449
+ const url = withCameraIds(`${apiBase()}/analytics/daily?start=${encodeURIComponent(s)}&end=${encodeURIComponent(e)}`);
450
+ const data = await fetchJson(url);
451
+ const pts = data.points || [];
452
+ const labels = pts.map(p => p.label);
453
+ const totals = pts.map(p => p.total);
454
+ const oks = pts.map(p => p.ok);
455
+ const ngs = pts.map(p => p.ng);
456
+ const yields = pts.map(p => Number(p.yield || 0).toFixed(2));
457
+ destroyChart(dailyChart);
458
+ dailyChart = makeMixedChart('daily-chart', labels, totals, oks, ngs, yields);
459
+ setStatus('就绪');
460
+ }
461
+
462
+ async function refreshHourly() {
463
+ const d = els.hourlyDate.value;
464
+ if (!d) return;
465
+ setStatus('拉取小时趋势…');
466
+ const url = withCameraIds(`${apiBase()}/analytics/hourly?date=${encodeURIComponent(d)}`);
467
+ const data = await fetchJson(url);
468
+ const pts = data.points || [];
469
+ const labels = pts.map(p => p.label);
470
+ const totals = pts.map(p => p.total);
471
+ const oks = pts.map(p => p.ok);
472
+ const ngs = pts.map(p => p.ng);
473
+ const yields = pts.map(p => Number(p.yield || 0).toFixed(2));
474
+ destroyChart(hourlyChart);
475
+ hourlyChart = makeMixedChart('hourly-chart', labels, totals, oks, ngs, yields);
476
+ setStatus('就绪');
477
+ }
478
+
479
+ function makePie(canvasId, labels, values) {
480
+ const ctx = document.getElementById(canvasId);
481
+ return new Chart(ctx, {
482
+ type: 'pie',
483
+ data: {
484
+ labels,
485
+ datasets: [{
486
+ data: values,
487
+ backgroundColor: [
488
+ 'rgba(248,113,113,0.55)',
489
+ 'rgba(250,204,21,0.55)',
490
+ 'rgba(96,165,250,0.55)',
491
+ 'rgba(167,139,250,0.55)',
492
+ 'rgba(74,222,128,0.55)',
493
+ 'rgba(148,163,184,0.55)'
494
+ ],
495
+ borderColor: 'rgba(15,23,42,0.8)',
496
+ borderWidth: 1
497
+ }]
498
+ },
499
+ options: {
500
+ responsive: true,
501
+ maintainAspectRatio: false,
502
+ plugins: { legend: { position: 'bottom', labels: { color: '#e2e8f0' } } }
503
+ }
504
+ });
505
+ }
506
+
507
+ function renderBucketTable(buckets, total) {
508
+ els.bucketTotal.textContent = `总数:${total || 0}`;
509
+ if (!buckets || !buckets.length) {
510
+ els.bucketTable.innerHTML = '<div class="muted">无数据</div>';
511
+ return;
512
+ }
513
+ const maxCount = Math.max(1, ...buckets.map(b => Number(b.count || 0)));
514
+ els.bucketTable.innerHTML = buckets.map(b => {
515
+ const pct = total ? ((b.count * 100.0 / total).toFixed(2) + '%') : '0%';
516
+ const ratio = Math.max(0, Math.min(1, (Number(b.count || 0) / maxCount)));
517
+ const w = (ratio * 100).toFixed(1) + '%';
518
+ return `<div class="ana-row">
519
+ <div>${b.name}</div>
520
+ <div class="ana-barwrap" title="数量条形图(相对最大值)"><div class="ana-bar" style="width:${w}"></div></div>
521
+ <div class="ana-right">${b.count}</div>
522
+ <div class="ana-right">${pct}</div>
523
+ </div>`;
524
+ }).join('');
525
+ }
526
+
527
+ async function refreshBuckets() {
528
+ const s = els.bucketStart.value;
529
+ const e = els.bucketEnd.value;
530
+ if (!s || !e) return;
531
+ setStatus('拉取分布…');
532
+ const url = withCameraIds(`${apiBase()}/analytics/buckets?start=${encodeURIComponent(s)}&end=${encodeURIComponent(e)}`);
533
+ const data = await fetchJson(url);
534
+ const buckets = data.buckets || [];
535
+ const total = Number(data.total || 0);
536
+ const labels = buckets.map(b => b.name);
537
+ const values = buckets.map(b => b.count);
538
+ destroyChart(bucketChart);
539
+ bucketChart = makePie('bucket-chart', labels, values);
540
+ renderBucketTable(buckets, total);
541
+ setStatus('就绪');
542
+ }
543
+
544
+ async function refreshAll() {
545
+ try {
546
+ await refreshDaily();
547
+ await refreshHourly();
548
+ await refreshBuckets();
549
+ } catch (e) {
550
+ console.error(e);
551
+ setStatus('拉取失败:' + (e.message || e));
552
+ }
553
+ }
554
+
555
+ els.dailyRefresh.addEventListener('click', () => refreshDaily().catch(e => setStatus('拉取失败:' + e.message)));
556
+ els.hourlyRefresh.addEventListener('click', () => refreshHourly().catch(e => setStatus('拉取失败:' + e.message)));
557
+ els.bucketRefresh.addEventListener('click', () => refreshBuckets().catch(e => setStatus('拉取失败:' + e.message)));
558
+
559
+ setActiveTab();
560
+ // 先做访问控制:没登录不初始化任何请求/图表
561
+ if (ACCESS_GUARD_ENABLED && !guardIsOk()) {
562
+ guardShowLogin();
563
+ const btn = document.getElementById('auth-login-btn');
564
+ const userEl = document.getElementById('auth-user');
565
+ const passEl = document.getElementById('auth-pass');
566
+ const doLogin = () => {
567
+ if (guardTryLogin()) {
568
+ refreshAll();
569
+ }
570
+ };
571
+ if (btn) btn.addEventListener('click', doLogin);
572
+ const onEnter = (e) => {
573
+ if (e && e.key === 'Enter') doLogin();
574
+ };
575
+ if (userEl) userEl.addEventListener('keydown', onEnter);
576
+ if (passEl) passEl.addEventListener('keydown', onEnter);
577
+ } else {
578
+ guardShowApp();
579
+ refreshAll();
580
+ }
581
+ </script>
582
+ </div>
583
+ </body>
584
+ </html>
585
+
586
+
gengyishi2/chart.umd.min.js ADDED
The diff for this file is too large to render. See raw diff
 
gengyishi2/flv.min.js ADDED
The diff for this file is too large to render. See raw diff
 
gengyishi2/index.html ADDED
@@ -0,0 +1,1591 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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">
6
+ <title>A2栋1F-COB无尘管理监控</title>
7
+ <link rel="stylesheet" href="styles.css">
8
+ <!-- flv.js 用于播放 FLV/HLS(Live);若需离线使用,请将 flv.min.js 放到同目录并改成本地路径 -->
9
+ <script src="flv.min.js"></script>
10
+ </head>
11
+ <body class="page">
12
+ <!-- 临时访问控制:未登录时遮罩并阻止查看页面内容(仅前端校验,适合临时管控) -->
13
+ <div class="auth-mask auth-hide" id="auth-mask">
14
+ <div class="auth-card">
15
+ <div class="auth-title">访问验证</div>
16
+ <div class="auth-desc">请输入账号密码后查看页面内容</div>
17
+ <div class="auth-row">
18
+ <div class="auth-field">
19
+ <label for="auth-user">账号</label>
20
+ <input class="auth-input" id="auth-user" autocomplete="username" />
21
+ </div>
22
+ <div class="auth-field">
23
+ <label for="auth-pass">密码</label>
24
+ <input class="auth-input" id="auth-pass" type="password" autocomplete="current-password" />
25
+ </div>
26
+ </div>
27
+ <div class="auth-error" id="auth-err"></div>
28
+ <div class="auth-actions">
29
+ <button class="btn" id="auth-login-btn">登录</button>
30
+ </div>
31
+ </div>
32
+ </div>
33
+
34
+ <!-- 闪屏报警 -->
35
+ <div class="modal" id="alert-modal">
36
+ <div class="modal-content">
37
+ <div class="modal-header" id="alert-title">警告</div>
38
+ <div class="modal-body" id="alert-body"></div>
39
+ </div>
40
+ </div>
41
+
42
+ <div id="app-root" class="auth-hide">
43
+ <header class="header">
44
+ <div>
45
+ <h1>A2栋1F-COB无尘管理监控</h1>
46
+ </div>
47
+ <div class="status">
48
+ <div class="export-popover-wrap">
49
+ <button class="btn" id="export-toggle-btn" title="导出指定时间段的记录">导出记录</button>
50
+ <div class="export-popover" id="export-popover" style="display:none;">
51
+ <div class="export-popover-title">导出记录</div>
52
+ <div class="export-row">
53
+ <label>开始
54
+ <input type="datetime-local" id="export-start" />
55
+ </label>
56
+ <label>结束
57
+ <input type="datetime-local" id="export-end" />
58
+ </label>
59
+ </div>
60
+ <div class="export-actions">
61
+ <button class="btn" id="export-wash-btn">导出洗手</button>
62
+ <button class="btn" id="export-dust-btn">导出沾尘</button>
63
+ </div>
64
+ <div class="muted">下载为 Excel(.xlsx)</div>
65
+ </div>
66
+ </div>
67
+ <button class="btn" id="sound-btn" title="浏览器需要你点一次才能允许语音播报">开启声音</button>
68
+ <button class="btn" id="analytics-btn" title="打开数据分析页面">数据分析</button>
69
+ <span id="status-dot" class="dot dot-warn"></span>
70
+ <span id="status-text">连接中...</span>
71
+ </div>
72
+ </header>
73
+
74
+ <section class="grid-2col">
75
+ <!-- 左:洗手监控 -->
76
+ <div class="col">
77
+ <div class="panel video-panel">
78
+ <div class="video-title-bar">洗手视频</div>
79
+ <video id="video-1" controls muted playsinline></video>
80
+ </div>
81
+ <div class="cards two-row">
82
+ <div class="card">
83
+ <div class="label">洗手 OK</div>
84
+ <div class="value ok" id="ok-count">0</div>
85
+ </div>
86
+ <div class="card">
87
+ <div class="label">洗手不规范</div>
88
+ <div class="value ng" id="ng-count">0</div>
89
+ </div>
90
+ <div class="card">
91
+ <div class="label">未洗手</div>
92
+ <div class="value ng" id="no-wash-count">0</div>
93
+ </div>
94
+ <div class="card">
95
+ <div class="label">未知/未追踪</div>
96
+ <div class="value warn" id="unknown-count">0</div>
97
+ </div>
98
+ <div class="card">
99
+ <div class="label">合格率</div>
100
+ <div class="value" id="yield">0%</div>
101
+ </div>
102
+ </div>
103
+ <div class="panel">
104
+ <div class="panel-header">
105
+ <div>
106
+ <div class="title">洗手实时事件</div>
107
+ <div class="muted">最近 50 条记录(可滚动)</div>
108
+ </div>
109
+ <button class="btn" id="refresh-btn">手动刷新</button>
110
+ </div>
111
+ <div class="table">
112
+ <div class="table-head">
113
+ <div>时间</div>
114
+ <div>摄像头</div>
115
+ <div>入口</div>
116
+ <div>结果</div>
117
+ <div>时长(s)</div>
118
+ <div>原因</div>
119
+ <div>回放</div>
120
+ </div>
121
+ <div id="event-body" class="table-body-scroll"></div>
122
+ </div>
123
+ </div>
124
+ </div>
125
+
126
+ <!-- 右:沾尘监控占位 -->
127
+ <div class="col">
128
+ <div class="panel video-panel">
129
+ <div class="video-title-bar dust">沾尘视频</div>
130
+ <video id="video-2" controls muted playsinline></video>
131
+ </div>
132
+ <div class="cards two-row">
133
+ <div class="card">
134
+ <div class="label">沾尘 OK</div>
135
+ <div class="value ok" id="dust-ok-count">0</div>
136
+ </div>
137
+ <div class="card">
138
+ <div class="label">沾尘不规范</div>
139
+ <div class="value ng" id="dust-ng-count">0</div>
140
+ </div>
141
+ <div class="card">
142
+ <div class="label">未沾尘</div>
143
+ <div class="value ng" id="dust-no-dust-count">0</div>
144
+ </div>
145
+ <div class="card">
146
+ <div class="label">未知/未追踪</div>
147
+ <div class="value warn" id="dust-unknown-count">0</div>
148
+ </div>
149
+ <div class="card">
150
+ <div class="label">合格率</div>
151
+ <div class="value" id="dust-yield">0%</div>
152
+ </div>
153
+ </div>
154
+ <div class="panel">
155
+ <div class="panel-header">
156
+ <div>
157
+ <div class="title">沾尘实时事件</div>
158
+ <div class="muted">最近 50 条记录(可滚动)</div>
159
+ </div>
160
+ </div>
161
+ <div class="table">
162
+ <div class="table-head">
163
+ <div>时间</div>
164
+ <div>摄像头</div>
165
+ <div>入口</div>
166
+ <div>结果</div>
167
+ <div>时长(s)</div>
168
+ <div>原因</div>
169
+ <div>回放</div>
170
+ </div>
171
+ <div id="dust-event-body" class="table-body-scroll"></div>
172
+ </div>
173
+ </div>
174
+ </div>
175
+ </section>
176
+
177
+ <!-- 回放弹窗 -->
178
+ <div id="clip-modal" style="display:none; position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 9999;">
179
+ <div style="max-width: 1500px; margin: 3vh auto; background: #0b1220; border: 1px solid #334155; border-radius: 12px; padding: 12px;">
180
+ <div style="display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:8px;">
181
+ <div style="font-weight:800;">NG 回放</div>
182
+ <button class="btn" id="clip-close-btn">关闭</button>
183
+ </div>
184
+ <video id="clip-player" controls style="width:100%; height:82vh; max-height:82vh; background:#000; border-radius:10px;"></video>
185
+ <div class="muted" id="clip-url-text" style="margin-top:8px;"></div>
186
+ </div>
187
+ </div>
188
+
189
+ <!-- 回放列表弹窗(点击统计数字弹出) -->
190
+ <div id="cliplist-modal" style="display:none; position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 9998;">
191
+ <div style="max-width: 1100px; margin: 6vh auto; background: #0b1220; border: 1px solid #334155; border-radius: 12px; padding: 12px;">
192
+ <div style="display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:10px;">
193
+ <div style="font-weight:800;" id="cliplist-title">回放列表</div>
194
+ <div style="display:flex; gap:10px; align-items:center; flex-wrap: wrap; justify-content:flex-end;">
195
+ <label class="muted" style="display:flex; align-items:center; gap:6px;">
196
+ 日期
197
+ <input type="date" id="cliplist-date" />
198
+ </label>
199
+ <button class="btn" id="cliplist-prev-btn">上一页</button>
200
+ <button class="btn" id="cliplist-next-btn">下一页</button>
201
+ <button class="btn" id="cliplist-refresh-btn">刷新</button>
202
+ <button class="btn" id="cliplist-close-btn">关闭</button>
203
+ </div>
204
+ </div>
205
+ <div class="muted" id="cliplist-subtitle" style="margin-bottom:10px;"></div>
206
+ <div class="table" style="margin-bottom:8px;">
207
+ <div class="table-head" style="grid-template-columns: 1.2fr 0.6fr 0.9fr 0.8fr 1.6fr 0.7fr;">
208
+ <div>时间</div>
209
+ <div>相机</div>
210
+ <div>结果</div>
211
+ <div>时长(s)</div>
212
+ <div>原因</div>
213
+ <div>回放</div>
214
+ </div>
215
+ <div id="cliplist-body" class="table-body-scroll" style="max-height: 520px;"></div>
216
+ </div>
217
+ </div>
218
+ </div>
219
+
220
+ <script>
221
+ // =============================
222
+ // 临时访问控制配置(只做“管控”,不做真正安全)
223
+ // =============================
224
+ // 你可以在这里改账号/密码(也可以后续迁移到 nginx basic auth 或后端鉴权)
225
+ const ACCESS_GUARD_ENABLED = false;
226
+ const ACCESS_GUARD_TTL_MS = 8 * 60 * 60 * 1000; // 登录有效期:8小时
227
+ const ACCESS_GUARD_USERS = [
228
+ { user: 'N231310', pass: 'Ahh123321' },
229
+ { user: 'H012F', pass: 'As123456' },
230
+ { user: 'T10929', pass: 'As123456' },
231
+ ];
232
+ const ACCESS_GUARD_KEY = 'handwash_guard_ok_gengyishi2';
233
+ const PAGE_CODE = 'PAGE_WASH_DUST_2';
234
+ const PORTAL_AUTH_TOKEN_KEY = 'PORTAL_AUTH_TOKEN_V1';
235
+
236
+ async function checkPageAccess() {
237
+ try {
238
+ const token = localStorage.getItem(PORTAL_AUTH_TOKEN_KEY) || '';
239
+ const res = await fetch(`/aa/api/auth/page-access?page_code=${encodeURIComponent(PAGE_CODE)}`, {
240
+ method: 'GET',
241
+ headers: token ? { 'X-Auth-Token': token } : {},
242
+ credentials: 'include'
243
+ });
244
+ if (!res.ok) {
245
+ if (res.status === 401) {
246
+ alert('请先在统一入口登录');
247
+ window.location.href = '/portal/portal.html?next=' + encodeURIComponent(location.pathname + location.search);
248
+ return false;
249
+ }
250
+ return true;
251
+ }
252
+ const data = await res.json();
253
+ if (!data || !data.ok) {
254
+ alert((data && data.error === 'IP_FORBIDDEN') ? '您的IP不在允许访问列表中' : '无访问权限');
255
+ window.location.href = '/portal/portal.html';
256
+ return false;
257
+ }
258
+ return true;
259
+ } catch (e) {
260
+ console.warn('page access check failed, allow temporarily:', e);
261
+ return true;
262
+ }
263
+ }
264
+
265
+ // 登录后也需要触发一次初始化(否则只会在刷新/DOMContentLoaded 时初始化)
266
+ let __appBootstrapped = false;
267
+
268
+ function guardIsOk() {
269
+ try {
270
+ const raw = localStorage.getItem(ACCESS_GUARD_KEY);
271
+ if (!raw) return false;
272
+ const v = JSON.parse(raw);
273
+ if (!v || !v.ok || !v.ts) return false;
274
+ return (Date.now() - v.ts) <= ACCESS_GUARD_TTL_MS;
275
+ } catch {
276
+ return false;
277
+ }
278
+ }
279
+
280
+ function guardSetOk() {
281
+ try { localStorage.setItem(ACCESS_GUARD_KEY, JSON.stringify({ ok: true, ts: Date.now() })); } catch {}
282
+ }
283
+
284
+ function guardShowLogin() {
285
+ const mask = document.getElementById('auth-mask');
286
+ const root = document.getElementById('app-root');
287
+ if (mask) mask.classList.remove('auth-hide');
288
+ if (root) root.classList.add('auth-hide');
289
+ }
290
+
291
+ function guardShowApp() {
292
+ const mask = document.getElementById('auth-mask');
293
+ const root = document.getElementById('app-root');
294
+ if (mask) mask.classList.add('auth-hide');
295
+ if (root) root.classList.remove('auth-hide');
296
+ }
297
+
298
+ function guardTryLogin() {
299
+ const u = (document.getElementById('auth-user')?.value || '').trim();
300
+ const p = (document.getElementById('auth-pass')?.value || '');
301
+ const err = document.getElementById('auth-err');
302
+ const ok = ACCESS_GUARD_USERS.some(x => x.user === u && x.pass === p);
303
+ if (!ok) {
304
+ if (err) err.textContent = '账号或密码错误';
305
+ return false;
306
+ }
307
+ if (err) err.textContent = '';
308
+ guardSetOk();
309
+ guardShowApp();
310
+ return true;
311
+ }
312
+
313
+ const apiProto = (location.protocol === 'https:') ? 'https:' : 'http:';
314
+ const wsProto = (location.protocol === 'https:') ? 'wss:' : 'ws:';
315
+ const qs = new URLSearchParams(location.search);
316
+ // 后端 API/WS 固定走 151;可通过 ?backendOrigin= 覆盖
317
+ const BACKEND_ORIGIN = (() => {
318
+ const v = (qs.get('backendOrigin') || '').trim();
319
+ if (v) return v.replace(/\/+$/, '');
320
+ if (location.host) return `${apiProto}//${location.host}`;
321
+ return 'http://192.168.55.36:8088';
322
+ })();
323
+ // 媒体播放默认同源(通常是 55.36:8088);可通过 ?mediaOrigin= 覆盖
324
+ const MEDIA_ORIGIN = (() => {
325
+ const v = (qs.get('mediaOrigin') || '').trim();
326
+ if (v) return v.replace(/\/+$/, '');
327
+ if (location.host) return `${apiProto}//${location.host}`;
328
+ return 'http://192.168.55.36:8088';
329
+ })();
330
+ const PROJECT_KEY = (qs.get('project') || 'gengyishi2').trim();
331
+ function withProject(url) {
332
+ if (!PROJECT_KEY) return url;
333
+ const join = url.includes('?') ? '&' : '?';
334
+ return `${url}${join}project=${encodeURIComponent(PROJECT_KEY)}`;
335
+ }
336
+ // 更衣室2:洗手=相机3,沾尘=相机4
337
+ const CAMERA_IDS = '3,4';
338
+ const CAMERA_ID_SET = new Set(
339
+ String(CAMERA_IDS).split(',').map(s => Number(String(s).trim())).filter(n => Number.isFinite(n))
340
+ );
341
+ function withCameraIds(url) {
342
+ const join = url.includes('?') ? '&' : '?';
343
+ return `${url}${join}cameraIds=${encodeURIComponent(CAMERA_IDS)}`;
344
+ }
345
+ function getCameraId(obj) {
346
+ if (!obj) return NaN;
347
+ const v = pick(obj, 'camera_id', 'cameraId');
348
+ const n = Number(v);
349
+ return Number.isFinite(n) ? n : NaN;
350
+ }
351
+ function isAllowedCamera(obj) {
352
+ const cam = getCameraId(obj);
353
+ if (!Number.isFinite(cam)) return true;
354
+ return CAMERA_ID_SET.has(cam);
355
+ }
356
+ const API_BASE = `${BACKEND_ORIGIN}/gengyishi/api/wash`;
357
+ const WS_URL = withProject(`${BACKEND_ORIGIN.replace(/^http/i, 'ws')}/gengyishi/ws/wash`);
358
+ const DUST_API_BASE = `${BACKEND_ORIGIN}/gengyishi/api/dust`;
359
+ const DUST_WS_URL = withProject(`${BACKEND_ORIGIN.replace(/^http/i, 'ws')}/gengyishi/ws/dust`);
360
+
361
+ // 回放 mp4 存放在算法端(可用 ?clipOrigin=http://10.71.15.151:8085 覆盖)
362
+ const CLIP_ORIGIN = (() => {
363
+ try {
364
+ const m = String(location.search || '').match(/[?&]clipOrigin=([^&]+)/i);
365
+ if (m && m[1]) return decodeURIComponent(m[1]);
366
+ } catch {}
367
+ return 'http://10.71.15.151:8085';
368
+ })();
369
+
370
+ function normalizeClipUrl(raw) {
371
+ const u = String(raw || '').trim();
372
+ if (!u) return '';
373
+ // 已是完整 URL:直接用
374
+ if (/^https?:\/\//i.test(u)) return u;
375
+ // 形如 //host/path
376
+ if (u.startsWith('//')) return `${apiProto}${u}`;
377
+ // 后端一般给 /clips/... 或 clips/...
378
+ if (u.startsWith('/clips/')) return `${CLIP_ORIGIN}${u}`;
379
+ if (u.startsWith('clips/')) return `${CLIP_ORIGIN}/${u}`;
380
+ // 有些服务只返回 dust/... 或 wash/...(不带 /clips 前缀)
381
+ if (/^(dust|wash)\//i.test(u) && /\.mp4(\?.*)?$/i.test(u)) return `${CLIP_ORIGIN}/clips/${u}`;
382
+ // 其他情况:保持原样(避免误拼)
383
+ return u;
384
+ }
385
+
386
+ // ZLMediaKit 播放地址(默认同源,可被 mediaOrigin 覆盖)
387
+ const ZLM_HTTP_ORIGIN = MEDIA_ORIGIN;
388
+ const VIDEO_CONFIG = {
389
+ 'video-1': `/live/wash_check2.live.flv`, // 洗手检测推流地址
390
+ 'video-2': `/live/dust_check2.live.flv` // 沾尘检测推流地址
391
+ };
392
+
393
+ const state = {
394
+ events: [],
395
+ dustEvents: [],
396
+ dust: {
397
+ ok: 0,
398
+ ng: 0,
399
+ unknown: 0,
400
+ yield: 0
401
+ },
402
+ soundEnabled: true,
403
+ // 洗手 NG 语音合并
404
+ washNgNoWashCnt: 0,
405
+ washNgBadWashCnt: 0,
406
+ washNgLastSpeakAt: 0,
407
+ // 防刷屏:同类 NG 合并播报
408
+ dustNgNoDustCnt: 0,
409
+ dustNgBadDustCnt: 0,
410
+ dustNgLastSpeakAt: 0
411
+ };
412
+
413
+ let alertTimer = null;
414
+ let lastFlashAt = 0;
415
+ function showAlertFlash(text, tone = 'red') {
416
+ const now = Date.now();
417
+ if (now - lastFlashAt < 1500) return; // 简单防刷屏
418
+ lastFlashAt = now;
419
+ const modal = document.getElementById('alert-modal');
420
+ const title = document.getElementById('alert-title');
421
+ const body = document.getElementById('alert-body');
422
+ if (!modal || !body) return;
423
+ if (title) title.textContent = tone === 'yellow' ? '提示' : '警告';
424
+ body.textContent = String(text || '');
425
+ modal.classList.remove('alert-flash-red', 'alert-flash-yellow');
426
+ modal.classList.add(tone === 'yellow' ? 'alert-flash-yellow' : 'alert-flash-red');
427
+ modal.classList.add('show');
428
+ if (alertTimer) clearTimeout(alertTimer);
429
+ alertTimer = setTimeout(() => {
430
+ modal.classList.remove('show', 'alert-flash-red', 'alert-flash-yellow');
431
+ }, 8000);
432
+ }
433
+
434
+ function setStatus(text, color) {
435
+ const dot = document.getElementById('status-dot');
436
+ const label = document.getElementById('status-text');
437
+ label.textContent = text;
438
+ dot.className = `dot ${color}`;
439
+ }
440
+
441
+ // -----------------------------
442
+ // 数据分析跳转
443
+ // -----------------------------
444
+ function gotoAnalytics(tab) {
445
+ const t = tab === 'dust' ? 'dust' : 'wash';
446
+ const proj = PROJECT_KEY ? `&project=${encodeURIComponent(PROJECT_KEY)}` : '';
447
+ window.location.href = `analytics.html?tab=${encodeURIComponent(t)}${proj}`;
448
+ }
449
+
450
+ // -----------------------------
451
+ // 浏览器语音播报(Web Speech API)
452
+ // -----------------------------
453
+ function pickZhVoice() {
454
+ try {
455
+ const voices = window.speechSynthesis ? speechSynthesis.getVoices() : [];
456
+ if (!voices || !voices.length) return null;
457
+ // 优先 zh-CN,其次 zh
458
+ return (
459
+ voices.find(v => (v.lang || '').toLowerCase() === 'zh-cn') ||
460
+ voices.find(v => (v.lang || '').toLowerCase().startsWith('zh')) ||
461
+ null
462
+ );
463
+ } catch {
464
+ return null;
465
+ }
466
+ }
467
+
468
+ function speak(text) {
469
+ if (!state.soundEnabled) return;
470
+ if (!text) return;
471
+ if (!window.speechSynthesis) {
472
+ console.warn('[SOUND] speechSynthesis not supported');
473
+ return;
474
+ }
475
+ try {
476
+ const u = new SpeechSynthesisUtterance(text);
477
+ u.lang = 'zh-CN';
478
+ const v = pickZhVoice();
479
+ if (v) u.voice = v;
480
+ // 语速/音量可按需再加 UI 配置,这里先用默认更稳
481
+ speechSynthesis.speak(u);
482
+ console.warn('[SOUND] speak:', text);
483
+ } catch (e) {
484
+ console.warn('[SOUND] speak failed', e);
485
+ }
486
+ }
487
+
488
+ function flushDustNgSpeak(force = false) {
489
+ const now = Date.now();
490
+ const minIntervalMs = 700;
491
+ if (!force && now - state.dustNgLastSpeakAt < minIntervalMs) return;
492
+ if (state.dustNgNoDustCnt === 0 && state.dustNgBadDustCnt === 0) return;
493
+
494
+ const parts = [];
495
+ if (state.dustNgNoDustCnt > 0) {
496
+ parts.push(`未沾尘${state.dustNgNoDustCnt > 1 ? state.dustNgNoDustCnt + '次' : ''}`);
497
+ }
498
+ if (state.dustNgBadDustCnt > 0) {
499
+ parts.push(`沾尘不规范${state.dustNgBadDustCnt > 1 ? state.dustNgBadDustCnt + '次' : ''}`);
500
+ }
501
+ state.dustNgNoDustCnt = 0;
502
+ state.dustNgBadDustCnt = 0;
503
+ state.dustNgLastSpeakAt = now;
504
+ speak(parts.join(','));
505
+ }
506
+
507
+ function flushWashNgSpeak(force = false) {
508
+ const now = Date.now();
509
+ const minIntervalMs = 700;
510
+ if (!force && now - state.washNgLastSpeakAt < minIntervalMs) return;
511
+ if (state.washNgNoWashCnt === 0 && state.washNgBadWashCnt === 0) return;
512
+
513
+ const parts = [];
514
+ if (state.washNgNoWashCnt > 0) {
515
+ parts.push(`未洗手${state.washNgNoWashCnt > 1 ? state.washNgNoWashCnt + '次' : ''}`);
516
+ }
517
+ if (state.washNgBadWashCnt > 0) {
518
+ parts.push(`洗手不合格${state.washNgBadWashCnt > 1 ? state.washNgBadWashCnt + '次' : ''}`);
519
+ }
520
+ state.washNgNoWashCnt = 0;
521
+ state.washNgBadWashCnt = 0;
522
+ state.washNgLastSpeakAt = now;
523
+ speak(parts.join(','));
524
+ }
525
+
526
+ // voices 列表是异步加载的,先触发一次刷新
527
+ try {
528
+ if (window.speechSynthesis) {
529
+ speechSynthesis.onvoiceschanged = () => {};
530
+ }
531
+ } catch {}
532
+
533
+ function initSoundUi() {
534
+ const btn = document.getElementById('sound-btn');
535
+ if (!btn) return;
536
+ const refreshLabel = () => {
537
+ btn.textContent = state.soundEnabled ? '声音已开启' : '开启声音';
538
+ };
539
+ refreshLabel();
540
+ btn.addEventListener('click', () => {
541
+ state.soundEnabled = !state.soundEnabled;
542
+ refreshLabel();
543
+ if (state.soundEnabled) {
544
+ // 用一次轻量播报来“解锁”浏览器音频策略
545
+ speak('语音提示已开启');
546
+ } else {
547
+ try { if (window.speechSynthesis) speechSynthesis.cancel(); } catch {}
548
+ }
549
+ });
550
+ }
551
+
552
+ function updateSummary(data) {
553
+ if (!data) return;
554
+ document.getElementById('ok-count').textContent = data.ok_count ?? 0;
555
+ document.getElementById('ng-count').textContent = data.ng_count ?? 0;
556
+ // 避免 WS summary 缺字段时把数值刷成 0:只有字段存在才更新
557
+ const nwEl = document.getElementById('no-wash-count');
558
+ if (nwEl) {
559
+ const hasNoWash = (data.no_wash_count !== undefined && data.no_wash_count !== null) ||
560
+ (data.noWashCount !== undefined && data.noWashCount !== null);
561
+ if (hasNoWash) {
562
+ const nw = data.no_wash_count ?? data.noWashCount ?? 0;
563
+ nwEl.textContent = nw;
564
+ }
565
+ }
566
+ document.getElementById('unknown-count').textContent = data.unknown_count ?? 0;
567
+ const y = data.yield !== undefined ? parseFloat(data.yield) : 0;
568
+ document.getElementById('yield').textContent = `${(isNaN(y) ? 0 : y).toFixed(2)}%`;
569
+ }
570
+
571
+ function updateDustSummary() {
572
+ document.getElementById('dust-ok-count').textContent = state.dust.ok;
573
+ document.getElementById('dust-ng-count').textContent = state.dust.ng;
574
+ const ndEl = document.getElementById('dust-no-dust-count');
575
+ if (ndEl) ndEl.textContent = state.dust.noDust ?? 0;
576
+ document.getElementById('dust-unknown-count').textContent = state.dust.unknown;
577
+ document.getElementById('dust-yield').textContent = `${state.dust.yield.toFixed ? state.dust.yield.toFixed(2) : '0.00'}%`;
578
+ }
579
+
580
+ const EVENT_LIMIT = 50;
581
+
582
+ function getId(e) {
583
+ if (!e) return null;
584
+ return e.id ?? e.ID ?? e._id ?? null;
585
+ }
586
+
587
+ function shouldStickToBottom(container) {
588
+ if (!container) return true;
589
+ const gap = container.scrollHeight - (container.scrollTop + container.clientHeight);
590
+ return gap < 60; // 接近底部就跟随
591
+ }
592
+
593
+ function scrollToBottom(container, animate = true, dur = 280) {
594
+ if (!container) return;
595
+ const target = container.scrollHeight - container.clientHeight;
596
+ if (!animate) {
597
+ container.scrollTop = Math.max(0, target);
598
+ return;
599
+ }
600
+ const from = container.scrollTop;
601
+ const to = Math.max(0, target);
602
+ const t0 = performance.now();
603
+ const ease = (t) => (t < 0.5 ? 2*t*t : 1 - Math.pow(-2*t + 2, 2)/2);
604
+ const step = (now) => {
605
+ const p = Math.min(1, (now - t0) / dur);
606
+ container.scrollTop = from + (to - from) * ease(p);
607
+ if (p < 1) requestAnimationFrame(step);
608
+ };
609
+ requestAnimationFrame(step);
610
+ }
611
+
612
+ // 鼠标拖拽滚动(框内拖动)
613
+ function enableDragScroll(el) {
614
+ if (!el) return;
615
+ let down = false;
616
+ let startY = 0;
617
+ let startTop = 0;
618
+
619
+ const onDown = (e) => {
620
+ down = true;
621
+ el.classList.add('dragging');
622
+ startY = (e.touches && e.touches[0]) ? e.touches[0].clientY : e.clientY;
623
+ startTop = el.scrollTop;
624
+ try { e.preventDefault(); } catch {}
625
+ };
626
+ const onMove = (e) => {
627
+ if (!down) return;
628
+ const y = (e.touches && e.touches[0]) ? e.touches[0].clientY : e.clientY;
629
+ const dy = y - startY;
630
+ el.scrollTop = startTop - dy;
631
+ try { e.preventDefault(); } catch {}
632
+ };
633
+ const onUp = () => {
634
+ down = false;
635
+ el.classList.remove('dragging');
636
+ };
637
+
638
+ el.addEventListener('mousedown', onDown);
639
+ window.addEventListener('mousemove', onMove);
640
+ window.addEventListener('mouseup', onUp);
641
+
642
+ // 兼容触摸(可选)
643
+ el.addEventListener('touchstart', onDown, { passive: false });
644
+ window.addEventListener('touchmove', onMove, { passive: false });
645
+ window.addEventListener('touchend', onUp);
646
+ }
647
+
648
+ // 回放:事件委托(两张表共用)
649
+ function initClipPlaybackUi() {
650
+ const modal = document.getElementById('clip-modal');
651
+ const player = document.getElementById('clip-player');
652
+ const closeBtn = document.getElementById('clip-close-btn');
653
+ const urlText = document.getElementById('clip-url-text');
654
+ if (!modal || !player) return;
655
+
656
+ const close = () => {
657
+ modal.style.display = 'none';
658
+ try { player.pause(); } catch {}
659
+ try { player.removeAttribute('src'); player.load(); } catch {}
660
+ };
661
+ if (closeBtn) closeBtn.addEventListener('click', close);
662
+ modal.addEventListener('click', (e) => { if (e.target === modal) close(); });
663
+
664
+ document.addEventListener('click', (e) => {
665
+ const btn = e.target && e.target.closest ? e.target.closest('button[data-clip]') : null;
666
+ if (!btn) return;
667
+ const raw = btn.getAttribute('data-clip');
668
+ const url = normalizeClipUrl(raw);
669
+ if (!url) return;
670
+ modal.style.display = 'block';
671
+ player.src = url;
672
+ if (urlText) urlText.textContent = url;
673
+ player.play().catch(() => {});
674
+ });
675
+ }
676
+
677
+ function appendEvent(evt) {
678
+ if (!evt) return;
679
+ if (!isAllowedCamera(evt)) return;
680
+ // 最新在最上面:插入到顶部
681
+ const id = getId(evt);
682
+ if (id != null && state.events.some(x => getId(x) === id)) return;
683
+ state.events.unshift(evt);
684
+ state.events = state.events.slice(0, EVENT_LIMIT);
685
+ renderEvents(new Set([id]));
686
+ }
687
+
688
+ function appendDustEvent(evt) {
689
+ if (!evt) return;
690
+ if (!isAllowedCamera(evt)) return;
691
+ const id = getId(evt);
692
+ if (id != null && state.dustEvents.some(x => getId(x) === id)) return;
693
+ state.dustEvents.unshift(evt);
694
+ state.dustEvents = state.dustEvents.slice(0, EVENT_LIMIT);
695
+ renderDustEvents(new Set([id]));
696
+ }
697
+
698
+ function renderEvents(highlightIds = new Set(), refreshing = false) {
699
+ const body = document.getElementById('event-body');
700
+ if (state.events.length === 0) {
701
+ body.innerHTML = '<div class="row muted center">等待数据...</div>';
702
+ return;
703
+ }
704
+ // 最新在最上面:如果用户在顶部附近,刷新后保持在顶部;否则保持当前浏览位置不跳动
705
+ const stickTop = (body.scrollTop || 0) < 60;
706
+ const prevTop = body.scrollTop || 0;
707
+ const prevH = body.scrollHeight || 0;
708
+ if (refreshing && body) {
709
+ body.classList.add('refreshing');
710
+ setTimeout(() => body.classList.remove('refreshing'), 350);
711
+ }
712
+ const pick = (obj, snake, camel) => {
713
+ if (!obj) return undefined;
714
+ if (obj[snake] !== undefined && obj[snake] !== null) return obj[snake];
715
+ if (camel && obj[camel] !== undefined && obj[camel] !== null) return obj[camel];
716
+ return undefined;
717
+ };
718
+ body.innerHTML = state.events.map(e => {
719
+ const id = getId(e);
720
+ const isNew = id != null && highlightIds.has(id);
721
+ const clip = pick(e,'clip_url','clipUrl');
722
+ return `
723
+ <div class="row ${rowClass(pick(e,'wash_result','washResult'))} ${isNew ? 'row-new' : ''}">
724
+ <div>${formatTime(pick(e,'exited_at','exitedAt') || pick(e,'wash_finished_at','washFinishedAt'))}</div>
725
+ <div>${pick(e,'camera_id','cameraId') ?? '--'}</div>
726
+ <div>${pick(e,'entry_source','entrySource') ?? '--'}</div>
727
+ <div>${pick(e,'wash_result','washResult') ?? '--'}</div>
728
+ <div>${pick(e,'wash_time_sec','washTimeSec') ? Number(pick(e,'wash_time_sec','washTimeSec')).toFixed(1) : '0.0'}</div>
729
+ <div>${pick(e,'reason','reason') || ''}</div>
730
+ <div>${(clip ? `<button class="btn btn-sm" data-clip="${escapeHtml(String(clip))}">回放</button>` : '--')}</div>
731
+ </div>
732
+ `;
733
+ }).join('');
734
+ if (stickTop) {
735
+ // 顶部跟随:最新永远在最上面
736
+ body.scrollTop = 0;
737
+ } else {
738
+ // 保持浏览位置(避免刷新瞬间跳动)
739
+ const newH = body.scrollHeight || 0;
740
+ const delta = newH - prevH;
741
+ body.scrollTop = prevTop + delta;
742
+ }
743
+ }
744
+
745
+ function renderDustEvents(highlightIds = new Set(), refreshing = false) {
746
+ const body = document.getElementById('dust-event-body');
747
+ if (!body) return;
748
+ if (state.dustEvents.length === 0) {
749
+ body.innerHTML = '<div class="row muted center">等待数据...</div>';
750
+ return;
751
+ }
752
+ const stickTop = (body.scrollTop || 0) < 60;
753
+ const prevTop = body.scrollTop || 0;
754
+ const prevH = body.scrollHeight || 0;
755
+ if (refreshing && body) {
756
+ body.classList.add('refreshing');
757
+ setTimeout(() => body.classList.remove('refreshing'), 350);
758
+ }
759
+ const pick = (obj, snake, camel) => {
760
+ if (!obj) return undefined;
761
+ if (obj[snake] !== undefined && obj[snake] !== null) return obj[snake];
762
+ if (camel && obj[camel] !== undefined && obj[camel] !== null) return obj[camel];
763
+ return undefined;
764
+ };
765
+ body.innerHTML = state.dustEvents.map(e => {
766
+ const id = getId(e);
767
+ const isNew = id != null && highlightIds.has(id);
768
+ const clip = pick(e,'clip_url','clipUrl');
769
+ return `
770
+ <div class="row ${rowClass(pick(e,'dust_result','dustResult'))} ${isNew ? 'row-new' : ''}">
771
+ <div>${formatTime(pick(e,'exited_at','exitedAt') || pick(e,'dust_finished_at','dustFinishedAt'))}</div>
772
+ <div>${pick(e,'camera_id','cameraId') ?? '--'}</div>
773
+ <div>${pick(e,'entry_source','entrySource') ?? '--'}</div>
774
+ <div>${pick(e,'dust_result','dustResult') ?? '--'}</div>
775
+ <div>${pick(e,'dust_time_sec','dustTimeSec') ? Number(pick(e,'dust_time_sec','dustTimeSec')).toFixed(1) : '0.0'}</div>
776
+ <div>${pick(e,'reason','reason') || ''}</div>
777
+ <div>${(clip ? `<button class="btn btn-sm" data-clip="${escapeHtml(String(clip))}">回放</button>` : '--')}</div>
778
+ </div>
779
+ `;
780
+ }).join('');
781
+ if (stickTop) {
782
+ body.scrollTop = 0;
783
+ } else {
784
+ const newH = body.scrollHeight || 0;
785
+ const delta = newH - prevH;
786
+ body.scrollTop = prevTop + delta;
787
+ }
788
+ }
789
+
790
+ function rowClass(result) {
791
+ if (!result) return '';
792
+ const r = result.toUpperCase();
793
+ if (r === 'OK') return 'row-ok';
794
+ if (r === 'NG') return 'row-ng';
795
+ if (r === 'UNKNOWN') return 'row-warn';
796
+ return '';
797
+ }
798
+
799
+ function escapeHtml(s) {
800
+ return String(s || '')
801
+ .replace(/&/g, '&amp;')
802
+ .replace(/</g, '&lt;')
803
+ .replace(/>/g, '&gt;')
804
+ .replace(/"/g, '&quot;')
805
+ .replace(/'/g, '&#39;');
806
+ }
807
+
808
+ // 全局字段兼容:后端可能是 snake_case,也可能是 camelCase
809
+ function pick(obj, snake, camel) {
810
+ if (!obj) return undefined;
811
+ if (obj[snake] !== undefined && obj[snake] !== null) return obj[snake];
812
+ if (camel && obj[camel] !== undefined && obj[camel] !== null) return obj[camel];
813
+ return undefined;
814
+ }
815
+
816
+ function formatTime(t) {
817
+ if (!t) return '--';
818
+ try {
819
+ const d = new Date(t);
820
+ if (isNaN(d.getTime())) return '--';
821
+ return d.toLocaleString('zh-CN', { hour12: false });
822
+ } catch (e) {
823
+ return '--';
824
+ }
825
+ }
826
+
827
+ async function loadRecent() {
828
+ try {
829
+ const res = await fetch(withCameraIds(`${API_BASE}/events/recent?limit=${EVENT_LIMIT}`));
830
+ if (!res.ok) return;
831
+ const data = await res.json();
832
+ const incoming = (data.events || []).filter(isAllowedCamera);
833
+ const oldMaxId = Math.max(0, ...state.events.map(e => Number(getId(e) || 0)));
834
+ const newIds = new Set(incoming.filter(e => Number(getId(e) || 0) > oldMaxId).map(e => getId(e)));
835
+ // 保持后端 DESC(最新在最上)
836
+ state.events = incoming.slice(0, EVENT_LIMIT);
837
+ renderEvents(newIds, true);
838
+ } catch (e) {
839
+ console.error('load recent failed', e);
840
+ }
841
+ }
842
+
843
+ async function loadDustRecent() {
844
+ try {
845
+ const res = await fetch(withCameraIds(`${DUST_API_BASE}/events/recent?limit=${EVENT_LIMIT}`));
846
+ if (!res.ok) return;
847
+ const data = await res.json();
848
+ const incoming = (data.events || []).filter(isAllowedCamera);
849
+ const oldMaxId = Math.max(0, ...state.dustEvents.map(e => Number(getId(e) || 0)));
850
+ const newIds = new Set(incoming.filter(e => Number(getId(e) || 0) > oldMaxId).map(e => getId(e)));
851
+ state.dustEvents = incoming.slice(0, EVENT_LIMIT);
852
+ renderDustEvents(newIds, true);
853
+ } catch (e) {
854
+ console.error('load dust recent failed', e);
855
+ }
856
+ }
857
+
858
+ async function loadSummary() {
859
+ try {
860
+ const res = await fetch(withCameraIds(`${API_BASE}/summary/today`));
861
+ if (!res.ok) return;
862
+ const data = await res.json();
863
+ updateSummary(data.summary);
864
+ } catch (e) {
865
+ console.error('load summary failed', e);
866
+ }
867
+ }
868
+
869
+ async function loadDustSummary() {
870
+ try {
871
+ const res = await fetch(withCameraIds(`${DUST_API_BASE}/summary/today`));
872
+ if (!res.ok) return;
873
+ const data = await res.json();
874
+ const s = data.summary || {};
875
+ state.dust.ok = s.ok_count ?? 0;
876
+ state.dust.ng = s.ng_count ?? 0;
877
+ state.dust.noDust = s.no_dust_count ?? s.noDustCount ?? 0;
878
+ state.dust.unknown = s.unknown_count ?? 0;
879
+ const y = s.yield !== undefined ? parseFloat(s.yield) : 0;
880
+ state.dust.yield = isNaN(y) ? 0 : y;
881
+ updateDustSummary();
882
+ } catch (e) {
883
+ console.error('load dust summary failed', e);
884
+ }
885
+ }
886
+
887
+ function fmt2(n) { return String(n).padStart(2, '0'); }
888
+ function toDatetimeLocal(d) {
889
+ const y = d.getFullYear();
890
+ const m = fmt2(d.getMonth() + 1);
891
+ const day = fmt2(d.getDate());
892
+ const hh = fmt2(d.getHours());
893
+ const mm = fmt2(d.getMinutes());
894
+ return `${y}-${m}-${day}T${hh}:${mm}`;
895
+ }
896
+
897
+ function normalizeIsoLocalSeconds(v) {
898
+ // datetime-local 通常是 yyyy-MM-ddTHH:mm;后端也支持该格式,但这里统一补秒更稳
899
+ if (!v) return '';
900
+ if (v.length === 16) return v + ':00';
901
+ return v;
902
+ }
903
+
904
+ function parseFilenameFromContentDisposition(cd) {
905
+ if (!cd) return '';
906
+ // Prefer RFC 5987: filename*=UTF-8''...
907
+ const star = cd.match(/filename\*\s*=\s*UTF-8''([^;]+)/i);
908
+ if (star && star[1]) {
909
+ try { return decodeURIComponent(star[1]); } catch { return star[1]; }
910
+ }
911
+ const m = cd.match(/filename\s*=\s*"([^"]+)"/i) || cd.match(/filename\s*=\s*([^;]+)/i);
912
+ if (m && m[1]) return m[1].trim();
913
+ return '';
914
+ }
915
+
916
+ async function downloadFile(url) {
917
+ const res = await fetch(url);
918
+ if (!res.ok) {
919
+ const text = await res.text().catch(() => '');
920
+ throw new Error(`export failed: http=${res.status} ${text}`);
921
+ }
922
+ const blob = await res.blob();
923
+ const a = document.createElement('a');
924
+ const href = URL.createObjectURL(blob);
925
+ a.href = href;
926
+ // 以 Content-Disposition 为准,兜底再用 URL 推断
927
+ const cd = res.headers.get('content-disposition') || '';
928
+ const fname = parseFilenameFromContentDisposition(cd);
929
+ a.download = fname || (url.includes('/api/dust/') ? '沾尘.xlsx' : '洗手.xlsx');
930
+ document.body.appendChild(a);
931
+ a.click();
932
+ a.remove();
933
+ URL.revokeObjectURL(href);
934
+ }
935
+
936
+ function connectWs() {
937
+ try {
938
+ const ws = new WebSocket(WS_URL);
939
+ let pingInterval;
940
+
941
+ ws.onopen = () => {
942
+ setStatus('已连接', 'dot-ok');
943
+ // 连上后立即刷新一次数据,确保数据最新
944
+ loadSummary();
945
+ loadRecent();
946
+ // 心跳机制:每 30 秒发送一个 ping,防止连接因闲置断开
947
+ pingInterval = setInterval(() => {
948
+ if (ws.readyState === WebSocket.OPEN) {
949
+ ws.send('ping');
950
+ }
951
+ }, 30000);
952
+ };
953
+
954
+ ws.onclose = () => {
955
+ clearInterval(pingInterval);
956
+ setStatus('连接断开,自动重连...', 'dot-warn');
957
+ setTimeout(connectWs, 3000);
958
+ };
959
+
960
+ ws.onerror = () => {
961
+ clearInterval(pingInterval);
962
+ setStatus('连接异常', 'dot-warn');
963
+ };
964
+ ws.onmessage = evt => {
965
+ try {
966
+ const data = JSON.parse(evt.data);
967
+ if (data.type === 'realtime') {
968
+ if (!isAllowedCamera(data)) return;
969
+ appendEvent(data);
970
+ // 浏览器侧洗手 NG 语音提示:区分 未洗手 vs 洗手不合格
971
+ const r = (data.wash_result || '').toUpperCase();
972
+ if (r === 'NG') {
973
+ const reason = (data.reason || '');
974
+ const wt = Number(data.wash_time_sec || 0);
975
+ if (wt <= 0.01 || reason.includes('未洗手') || reason.includes('未进入洗手区')) {
976
+ state.washNgNoWashCnt += 1;
977
+ showAlertFlash('未洗手,请洗手后再进入车间');
978
+ } else {
979
+ state.washNgBadWashCnt += 1;
980
+ showAlertFlash('洗手不规范,请规范洗手后进入车间');
981
+ }
982
+ flushWashNgSpeak(false);
983
+ setTimeout(() => flushWashNgSpeak(true), 1200);
984
+ }
985
+ } else if (data.type === 'summary') {
986
+ loadSummary();
987
+ }
988
+ } catch (e) {
989
+ console.error('ws parse fail', e);
990
+ }
991
+ };
992
+ } catch (e) {
993
+ setStatus('连接失败', 'dot-warn');
994
+ }
995
+ }
996
+
997
+ function connectDustWs() {
998
+ try {
999
+ const ws = new WebSocket(DUST_WS_URL);
1000
+ let pingInterval;
1001
+
1002
+ ws.onopen = () => {
1003
+ // 连上后立即刷新一次数据
1004
+ loadDustSummary();
1005
+ loadDustRecent();
1006
+ pingInterval = setInterval(() => {
1007
+ if (ws.readyState === WebSocket.OPEN) {
1008
+ ws.send('ping');
1009
+ }
1010
+ }, 30000);
1011
+ };
1012
+
1013
+ ws.onclose = () => {
1014
+ clearInterval(pingInterval);
1015
+ setTimeout(connectDustWs, 3000);
1016
+ };
1017
+
1018
+ ws.onerror = () => {
1019
+ clearInterval(pingInterval);
1020
+ };
1021
+
1022
+ ws.onmessage = evt => {
1023
+ try {
1024
+ const data = JSON.parse(evt.data);
1025
+ if (data.type === 'realtime') {
1026
+ if (!isAllowedCamera(data)) return;
1027
+ appendDustEvent(data);
1028
+ // 浏览器侧声音提示:只对 NG 播报(按 reason 区分两类)
1029
+ const r = (data.dust_result || '').toUpperCase();
1030
+ if (r === 'NG') {
1031
+ const reason = (data.reason || '');
1032
+ if (reason.includes('未沾尘') || reason.includes('未进入沾尘区')) {
1033
+ state.dustNgNoDustCnt += 1;
1034
+ showAlertFlash('未沾尘,请沾尘后再进入车间');
1035
+ } else {
1036
+ state.dustNgBadDustCnt += 1;
1037
+ showAlertFlash('沾尘不规范,请规范沾尘后进入车间');
1038
+ }
1039
+ flushDustNgSpeak(false);
1040
+ // 再兜底:1.2s 后强制 flush 一次(防止一直卡在间隔里)
1041
+ setTimeout(() => flushDustNgSpeak(true), 1200);
1042
+ }
1043
+ } else if (data.type === 'summary') {
1044
+ loadDustSummary();
1045
+ }
1046
+ } catch (e) {
1047
+ console.error('dust ws parse fail', e);
1048
+ }
1049
+ };
1050
+ } catch (e) {
1051
+ // ignore
1052
+ }
1053
+ }
1054
+
1055
+ // 初始化视频:支持 FLV (flv.js);HTTP(s) MP4/HLS 直接设置 src;RTSP 无法在浏览器直接播放,请转封装/推流
1056
+ function initVideos() {
1057
+ Object.entries(VIDEO_CONFIG).forEach(([id, url]) => {
1058
+ const video = document.getElementById(id);
1059
+ if (!video || !url) return;
1060
+
1061
+ // 打印 video 元素状态(定位“转圈”到底是 waiting 还是 stalled/网络)
1062
+ if (!video._eventsBound) {
1063
+ video._eventsBound = true;
1064
+ const logVideoState = (tag) => {
1065
+ try {
1066
+ const rs = video.readyState; // 0-4
1067
+ const ns = video.networkState; // 0-3
1068
+ const buf = video.buffered;
1069
+ let bufStr = '';
1070
+ if (buf && buf.length) {
1071
+ const end = buf.end(buf.length - 1);
1072
+ bufStr = ` bufferedEnd=${end.toFixed(2)} ct=${video.currentTime.toFixed(2)} delta=${(end - video.currentTime).toFixed(2)}`;
1073
+ }
1074
+ console.warn(`[VIDEO:${id}] ${tag} readyState=${rs} networkState=${ns}${bufStr}`);
1075
+ } catch {}
1076
+ };
1077
+ video.addEventListener('waiting', () => logVideoState('waiting'));
1078
+ video.addEventListener('stalled', () => logVideoState('stalled'));
1079
+ video.addEventListener('error', () => logVideoState('error'));
1080
+ }
1081
+
1082
+ const lower = url.toLowerCase();
1083
+
1084
+ // 缓冲守门员(自适应):尽量不转圈,也尽量不“卡一下暂停一下”
1085
+ // 思路:
1086
+ // - delta 变薄时先降 playbackRate,让 buffer 自然回涨(更顺)
1087
+ // - 只有 delta 极低才 pause(避免进入 waiting 转圈)
1088
+ // - 恢复时一次性攒够 buffer 再 play
1089
+ const BUFFER_PAUSE = 0.12; // delta < 0.12s 且连续触发 -> pause
1090
+ const BUFFER_RESUME = 1.50; // pause 后至少攒到 1.5s 再恢复
1091
+ const BUFFER_TARGET_LOW = 0.60; // <0.6s 开始降速
1092
+ const BUFFER_TARGET_HIGH = 2.50; // >2.5s 轻微加速追上
1093
+ const GUARD_INTERVAL_MS = 200;
1094
+ const ensureBufferGuard = () => {
1095
+ if (video._bufferGuardStarted) return;
1096
+ video._bufferGuardStarted = true;
1097
+ video._bufferingByGuard = false;
1098
+ video._guardLowCnt = 0;
1099
+ video._guardTimer = setInterval(() => {
1100
+ try {
1101
+ const buf = video.buffered;
1102
+ if (!buf || buf.length === 0) return;
1103
+ const end = buf.end(buf.length - 1);
1104
+ const ct = video.currentTime || 0;
1105
+ const delta = end - ct;
1106
+
1107
+ // 如果是 guard pause 状态:攒够再恢复
1108
+ if (video.paused && video._bufferingByGuard) {
1109
+ if (delta >= BUFFER_RESUME) {
1110
+ video._bufferingByGuard = false;
1111
+ video.playbackRate = 1.0;
1112
+ console.warn(`[VIDEO:${id}] guard_resume delta=${delta.toFixed(2)}s`);
1113
+ video.play().catch(() => {});
1114
+ }
1115
+ return;
1116
+ }
1117
+
1118
+ // 初始阶段:先攒够再播放
1119
+ if (video.paused && !video._bufferingByGuard) {
1120
+ if (delta >= BUFFER_RESUME) {
1121
+ video.playbackRate = 1.0;
1122
+ video.play().catch(() => {});
1123
+ }
1124
+ return;
1125
+ }
1126
+
1127
+ // 播放中:优先“降速”而不是 pause(更顺)
1128
+ if (!video.paused) {
1129
+ if (delta <= BUFFER_PAUSE) {
1130
+ video._guardLowCnt += 1;
1131
+ } else {
1132
+ video._guardLowCnt = 0;
1133
+ }
1134
+
1135
+ // 连续多次极低 buffer,才 pause(避免抖动误判导致频繁停)
1136
+ if (video._guardLowCnt >= 2) {
1137
+ video._bufferingByGuard = true;
1138
+ video._guardLowCnt = 0;
1139
+ try { video.pause(); } catch {}
1140
+ console.warn(`[VIDEO:${id}] guard_pause delta=${delta.toFixed(2)}s`);
1141
+ return;
1142
+ }
1143
+
1144
+ // 自适应速率:buffer 薄 -> 降速;buffer 厚 -> 轻微加速追上;中间 -> 正常
1145
+ let rate = 1.0;
1146
+ if (delta < BUFFER_TARGET_LOW) rate = 0.85;
1147
+ else if (delta > BUFFER_TARGET_HIGH) rate = 1.05;
1148
+ if (video.playbackRate !== rate) video.playbackRate = rate;
1149
+ }
1150
+ } catch {}
1151
+ }, GUARD_INTERVAL_MS);
1152
+ };
1153
+
1154
+ // RTSP 需转换为 FLV/HLS/WebRTC 才能在浏览器播放
1155
+ if (lower.startsWith('rtsp://')) {
1156
+ console.warn(`RTSP 无法直接在浏览器播放,请先转封装为 FLV/HLS/WebRTC: ${url}`);
1157
+ // 避免 file:// 去加载 poster 造成 404
1158
+ video.removeAttribute('poster');
1159
+ return;
1160
+ }
1161
+
1162
+ // 使用 flv.js 播放 FLV
1163
+ if (window.flvjs && flvjs.isSupported() && lower.endsWith('.flv')) {
1164
+ const FLV_PLAYER_CONFIG = {
1165
+ // Live 稳定优先:适当 stash + 清理,减少短抖动导致的转圈
1166
+ // 某些浏览器/策略下 blob worker 会直接报错(blob:null TypeError),默认关闭
1167
+ enableWorker: false,
1168
+ enableStashBuffer: true,
1169
+ // 缓冲更大:让 MSE 保持 1~2 秒余量,代价是延迟会增加一点,但更稳
1170
+ stashInitialSize: 8192,
1171
+ // 允许直播“堆缓冲”,不要追求极限低延迟(否则缓冲会被压到接近 0,抖动就 waiting)
1172
+ liveBufferLatencyChasing: false,
1173
+ liveBufferLatencyMaxLatency: 10,
1174
+ liveBufferLatencyMinRemain: 1.0,
1175
+ lazyLoad: false,
1176
+ autoCleanupSourceBuffer: true,
1177
+ autoCleanupMaxBackwardDuration: 30,
1178
+ autoCleanupMinBackwardDuration: 15
1179
+ };
1180
+
1181
+ let softRecovering = false;
1182
+ let hardRecovering = false;
1183
+ let lastHardRecoverAt = 0;
1184
+ let lastProgressAt = Date.now();
1185
+ let lastCt = -1;
1186
+ let lastBufEnd = -1;
1187
+
1188
+ const destroyFlv = () => {
1189
+ if (!video._flv) return;
1190
+ try { video._flv.destroy(); } catch {}
1191
+ video._flv = null;
1192
+ };
1193
+
1194
+ const markProgress = () => {
1195
+ lastProgressAt = Date.now();
1196
+ };
1197
+
1198
+ const clearWatchdog = () => {
1199
+ if (video._flvWatchdogTimer) {
1200
+ clearInterval(video._flvWatchdogTimer);
1201
+ video._flvWatchdogTimer = null;
1202
+ }
1203
+ };
1204
+
1205
+ const hardRecover = (reason) => {
1206
+ const nowTs = Date.now();
1207
+ if (hardRecovering) return;
1208
+ if (nowTs - lastHardRecoverAt < 5000) return; // 限制重建频率,避免风暴
1209
+ hardRecovering = true;
1210
+ lastHardRecoverAt = nowTs;
1211
+ console.warn(`[FLV] hard recover ${id}: ${reason}`);
1212
+ clearWatchdog();
1213
+ destroyFlv();
1214
+ setTimeout(() => {
1215
+ try {
1216
+ buildFlvPlayer();
1217
+ } finally {
1218
+ hardRecovering = false;
1219
+ }
1220
+ }, 1200);
1221
+ };
1222
+
1223
+ const softRecover = (reason) => {
1224
+ if (softRecovering || hardRecovering) return;
1225
+ softRecovering = true;
1226
+ try {
1227
+ if (video._flv) {
1228
+ try { video._flv.unload(); } catch {}
1229
+ try { video._flv.load(); } catch {}
1230
+ }
1231
+ } finally {
1232
+ setTimeout(() => {
1233
+ softRecovering = false;
1234
+ if (Date.now() - lastProgressAt >= 8000) {
1235
+ hardRecover(`soft timeout: ${reason}`);
1236
+ }
1237
+ }, 1600);
1238
+ }
1239
+ };
1240
+
1241
+ const startWatchdog = () => {
1242
+ clearWatchdog();
1243
+ lastProgressAt = Date.now();
1244
+ lastCt = -1;
1245
+ lastBufEnd = -1;
1246
+ video._flvWatchdogTimer = setInterval(() => {
1247
+ if (!video._flv || hardRecovering) return;
1248
+ try {
1249
+ const ct = video.currentTime || 0;
1250
+ const buf = video.buffered;
1251
+ const end = (buf && buf.length) ? buf.end(buf.length - 1) : -1;
1252
+
1253
+ if (ct > lastCt + 0.05 || end > lastBufEnd + 0.10) {
1254
+ lastCt = ct;
1255
+ lastBufEnd = end;
1256
+ markProgress();
1257
+ return;
1258
+ }
1259
+
1260
+ // guard 主动 pause 的阶段不判定为死流
1261
+ if (video._bufferingByGuard) return;
1262
+ const stuckMs = Date.now() - lastProgressAt;
1263
+ if (stuckMs >= 12000) {
1264
+ hardRecover(`watchdog no progress ${stuckMs}ms`);
1265
+ }
1266
+ } catch {}
1267
+ }, 1000);
1268
+ };
1269
+
1270
+ const buildFlvPlayer = () => {
1271
+ destroyFlv();
1272
+ const flvPlayer = flvjs.createPlayer(
1273
+ {
1274
+ type: 'flv',
1275
+ url,
1276
+ isLive: true,
1277
+ hasAudio: false
1278
+ },
1279
+ FLV_PLAYER_CONFIG
1280
+ );
1281
+ flvPlayer.attachMediaElement(video);
1282
+ flvPlayer.load();
1283
+ // 不要立刻播放,让 guard 先攒 buffer(避免贴边播放导致 waiting)
1284
+ try { video.pause(); } catch {}
1285
+ ensureBufferGuard();
1286
+ video._flv = flvPlayer;
1287
+ startWatchdog();
1288
+ markProgress();
1289
+
1290
+ flvPlayer.on(flvjs.Events.ERROR, (errType, errDetail) => {
1291
+ console.warn('[FLV] error', errType, errDetail);
1292
+ softRecover(`flv error: ${errType}/${errDetail}`);
1293
+ });
1294
+ };
1295
+
1296
+ try {
1297
+ if (!video._flvProgressEventsBound) {
1298
+ video._flvProgressEventsBound = true;
1299
+ ['playing', 'timeupdate', 'progress', 'loadeddata', 'canplay'].forEach((evt) => {
1300
+ video.addEventListener(evt, markProgress);
1301
+ });
1302
+ video.addEventListener('stalled', () => {
1303
+ if (video._bufferingByGuard) return;
1304
+ console.warn(`[FLV] stalled ${id}`);
1305
+ softRecover('video stalled');
1306
+ });
1307
+ video.addEventListener('error', () => {
1308
+ if (video._bufferingByGuard) return;
1309
+ softRecover('video error');
1310
+ });
1311
+ video.addEventListener('ended', () => {
1312
+ hardRecover('video ended');
1313
+ });
1314
+ }
1315
+
1316
+ buildFlvPlayer();
1317
+ } catch (e) {
1318
+ console.error('flv.js 初始化失败', e);
1319
+ }
1320
+ return;
1321
+ }
1322
+
1323
+ // 其他 HTTP(s) 流(HLS/MP4)
1324
+ video.src = url;
1325
+ video.play().catch(() => {});
1326
+ });
1327
+ }
1328
+
1329
+ document.getElementById('refresh-btn').addEventListener('click', () => {
1330
+ loadRecent();
1331
+ loadSummary();
1332
+ loadDustSummary();
1333
+ loadDustRecent();
1334
+ });
1335
+
1336
+ function bootstrapApp() {
1337
+ if (__appBootstrapped) return;
1338
+ __appBootstrapped = true;
1339
+
1340
+ initSoundUi();
1341
+ initClipPlaybackUi();
1342
+
1343
+ // 导出弹层
1344
+ const pop = document.getElementById('export-popover');
1345
+ const toggle = document.getElementById('export-toggle-btn');
1346
+ const startEl = document.getElementById('export-start');
1347
+ const endEl = document.getElementById('export-end');
1348
+
1349
+ const closePop = () => { if (pop) pop.style.display = 'none'; };
1350
+ const togglePop = () => {
1351
+ if (!pop) return;
1352
+ const isOpen = pop.style.display !== 'none';
1353
+ pop.style.display = isOpen ? 'none' : 'block';
1354
+ };
1355
+ if (toggle) toggle.addEventListener('click', (e) => { e.stopPropagation(); togglePop(); });
1356
+ if (pop) pop.addEventListener('click', (e) => e.stopPropagation());
1357
+ document.addEventListener('click', () => closePop());
1358
+
1359
+ // 默认导出范围:今天 00:00 到现在
1360
+ const now = new Date();
1361
+ const today0 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
1362
+ if (startEl) startEl.value = toDatetimeLocal(today0);
1363
+ if (endEl) endEl.value = toDatetimeLocal(now);
1364
+
1365
+ const exportWashBtn = document.getElementById('export-wash-btn');
1366
+ if (exportWashBtn) {
1367
+ exportWashBtn.addEventListener('click', async () => {
1368
+ try {
1369
+ const start = normalizeIsoLocalSeconds(startEl?.value);
1370
+ const end = normalizeIsoLocalSeconds(endEl?.value);
1371
+ const url = withCameraIds(`${API_BASE}/export?start=${encodeURIComponent(start)}&end=${encodeURIComponent(end)}`);
1372
+ await downloadFile(url);
1373
+ closePop();
1374
+ } catch (e) {
1375
+ console.error(e);
1376
+ alert(String(e.message || e));
1377
+ }
1378
+ });
1379
+ }
1380
+
1381
+ const exportDustBtn = document.getElementById('export-dust-btn');
1382
+ if (exportDustBtn) {
1383
+ exportDustBtn.addEventListener('click', async () => {
1384
+ try {
1385
+ const start = normalizeIsoLocalSeconds(startEl?.value);
1386
+ const end = normalizeIsoLocalSeconds(endEl?.value);
1387
+ const url = withCameraIds(`${DUST_API_BASE}/export?start=${encodeURIComponent(start)}&end=${encodeURIComponent(end)}`);
1388
+ await downloadFile(url);
1389
+ closePop();
1390
+ } catch (e) {
1391
+ console.error(e);
1392
+ alert(String(e.message || e));
1393
+ }
1394
+ });
1395
+ }
1396
+
1397
+ // 顶部“数据分析”按钮
1398
+ const anaBtn = document.getElementById('analytics-btn');
1399
+ if (anaBtn) anaBtn.addEventListener('click', () => gotoAnalytics('wash'));
1400
+
1401
+ // 点击统计卡片跳转(“视频框下面的数据统计栏任何一个”)
1402
+ const bindCardClick = (selector, tab, title) => {
1403
+ document.querySelectorAll(selector).forEach(el => {
1404
+ try {
1405
+ const card = el.closest('.card');
1406
+ if (card) {
1407
+ card.style.cursor = 'pointer';
1408
+ if (title) card.title = title;
1409
+ card.addEventListener('click', () => gotoAnalytics(tab));
1410
+ }
1411
+ } catch {}
1412
+ });
1413
+ };
1414
+ bindCardClick('#ok-count, #ng-count, #no-wash-count, #unknown-count, #yield', 'wash', '点击查看洗手数据分析');
1415
+ bindCardClick('#dust-ok-count, #dust-ng-count, #dust-no-dust-count, #dust-unknown-count, #dust-yield', 'dust', '点击查看沾尘数据分析');
1416
+
1417
+ // 回放列表:点击统计数字(不规范/未洗手/未知)弹出该类别所有回放
1418
+ function catTitle(scene, cat) {
1419
+ if (scene === 'wash') {
1420
+ if (cat === 'bad') return '洗手不规范回放';
1421
+ if (cat === 'no') return '未洗手回放';
1422
+ return '洗手未知回放';
1423
+ } else {
1424
+ if (cat === 'bad') return '沾尘不规范回放';
1425
+ if (cat === 'no') return '未沾尘回放';
1426
+ return '沾尘未知回放';
1427
+ }
1428
+ }
1429
+
1430
+ const clipListModal = document.getElementById('cliplist-modal');
1431
+ const clipListBody = document.getElementById('cliplist-body');
1432
+ const clipListTitle = document.getElementById('cliplist-title');
1433
+ const clipListSubtitle = document.getElementById('cliplist-subtitle');
1434
+ const clipListCloseBtn = document.getElementById('cliplist-close-btn');
1435
+ const clipListRefreshBtn = document.getElementById('cliplist-refresh-btn');
1436
+ const clipListPrevBtn = document.getElementById('cliplist-prev-btn');
1437
+ const clipListNextBtn = document.getElementById('cliplist-next-btn');
1438
+ const clipListDateEl = document.getElementById('cliplist-date');
1439
+ let lastClipListReq = null;
1440
+ const CLIPLIST_PAGE_SIZE = 100;
1441
+
1442
+ function localYmd(d) {
1443
+ const y = d.getFullYear();
1444
+ const m = String(d.getMonth() + 1).padStart(2, '0');
1445
+ const day = String(d.getDate()).padStart(2, '0');
1446
+ return `${y}-${m}-${day}`;
1447
+ }
1448
+
1449
+ function getClipListDate() {
1450
+ if (!clipListDateEl) return null;
1451
+ let v = (clipListDateEl.value || '').trim();
1452
+ if (!v) {
1453
+ v = localYmd(new Date());
1454
+ clipListDateEl.value = v;
1455
+ }
1456
+ return v;
1457
+ }
1458
+
1459
+ function showClipListModal() {
1460
+ if (clipListModal) clipListModal.style.display = 'block';
1461
+ }
1462
+ function hideClipListModal() {
1463
+ if (clipListModal) clipListModal.style.display = 'none';
1464
+ }
1465
+ if (clipListCloseBtn) clipListCloseBtn.addEventListener('click', hideClipListModal);
1466
+ if (clipListModal) clipListModal.addEventListener('click', (e) => { if (e.target === clipListModal) hideClipListModal(); });
1467
+ if (clipListRefreshBtn) clipListRefreshBtn.addEventListener('click', () => { if (lastClipListReq) openClipList(lastClipListReq.scene, lastClipListReq.cat, lastClipListReq.page || 1); });
1468
+ if (clipListDateEl) clipListDateEl.addEventListener('change', () => { if (lastClipListReq) openClipList(lastClipListReq.scene, lastClipListReq.cat, 1); });
1469
+ if (clipListPrevBtn) clipListPrevBtn.addEventListener('click', () => {
1470
+ if (!lastClipListReq) return;
1471
+ const p = Math.max(1, (lastClipListReq.page || 1) - 1);
1472
+ openClipList(lastClipListReq.scene, lastClipListReq.cat, p);
1473
+ });
1474
+ if (clipListNextBtn) clipListNextBtn.addEventListener('click', () => {
1475
+ if (!lastClipListReq) return;
1476
+ const p = (lastClipListReq.page || 1) + 1;
1477
+ openClipList(lastClipListReq.scene, lastClipListReq.cat, p);
1478
+ });
1479
+
1480
+ function updateClipListPager(page, totalPages) {
1481
+ const p = Number(page || 1);
1482
+ const tp = Number(totalPages || 1);
1483
+ if (clipListPrevBtn) clipListPrevBtn.disabled = (p <= 1);
1484
+ if (clipListNextBtn) clipListNextBtn.disabled = (p >= tp);
1485
+ }
1486
+
1487
+ function renderClipList(scene, cat, date, items, page, size, total, totalPages) {
1488
+ if (!clipListBody) return;
1489
+ const list = items || [];
1490
+ if (clipListTitle) clipListTitle.textContent = catTitle(scene, cat);
1491
+ if (clipListSubtitle) {
1492
+ const p = Number(page || 1);
1493
+ const tp = Number(totalPages || 1);
1494
+ const t = Number(total || 0);
1495
+ clipListSubtitle.textContent = `日期:${date || ''},共 ${t} 条,第 ${p}/${tp} 页(每页 ${Number(size || CLIPLIST_PAGE_SIZE)} 条)`;
1496
+ }
1497
+ updateClipListPager(page, totalPages);
1498
+ if (list.length === 0) {
1499
+ clipListBody.innerHTML = `<div class="row" style="grid-template-columns: 1fr; color: var(--muted);"><div>暂无回放(可能还没产生 clip_url,或后端未重启)</div></div>`;
1500
+ return;
1501
+ }
1502
+ clipListBody.innerHTML = list.map((e) => {
1503
+ const t = pick(e, 'exited_at','exitedAt') || pick(e, 'dust_finished_at','dustFinishedAt') || pick(e,'wash_finished_at','washFinishedAt') || '';
1504
+ const cam = pick(e, 'camera_id','cameraId') ?? '';
1505
+ const r = (pick(e, 'wash_result','washResult') || pick(e, 'dust_result','dustResult') || '').toUpperCase();
1506
+ const sec = pick(e, 'wash_time_sec','washTimeSec') ?? pick(e, 'dust_time_sec','dustTimeSec') ?? 0;
1507
+ const reason = pick(e, 'reason','reason') || '';
1508
+ const clip = pick(e, 'clip_url','clipUrl') || '';
1509
+ return `
1510
+ <div class="row ${rowClass(r)}" style="grid-template-columns: 1.2fr 0.6fr 0.9fr 0.8fr 1.6fr 0.7fr;">
1511
+ <div>${escapeHtml(String(t))}</div>
1512
+ <div>${escapeHtml(String(cam))}</div>
1513
+ <div>${escapeHtml(String(r))}</div>
1514
+ <div>${Number(sec || 0).toFixed(1)}</div>
1515
+ <div>${escapeHtml(String(reason))}</div>
1516
+ <div>${clip ? `<button class="btn btn-sm" data-clip="${escapeHtml(String(clip))}">播放</button>` : '--'}</div>
1517
+ </div>
1518
+ `;
1519
+ }).join('');
1520
+ }
1521
+
1522
+ async function openClipList(scene, cat, page = 1) {
1523
+ const base = scene === 'wash' ? API_BASE : DUST_API_BASE;
1524
+ const pickedDate = getClipListDate();
1525
+ const p = Math.max(1, Number(page || 1));
1526
+ const url = withCameraIds(`${base}/clips/recent?category=${encodeURIComponent(cat)}&page=${p}&size=${CLIPLIST_PAGE_SIZE}${pickedDate ? `&date=${encodeURIComponent(pickedDate)}` : ''}`);
1527
+ lastClipListReq = { scene, cat, page: p, size: CLIPLIST_PAGE_SIZE };
1528
+ showClipListModal();
1529
+ updateClipListPager(p, p); // 先禁用/更新一下,避免用户连点
1530
+ if (clipListBody) clipListBody.innerHTML = `<div class="row" style="grid-template-columns: 1fr; color: var(--muted);"><div>加载中...</div></div>`;
1531
+ try {
1532
+ const res = await fetch(url);
1533
+ if (!res.ok) throw new Error(`http=${res.status}`);
1534
+ const data = await res.json();
1535
+ // 回写服务端最终使用的日期(如果前端没填,会默认 today)
1536
+ if (clipListDateEl && data && data.date) clipListDateEl.value = String(data.date);
1537
+ lastClipListReq.page = Number(data.page || p);
1538
+ renderClipList(scene, cat, data.date, data.clips || [], data.page, data.size, data.total, data.total_pages);
1539
+ } catch (e) {
1540
+ updateClipListPager(1, 1);
1541
+ if (clipListBody) clipListBody.innerHTML = `<div class="row" style="grid-template-columns: 1fr; color: var(--ng);"><div>加载失败:${escapeHtml(String(e))}</div></div>`;
1542
+ }
1543
+ }
1544
+
1545
+ function bindClipListClick(selector, scene, cat) {
1546
+ document.querySelectorAll(selector).forEach((el) => {
1547
+ el.style.cursor = 'pointer';
1548
+ el.title = '点击查看回放列表';
1549
+ el.addEventListener('click', (e) => {
1550
+ e.preventDefault();
1551
+ e.stopPropagation();
1552
+ openClipList(scene, cat);
1553
+ });
1554
+ });
1555
+ }
1556
+ // wash: 不规范/未洗手/未知
1557
+ bindClipListClick('#ng-count', 'wash', 'bad');
1558
+ bindClipListClick('#no-wash-count', 'wash', 'no');
1559
+ bindClipListClick('#unknown-count', 'wash', 'unknown');
1560
+ // dust: 不规范/未沾尘/未知
1561
+ bindClipListClick('#dust-ng-count', 'dust', 'bad');
1562
+ bindClipListClick('#dust-no-dust-count', 'dust', 'no');
1563
+ bindClipListClick('#dust-unknown-count', 'dust', 'unknown');
1564
+
1565
+ // 实时事件:支持鼠标拖拽滚动(框内拖动)
1566
+ enableDragScroll(document.getElementById('event-body'));
1567
+ enableDragScroll(document.getElementById('dust-event-body'));
1568
+
1569
+ loadRecent();
1570
+ loadSummary();
1571
+ loadDustSummary();
1572
+ loadDustRecent();
1573
+ connectWs();
1574
+ connectDustWs();
1575
+ initVideos();
1576
+ // 移除高频轮询,改为每 5 分钟同步一次作为兜底
1577
+ setInterval(loadSummary, 300000);
1578
+ setInterval(loadDustSummary, 300000);
1579
+ }
1580
+
1581
+ window.addEventListener('DOMContentLoaded', async () => {
1582
+ const ok = await checkPageAccess();
1583
+ if (!ok) return;
1584
+ guardShowApp();
1585
+ bootstrapApp();
1586
+ });
1587
+ </script>
1588
+ </div>
1589
+ </body>
1590
+ </html>
1591
+
gengyishi2/styles.css ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :root {
2
+ --bg: #0f172a;
3
+ --panel: #1e293b;
4
+ --text: #e2e8f0;
5
+ --muted: #94a3b8;
6
+ --ok: #4ade80;
7
+ --ng: #f87171;
8
+ --warn: #facc15;
9
+ }
10
+
11
+ * { box-sizing: border-box; }
12
+ body { margin: 0; font-family: "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); }
13
+ .page { padding: 20px; }
14
+
15
+ .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
16
+ .header h1 { margin: 0; font-size: 24px; }
17
+ .muted { color: var(--muted); font-size: 13px; }
18
+ .status { display: flex; align-items: center; gap: 8px; font-weight: 600; }
19
+ .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
20
+ .dot-ok { background: var(--ok); box-shadow: 0 0 12px var(--ok); }
21
+ .dot-warn { background: var(--warn); box-shadow: 0 0 12px var(--warn); }
22
+
23
+ .cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
24
+ .card { background: var(--panel); padding: 14px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,0.2); }
25
+ .label { color: var(--muted); font-size: 13px; }
26
+ .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
27
+ .value.ok { color: var(--ok); }
28
+ .value.ng { color: var(--ng); }
29
+ .value.warn { color: var(--warn); }
30
+
31
+ .grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; }
32
+ .panel { background: var(--panel); border-radius: 14px; padding: 16px; box-shadow: 0 10px 24px rgba(0,0,0,0.25); min-height: 340px; }
33
+ .panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
34
+ .title { font-weight: 700; font-size: 16px; }
35
+ .btn { background: #334155; color: var(--text); border: 1px solid #475569; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
36
+ .btn:hover { background: #3b4a63; }
37
+
38
+ .btn-primary { background: #334155; color: var(--text); border: 1px solid #475569; }
39
+
40
+ /* =========================
41
+ 临时访问控制(前端登录遮罩)
42
+ 注意:仅做“临时管控”,不具备真正安全性(账号密码在前端可见)
43
+ ========================= */
44
+ .auth-mask {
45
+ position: fixed;
46
+ inset: 0;
47
+ background: rgba(2, 6, 23, 0.80);
48
+ backdrop-filter: blur(6px);
49
+ display: flex;
50
+ align-items: center;
51
+ justify-content: center;
52
+ z-index: 2000;
53
+ }
54
+ .auth-card {
55
+ width: min(420px, calc(100vw - 32px));
56
+ background: var(--panel);
57
+ border: 1px solid #334155;
58
+ border-radius: 14px;
59
+ box-shadow: 0 20px 45px rgba(0,0,0,0.45);
60
+ padding: 16px;
61
+ }
62
+ .auth-title { font-weight: 800; font-size: 18px; margin-bottom: 6px; }
63
+ .auth-desc { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
64
+ .auth-row { display: grid; gap: 10px; margin-bottom: 12px; }
65
+ .auth-field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
66
+ .auth-input {
67
+ width: 100%;
68
+ background: #0b1220;
69
+ color: var(--text);
70
+ border: 1px solid #334155;
71
+ border-radius: 10px;
72
+ padding: 10px 12px;
73
+ outline: none;
74
+ }
75
+ .auth-actions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
76
+ .auth-error { color: var(--ng); font-size: 13px; min-height: 18px; }
77
+ .auth-hide { display: none !important; }
78
+
79
+ /* =========================
80
+ 闪屏报警(红/黄)8秒自动消失 - 仿 AA 烘烤
81
+ ========================= */
82
+ @keyframes alertFlashBg {
83
+ 0% { opacity: 0.65; }
84
+ 50% { opacity: 1; }
85
+ 100% { opacity: 0.65; }
86
+ }
87
+ #alert-modal {
88
+ display: none;
89
+ position: fixed;
90
+ z-index: 1500;
91
+ left: 0;
92
+ top: 0;
93
+ width: 100%;
94
+ height: 100%;
95
+ align-items: center;
96
+ justify-content: center;
97
+ }
98
+ #alert-modal.alert-flash-red { background-color: rgba(220, 38, 38, 0.45); animation: alertFlashBg 0.55s ease-in-out infinite; }
99
+ #alert-modal.alert-flash-yellow { background-color: rgba(250, 204, 21, 0.40); animation: alertFlashBg 0.55s ease-in-out infinite; }
100
+ #alert-modal.show { display: flex; }
101
+ #alert-modal .modal-content {
102
+ background-color: #1e293b;
103
+ padding: 2rem;
104
+ border-radius: 0.75rem;
105
+ max-width: 1400px;
106
+ width: min(98vw, 1400px);
107
+ min-height: 75vh;
108
+ display: flex;
109
+ flex-direction: column;
110
+ justify-content: center;
111
+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
112
+ }
113
+ #alert-modal .modal-header {
114
+ font-size: 4.5rem;
115
+ font-weight: 700;
116
+ margin-bottom: 1rem;
117
+ color: #f87171;
118
+ }
119
+ #alert-modal .modal-body {
120
+ color: #e2e8f0;
121
+ font-size: 4rem;
122
+ }
123
+
124
+ .export-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
125
+ .export-row label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
126
+ .export-row input { background: #0b1220; color: var(--text); border: 1px solid #334155; border-radius: 8px; padding: 8px 10px; }
127
+
128
+ .export-popover-wrap { position: relative; }
129
+ .export-popover {
130
+ position: absolute;
131
+ top: 44px;
132
+ right: 0;
133
+ z-index: 50;
134
+ width: 360px;
135
+ background: #0b1220;
136
+ border: 1px solid #334155;
137
+ border-radius: 12px;
138
+ padding: 12px;
139
+ box-shadow: 0 18px 40px rgba(0,0,0,0.45);
140
+ }
141
+ .export-popover-title { font-weight: 800; margin-bottom: 8px; }
142
+ .export-actions { display: flex; gap: 10px; margin-top: 10px; margin-bottom: 6px; }
143
+
144
+ .table { border: 1px solid #334155; border-radius: 10px; overflow: hidden; }
145
+ .table-head, .row { display: grid; grid-template-columns: 1.1fr 0.7fr 0.8fr 0.8fr 0.7fr 1.2fr 0.7fr; padding: 10px; }
146
+ .table-head { background: #111827; color: var(--muted); font-size: 13px; }
147
+ .row { border-top: 1px solid #1f2937; font-size: 14px; align-items: center; }
148
+ .row-ok { background: rgba(74, 222, 128, 0.08); }
149
+ .row-ng { background: rgba(248, 113, 113, 0.10); }
150
+ .row-warn { background: rgba(250, 204, 21, 0.10); }
151
+ .center { text-align: center; }
152
+
153
+ /* 事件列表:可滚动(50条) */
154
+ .table-body-scroll {
155
+ /* 约显示 10 条左右,其余通过滚动条/拖拽浏览 */
156
+ max-height: 420px;
157
+ overflow-y: auto;
158
+ cursor: grab;
159
+ user-select: none;
160
+ }
161
+ .table-body-scroll.dragging { cursor: grabbing; }
162
+ .table-body-scroll::-webkit-scrollbar { width: 10px; }
163
+ .table-body-scroll::-webkit-scrollbar-thumb { background: #475569; border-radius: 6px; }
164
+ .table-body-scroll::-webkit-scrollbar-thumb:hover { background: #64748b; }
165
+
166
+ /* 刷新动效:从上往下“滑入” */
167
+ @keyframes refreshDropIn {
168
+ from { transform: translateY(-10px); opacity: 0.45; }
169
+ to { transform: translateY(0); opacity: 1; }
170
+ }
171
+ .table-body-scroll.refreshing {
172
+ animation: refreshDropIn 320ms ease-out;
173
+ }
174
+ .row.row-new {
175
+ animation: refreshDropIn 320ms ease-out;
176
+ }
177
+
178
+ .video-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
179
+ .video-card { background: #111827; border-radius: 10px; padding: 10px; }
180
+ .video-title { font-weight: 600; margin-bottom: 6px; }
181
+ video { width: 100%; height: 220px; object-fit: cover; background: #000; border-radius: 8px; }
182
+
183
+ .grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
184
+ .col { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
185
+ .video-panel { padding: 0; overflow: hidden; min-height: auto; position: relative; }
186
+ .video-panel video { height: 500px; }
187
+ .video-title-bar { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,0.6); color: var(--ok); padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 700; }
188
+ .video-title-bar.dust { color: var(--warn); }
189
+ .cards.two-row { grid-template-columns: repeat(5, minmax(0, 1fr)); }
190
+
191
+ @media (max-width: 1100px) {
192
+ .grid { grid-template-columns: 1fr; }
193
+ .grid-2col { grid-template-columns: 1fr; }
194
+ .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
195
+ .cards.two-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
196
+ }
197
+
198
+ @media (max-width: 640px) {
199
+ .cards { grid-template-columns: 1fr; }
200
+ .cards.two-row { grid-template-columns: 1fr; }
201
+ .table-head, .row { grid-template-columns: 1fr 0.6fr 0.6fr 0.7fr 0.6fr 1fr 0.6fr; }
202
+ }
203
+
204
+ /* =========================
205
+ 数据分析页(analytics.html)
206
+ ========================= */
207
+ .ana-tabs { display: flex; gap: 10px; margin-bottom: 12px; }
208
+ .ana-tab {
209
+ background: #111827;
210
+ color: var(--text);
211
+ border: 1px solid #334155;
212
+ padding: 10px 14px;
213
+ border-radius: 10px;
214
+ cursor: pointer;
215
+ font-weight: 700;
216
+ }
217
+ .ana-tab.active { border-color: #60a5fa; box-shadow: 0 0 0 2px rgba(96,165,250,0.25) inset; }
218
+ .ana-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
219
+ .ana-panel { min-height: auto; }
220
+ .ana-panel-wide { grid-column: 1 / -1; }
221
+ .ana-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
222
+ .ana-controls label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
223
+ .ana-controls input { background: #0b1220; color: var(--text); border: 1px solid #334155; border-radius: 8px; padding: 8px 10px; }
224
+ .ana-quick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
225
+ .ana-iconbtn { padding: 8px 10px; min-width: 42px; text-align: center; }
226
+ .ana-chart { height: 320px; }
227
+ .ana-split { display: grid; grid-template-columns: 420px 1fr; gap: 16px; align-items: start; }
228
+ .ana-legend { border: 1px solid #334155; border-radius: 12px; padding: 12px; background: rgba(15,23,42,0.35); }
229
+ .ana-table { margin-top: 10px; display: grid; gap: 8px; }
230
+ .ana-row { display: grid; grid-template-columns: 1fr 1.3fr 80px 90px; gap: 10px; padding: 8px 10px; border: 1px solid #1f2937; border-radius: 10px; background: rgba(17,24,39,0.6); align-items: center; }
231
+ .ana-right { text-align: right; }
232
+ .ana-barwrap { width: 100%; height: 10px; background: rgba(148,163,184,0.18); border-radius: 999px; overflow: hidden; border: 1px solid rgba(51,65,85,0.6); }
233
+ .ana-bar { height: 100%; width: 0%; background: linear-gradient(90deg, rgba(96,165,250,0.9), rgba(74,222,128,0.85)); border-radius: 999px; }
234
+
235
+ @media (max-width: 1100px) {
236
+ .ana-split { grid-template-columns: 1fr; }
237
+ .ana-chart { height: 300px; }
238
+ }
239
+
handwash-show-0.0.1-SNAPSHOT.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbd57ec95c25d1cb8f8581eb01db5210e48584939b62f706210e1d815dec7697
3
+ size 47218946