yxh
yxh
5 天以前 796047fbe84d51816f44be535501415d3c66dd9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
<!doctype html>
<html lang="zh-CN">
 
<head>
    <meta charset="UTF-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>大厅</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            /* Android 6 可用中文字体 */
            ;
            font-family: "Droid Sans Fallback", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
        }
 
        /* 1. 全局深色背景 */
        body {
            background: #001f3f;
            color: #fff;
            height: 100vh;
            overflow: hidden;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-box-direction: normal;
            -webkit-flex-direction: column;
            flex-direction: column;
            font-size: 14px;
        }
 
        /* 2. 顶部栏 */
        .top-header {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-align: center;
            -webkit-align-items: center;
            align-items: center;
            padding: 15px 30px;
            background: rgba(0, 30, 60, 0.9);
            white-space: nowrap;
            position: relative;
            border-bottom: 1px solid #003366;
        }
 
        .top-header img {
            height: 50px;
            margin-right: 20px;
            z-index: 2;
        }
 
        .top-header .title-text {
            position: absolute;
            left: 50%;
            -webkit-transform: translateX(-50%);
            transform: translateX(-50%);
            font-size: 32px;
            font-weight: bold;
            color: #fff;
            z-index: 1;
        }
 
        .top-header .time-info {
            font-size: 20px;
            color: #aaa;
            margin-left: auto;
            z-index: 2;
            text-align: right;
            line-height: 1.3;
        }
 
        .time-info-inner {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-align: center;
            -webkit-align-items: center;
            align-items: center;
        }
 
        .time-left {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-flex-direction: column;
            flex-direction: column;
            text-align: right;
            line-height: 1.3;
        }
 
        .time-right {
            margin-left: 8px;
        }
 
        .top-header .time-info .time-clock {
            font-size: 36px;
            font-weight: bold;
            color: #ffcc00;
            line-height: 1.1;
        }
 
        /* 3. 主体内容(gap 替换为 margin 兼容旧 Chrome) */
        .main-content {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-box-direction: normal;
            -webkit-flex-direction: column;
            flex-direction: column;
            padding: 15px 20px;
            overflow: hidden;
        }
 
        /* 列行容器 */
        .columns-row {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            overflow: hidden;
        }
 
        .columns-row>.column-box {
            margin-left: 5px;
            margin-right: 5px;
        }
 
        .columns-row>.column-box:first-child {
            margin-left: 0;
        }
 
        .columns-row>.column-box:last-child {
            margin-right: 0;
        }
 
        /* 列容器 */
        .column-box {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-box-direction: normal;
            -webkit-flex-direction: column;
            flex-direction: column;
            background: rgba(10, 40, 80, 0.5);
            border-radius: 0;
            padding: 10px;
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            min-width: 0;
            border: 1px solid #003366;
        }
 
        .column-box.col-wide {
            -webkit-box-flex: 2.5;
            -webkit-flex: 2.5;
            flex: 2.5;
        }
 
        .column-box.col-normal {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
        }
 
        /* 标题行 */
        .col-title-line {
            font-size: 22px;
            font-weight: bold;
            color: #4da6ff;
            text-align: center;
        }
 
        .col-title {
            padding-bottom: 8px;
            border-bottom: 1px solid #003366;
            margin-bottom: 10px;
            text-align: center;
        }
 
        .col-subtitle {
            font-size: 14px;
            color: #999;
            text-align: center;
            min-height: 20px;
            /* 即使为空也保留高度,防止标题栏高低不平 */
            ;
            line-height: 1.4;
            word-break: keep-all;
        }
 
        /* 患者列表 */
        .patient-list {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            overflow-y: auto;
            padding-right: 5px;
        }
 
        /* 第1栏:一行两个 */
        #col-0 {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-flex-wrap: wrap;
            flex-wrap: wrap;
            -webkit-align-content: flex-start;
            align-content: flex-start;
        }
 
        .col-normal .patient-list {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-box-direction: normal;
            -webkit-flex-direction: column;
            flex-direction: column;
        }
 
        /* 患者项目 */
        .patient-item {
            font-size: 22px;
            padding: 8px 5px;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-align: center;
            -webkit-align-items: center;
            align-items: center;
            color: #fff;
            line-height: 1.4;
        }
 
        #col-0 .patient-item {
            width: 45%;
            font-size: 20px;
            margin: 0 2.5%;
        }
 
        .p-number {
            color: #ffcc00;
            font-weight: bold;
            margin-right: 8px;
        }
 
        .p-name {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
 
        .p-name-wrap {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
 
        .p-room {
            color: #4da6ff;
            font-weight: bold;
            font-size: 18px;
            margin-left: 4px;
        }
 
        /* 过号患者:排在列内,视觉弱化 */
        .patient-item.missed {
            color: #aa8888;
        }
 
        .patient-item.missed .p-number {
            color: #cc9966;
        }
 
        .patient-item.missed .p-missed-tag {
            color: #ff6666;
            font-size: 16px;
            margin-left: 4px;
            -webkit-flex-shrink: 0;
            flex-shrink: 0;
        }
 
        /* 底部栏 */
        .bottom-footer {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-pack: center;
            -webkit-justify-content: center;
            justify-content: center;
            -webkit-box-align: center;
            -webkit-align-items: center;
            align-items: center;
            padding: 10px 30px;
            background: rgba(0, 30, 60, 0.9);
            border-top: 1px solid #003366;
        }
 
        .footer-tip {
            font-size: 22px;
            color: #ffcc00;
            font-weight: bold;
            text-align: center;
        }
 
        /* 滚动条 */
        .patient-list::-webkit-scrollbar {
            width: 4px;
        }
 
        .patient-list::-webkit-scrollbar-thumb {
            background: #444;
            border-radius: 2px;
        }
 
        /* 调试面板 */
        .debug-panel {
            display: none; /* 需要调试时删掉此行即可显示 */
            position: fixed;
            right: 15px;
            bottom: 70px;
            width: 350px;
            height: 200px;
            background: rgba(0, 0, 0, 0.9);
            color: #0f0;
            border-radius: 4px;
            font-family: monospace;
            font-size: 12px;
            z-index: 9999;
            overflow: visible;
        }
 
        .debug-header {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-pack: justify;
            -webkit-justify-content: space-between;
            justify-content: space-between;
            -webkit-box-align: center;
            -webkit-align-items: center;
            align-items: center;
            padding: 5px;
            background: #333;
            border-bottom: 1px solid #000;
        }
 
        .debug-header span {
            font-weight: bold;
            font-size: 13px;
        }
 
        .debug-header button {
            background: #c00;
            color: #fff;
            border: none;
            padding: 2px 6px;
            font-size: 10px;
            cursor: pointer;
        }
 
        .debug-body {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            padding: 5px;
            overflow-y: auto;
            font-size: 11px;
        }
 
        .debug-line {
            margin-bottom: 2px;
        }
 
        .debug-time {
            color: #888;
        }
    </style>
</head>
 
<body>
    <!-- 顶部栏 -->
    <div class="top-header">
        <img src="logo.png" alt="logo" />
        <span class="title-text">心电检查服务诊区大厅</span>
        <span class="time-info" id="headerTime"></span>
    </div>
 
    <!-- 主体内容 -->
    <div class="main-content" id="mainContent"></div>
 
    <!-- 底部栏 -->
    <div class="bottom-footer">
        <div class="footer-tip">温馨提示:听到呼叫后请前往对应诊室,过号患者到导诊台处理!</div>
    </div>
 
    <!-- 调试面板 -->
    <div class="debug-panel" id="debugPanel" >
        <div class="debug-header">
            <span>[调试] 运行日志</span>
            <button onclick="document.getElementById('debugBody').innerHTML=''">清空</button>
        </div>
        <div class="debug-body" id="debugBody"></div>
    </div>
 
    <script src="./static/jquery.min.js"></script>
    <script>
        // ================= 调试日志 =================
        function logDebug(msg) {
            var now = new Date();
            function pad(num) { return num < 10 ? '0' + num : '' + num; }
            var timeStr = pad(now.getHours()) + ':' + pad(now.getMinutes()) + ':' + pad(now.getSeconds());
            var logHtml = '<div class="debug-line"><span class="debug-time">[' + timeStr + ']</span> ' + msg + '</div>';
            console.log("[" + timeStr + "] " + msg);
            var body = document.getElementById("debugBody");
            if (body) {
                body.insertAdjacentHTML("beforeend", logHtml);
                body.scrollTop = body.scrollHeight;
            }
        }
 
        // ================= 应用状态 =================
        // 呼叫叫号次数参数:呼叫患者就诊时重复播报的次数,默认 2 次
        var CALL_REPEAT_TIMES = 2;
        var appState = {
            columnTitles: ["常规心电图", "动态心电图/血压", "心电图运动试验", "食道电生理", "动脉硬化监测"],
            columnSubTitles: ["床边心电图(常规+频谱) / 心电向量图", "", "", "", ""],
            patients: [],
            apiBaseUrl: "http://localhost/admin-api",
            // apiBaseUrl: "http://10.0.2.193/admin-api",
            pollTimer: null,
            spokenPatients: {},
            ttsQueue: [],
            isSpeaking: false,
        };
 
        var patStatus = {
            3: "已过号-排队", 5: "已过号", 7: "已过号-安装", 10: "排队中", 12: "亲和",
            13: "亲和-安装", 15: "已召回", 20: "候诊中", 30: "就诊中", 33: "已领用",
            34: "已召回-安装", 36: "安装中", 40: "已就诊"
        };
 
        // ================= 语音播报 =================
        function processTtsQueue() {
            if (appState.isSpeaking || appState.ttsQueue.length === 0) return;
            appState.isSpeaking = true;
            var text = appState.ttsQueue.shift();
            logDebug("[播报] " + text);
 
            var utterance = new SpeechSynthesisUtterance(text);
            // Android 6 默认语速可能很快,适当调慢
            utterance.rate = 0.85;
            utterance.onend = function () {
                appState.isSpeaking = false;
                processTtsQueue();
            };
            utterance.onerror = function (e) {
                logDebug("[TTS错误] " + (e.error || "unknown"));
                appState.isSpeaking = false;
                processTtsQueue();
            };
 
            // 优先尝试设备原生 TTS 接口
            if (typeof wowjoy !== 'undefined' && typeof wowjoy.speek === 'function') {
                try {
                    wowjoy.speek(text);
                    setTimeout(function () { appState.isSpeaking = false; processTtsQueue(); }, 4000);
                    return;
                } catch (e) { logDebug("[wowjoy失败] " + e.message); }
            }
 
            if (window.speechSynthesis) {
                // Android 6 WebView 有时需要先 cancel 再 speak
                window.speechSynthesis.cancel();
                window.speechSynthesis.speak(utterance);
            } else {
                logDebug("[TTS] 浏览器不支持语音合成");
                appState.isSpeaking = false;
                processTtsQueue();
            }
        }
 
        function speak(text) {
            if (!text) return;
            appState.ttsQueue.push(text);
            processTtsQueue();
        }
 
        // ================= 渲染:标题框架(仅初始化一次)=================
        function initLayout() {
            var main = document.getElementById("mainContent");
            var html = '<div class="columns-row">';
 
            for (var i = 0; i < appState.columnTitles.length; i++) {
                // 标题和副标题都有固定占位,避免有/无副标题时高度跳动
                var subtitle = appState.columnSubTitles[i] || "&nbsp;";
                var colClass = (i === 0) ? 'col-wide' : 'col-normal';
                html += '<div class="column-box ' + colClass + '">' +
                    '<div class="col-title">' +
                    '<div class="col-title-line">' + appState.columnTitles[i] + '</div>' +
                    '<div class="col-subtitle">' + subtitle + '</div>' +
                    '</div>' +
                    '<div class="patient-list" id="col-' + i + '"></div>' +
                    '</div>';
            }
            html += '</div>';
            main.innerHTML = html;
        }
 
        // ================= 渲染:患者列表(diff 更新,只改变化的列)=================
        function desensitizeName(name) {
            if (!name || name.length < 2) return name || '';
            return name.charAt(0) + '*' + name.substring(2);
        }
 
        function isMissedStatus(status) {
            var s = parseInt(status, 10);
            return s === 3 || s === 5 || s === 7;
        }
 
        function buildColumnHtml(colData) {
            if (!Array.isArray(colData) || colData.length === 0) return "";
            var h = "";
            for (var p = 0; p < colData.length; p++) {
                var pat = colData[p];
                var missedClass = isMissedStatus(pat.status) ? ' missed' : '';
                var roomHtml = (!isMissedStatus(pat.status) && pat.roomName) ? '<span class="p-room">(' + pat.roomName + ')</span>' : '';
                h += '<div class="patient-item' + missedClass + '">' +
                    '<span class="p-number">' + (pat.seqNum || '') + '</span>' +
                    '<span class="p-name-wrap"><span class="p-name">' + desensitizeName(pat.patName) + '</span>' + roomHtml +
                    (missedClass ? '<span class="p-missed-tag">(过号)</span>' : '') + '</span>' +
                    '</div>';
            }
            return h;
        }
        function isSameColumn(a, b) {
            if (!Array.isArray(a) || !Array.isArray(b)) return a === b;
            if (a.length !== b.length) return false;
            for (var i = 0; i < a.length; i++) {
                if (a[i].patId !== b[i].patId) return false;
                if (a[i].roomName !== b[i].roomName) return false;
                if (parseInt(a[i].status, 10) !== parseInt(b[i].status, 10)) return false;
            }
            return true;
        }
 
        function updatePatients(dataList) {
            for (var i = 0; i < appState.columnTitles.length; i++) {
                var newData = (dataList && dataList[i]) ? dataList[i] : [];
                var oldData = appState.patients[i];
 
                // diff:数据未变化则跳过该列 DOM 操作
                if (isSameColumn(oldData, newData)) continue;
 
                var col = document.getElementById("col-" + i);
                if (col) col.innerHTML = buildColumnHtml(newData);
            }
        }
 
        // ================= 数据对比与播报 =================
        function checkAndSpeakNewRooms(oldData, newData) {
            if (!oldData || oldData.length === 0) return;
            for (var c = 0; c < newData.length; c++) {
                var newCol = newData[c];
                var oldCol = oldData[c];
                if (Array.isArray(newCol)) {
                    for (var p = 0; p < newCol.length; p++) {
                        var newPat = newCol[p];
                        if (newPat.roomName) {
                            if (appState.spokenPatients[newPat.patId]) continue;
                            var oldPat = null;
                            if (Array.isArray(oldCol)) {
                                for (var k = 0; k < oldCol.length; k++) {
                                    if (oldCol[k].patId === newPat.patId) {
                                        oldPat = oldCol[k];
                                        break;
                                    }
                                }
                            }
                            if (!oldPat || !oldPat.roomName) {
                                var repeatText = "";
                                repeatText += "请 " + newPat.seqNum + " 号 " + newPat.patName + " 到 " + newPat.roomName + " 就诊。";
                                for (var r = 0; r < CALL_REPEAT_TIMES; r++) {
                                    speak(repeatText);
                                }                                
                                appState.spokenPatients[newPat.patId] = true;
                                logDebug("[排队] " + newPat.patName + " -> " + newPat.roomName);
                            }
                        }
                    }
                }
            }
        }
 
        // ================= 数据获取 =================
        function fetchQueueData() {
            var url = appState.apiBaseUrl + "/ecg/screen/big-screen-data";
            $.ajax({
                url: url,
                type: "GET",
                dataType: "json",
                timeout: 5000,
                success: function (res) {
                    var dataList = [];
                    if (res && res.code === 0 && res.data) {
                        for (var i = 0; i < appState.columnTitles.length; i++) {
                            var key = i.toString();
                            dataList[i] = (res.data[key] && Array.isArray(res.data[key])) ? res.data[key] : [];
                        }
                    }
                    // 先 diff 更新 DOM,再播报,最后保存数据用于下次对比
                    updatePatients(dataList);
                    checkAndSpeakNewRooms(appState.patients, dataList);
                    appState.patients = dataList;
 
                    // Android 6 WebView 通常不支持 performance.memory,安全守卫
                    try {
                        if (window.performance && window.performance.memory) {
                            var usedMB = (window.performance.memory.usedJSHeapSize / 1048576).toFixed(2);
                            logDebug("[内存] " + usedMB + " MB");
                        }
                    } catch (e) { }
                },
                error: function (err) {
                    logDebug("[请求失败] " + (err.statusText || "网络错误"));
                }
            });
        }
 
        // ================= 初始化 =================
        function onReady() {
            initLayout();
            updateHeaderTime();
            setInterval(updateHeaderTime, 1000);
            fetchQueueData();
            appState.pollTimer = setInterval(fetchQueueData, 5000);
            logDebug("[系统] 启动完成 - Android 6.0.1");
        }
 
        function updateHeaderTime() {
            var now = new Date();
            var weekDays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
            function padZero(num) { return num < 10 ? '0' + num : '' + num; }
            var dateStr = now.getFullYear() + "年" + padZero(now.getMonth() + 1) + "月" + padZero(now.getDate()) + "日";
            var weekStr = weekDays[now.getDay()];
            var timeStr = padZero(now.getHours()) + ":" + padZero(now.getMinutes());
            var el = document.getElementById("headerTime");
            // 星期和日期各占一行在左,时间大字在右跨两行
            if (el) el.innerHTML = '<div class="time-info-inner"><div class="time-left"><div>' + weekStr + '</div><div>' + dateStr + '</div></div><div class="time-right"><span class="time-clock">' + timeStr + '</span></div></div>';
        }
 
        // 兼容 DOM ready(Android 6 某些 WebView 可能没有 $)
        if (typeof $ !== 'undefined') {
            $(document).ready(onReady);
        } else if (document.readyState === 'complete' || document.readyState === 'interactive') {
            setTimeout(onReady, 1);
        } else {
            document.addEventListener('DOMContentLoaded', onReady);
        }
    </script>
</body>
 
</html>