-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
2013 lines (1856 loc) · 103 KB
/
Copy pathadmin.html
File metadata and controls
2013 lines (1856 loc) · 103 KB
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title data-i18n="admin.title">Scanner AI - Control Panel [UPDATED]</title>
<!-- 引入 Google Fonts: Plus Jakarta Sans -->
<!-- Removed external fonts for offline support -->
<!-- 引入 Lucide Icons -->
<script src="lucide.min.js"></script>
<style>
:root {
/* 现代企业 SaaS 调色板 (ui-ux-pro-max 推荐) */
--bg-color: #F8FAFC; /* slate-50 */
--card-bg: #FFFFFF;
--text-color: #1E293B; /* slate-800 */
--text-muted: #64748B; /* slate-500 */
--accent-color: #0D9488; /* teal-600 */
--accent-hover: #0F766E; /* teal-700 */
--success-color: #10B981; /* emerald-500 */
--danger-color: #EF4444; /* red-500 */
--ai-color: #8B5CF6; /* violet-500 */
--border-color: #E2E8F0; /* slate-200 */
--border-radius: 16px;
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
--shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
* { box-sizing: border-box; }
body {
font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
margin: 0;
padding: 30px 20px;
display: flex;
justify-content: center;
line-height: 1.5;
}
.container { max-width: 1000px; width: 100%; }
h1 {
text-align: center;
margin-bottom: 8px;
font-weight: 700;
letter-spacing: -0.5px;
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
}
.subtitle { text-align: center; color: var(--text-muted); margin-bottom: 32px; font-weight: 500;}
/* ===== Page Header · White Tech ===== */
.page-header {
position: relative;
padding: 32px 0 28px 20px;
margin-bottom: 24px;
}
/* 左侧 accent 竖条 */
.page-header::before {
content: '';
position: absolute;
left: 0;
top: 36px;
bottom: 28px;
width: 4px;
background: linear-gradient(180deg, var(--accent-color) 0%, rgba(13,148,136,0.25) 100%);
border-radius: 2px;
}
/* 底部分隔 */
.page-header::after {
content: '';
position: absolute;
left: 20px;
right: 0;
bottom: 0;
height: 1px;
background: linear-gradient(90deg, var(--accent-color) 0%, #E2E8F0 25%, #E2E8F0 100%);
}
.page-header h1 {
text-align: left;
justify-content: flex-start;
font-size: 32px;
font-weight: 700;
letter-spacing: -0.03em;
color: #0F172A;
margin: 0 0 8px 0;
}
.page-header .subtitle {
text-align: left;
margin: 0;
font-size: 15px;
color: #64748B;
font-weight: 400;
}
.lang-toggle {
background: #F8FAFC;
border: 1px solid #E2E8F0;
color: #475569;
font-size: 12px;
font-weight: 500;
cursor: pointer;
padding: 5px 14px;
border-radius: 20px;
letter-spacing: 0.02em;
transition: all 0.2s;
font-family: inherit;
}
.lang-toggle:hover {
background: #F1F5F9;
border-color: #CBD5E1;
color: #0F172A;
}
/* AI badge */
.ai-mark {
display: inline-flex;
align-items: center;
gap: 5px;
background: var(--accent-color);
color: #fff;
font-size: 11px;
font-weight: 600;
padding: 4px 12px;
border-radius: 100px;
vertical-align: middle;
margin-left: 10px;
letter-spacing: 0.05em;
box-shadow: 0 2px 12px rgba(13,148,136,0.3);
}
.ai-mark::before {
content: '';
width: 5px;
height: 5px;
background: #86EFAC;
border-radius: 50%;
box-shadow: 0 0 8px rgba(134,239,172,0.5);
}
.icon { width: 24px; height: 24px; stroke-width: 2.2px; }
.icon-sm { width: 18px; height: 18px; stroke-width: 2.2px; }
.two-column {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
}
@media (max-width: 768px) {
.two-column { grid-template-columns: 1fr; }
}
.card {
background: var(--card-bg);
border-radius: var(--border-radius);
box-shadow: var(--shadow-sm);
border: 1px solid var(--border-color);
padding: 24px;
margin-bottom: 24px;
transition: box-shadow 0.3s ease;
}
.card:hover {
box-shadow: var(--shadow);
}
.card h2 {
margin-top: 0;
padding-bottom: 12px;
margin-bottom: 20px;
font-size: 1.15em;
font-weight: 600;
display: flex;
align-items: center;
gap: 10px;
border-bottom: 1px solid var(--border-color);
color: var(--text-color);
}
.form-group {
margin-bottom: 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
label { font-weight: 600; flex: 1; font-size: 14px; color: var(--text-color); }
.label-desc { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 400;}
input[type="number"], select {
padding: 8px 12px;
border-radius: 8px;
border: 1px solid var(--border-color);
background: #fff;
font-size: 14px;
font-family: inherit;
color: var(--text-color);
width: 120px;
transition: all 0.2s;
}
input[type="number"]:focus, select:focus {
outline: none;
border-color: var(--accent-color);
box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}
input[type="range"] { width: 180px; margin: 0; cursor: pointer; accent-color: var(--accent-color); }
.range-value {
min-width: 50px;
text-align: right;
font-family: 'Plus Jakarta Sans', monospace;
font-size: 13px;
color: var(--accent-color);
font-weight: 700;
}
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
background-color: var(--border-color); transition: .3s; border-radius: 34px;
}
.slider:before {
position: absolute; content: ""; height: 18px; width: 18px;
left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
input:checked+.slider { background-color: var(--success-color); }
input:checked+.slider:before { transform: translateX(20px); }
/* ===== 按钮系统 ===== */
.btn {
display: inline-flex; justify-content: center; align-items: center; gap: 6px;
padding: 10px 18px; border-radius: 8px; font-size: 14px;
font-weight: 600; cursor: pointer; transition: all 0.2s;
border: 1px solid transparent; line-height: 1.4; white-space: nowrap;
box-shadow: var(--shadow-sm);
}
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 6px; }
.btn-lg { padding: 14px 24px; font-size: 16px; border-radius: 10px; }
.btn-primary { background: var(--accent-color); color: white; border-color: var(--accent-color); }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(13, 148, 136, 0.25); }
.btn-secondary { background: #FFFFFF; color: var(--text-color); border-color: var(--border-color); }
.btn-secondary:hover { background: #F8FAFC; border-color: #CBD5E1; color: var(--accent-color); box-shadow: 0 2px 8px rgba(13, 148, 136, 0.08); transform: translateY(-1px); }
.btn-success { background: var(--success-color); color: white; border-color: var(--success-color); }
.btn-success:hover { background: #059669; border-color: #059669; transform: translateY(-1px); }
.btn-danger { background: var(--danger-color); color: white; border-color: var(--danger-color); }
.btn-danger:hover { background: #DC2626; border-color: #DC2626; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; padding: 4px 8px; font-size: 12px; }
.btn-ghost:hover { background: #F1F5F9; color: var(--text-color); }
.btn-ghost.btn-danger { color: var(--danger-color); }
.btn-ghost.btn-danger:hover { background: #FEF2F2; }
.btn-ghost.btn-accent { color: var(--accent-color); }
.btn-ghost.btn-accent:hover { background: #F0FDFA; }
.btn-group { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; align-items: flex-start; }
.btn-group .btn { flex: 1 1 0%; }
.preview-canvas {
width: 100%; max-width: 220px; aspect-ratio: 9 / 16;
margin: 12px auto 0; border: 1px solid var(--border-color); border-radius: 12px;
background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
position: relative; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}
.roi-overlay {
position: absolute; border: 2px solid rgba(16, 185, 129, 0.9);
box-shadow: 0 0 0 2000px rgba(15, 23, 42, 0.6); border-radius: 4px;
}
#status-msg {
text-align: center; margin-top: 15px; min-height: 24px;
font-weight: 600; padding: 12px; border-radius: 8px;
font-size: 14px; transition: all 0.3s ease;
}
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 15px; }
.stat-item { background: #F8FAFC; padding: 16px; border-radius: 12px; border: 1px solid var(--border-color); text-align: center; transition: transform 0.2s ease, box-shadow 0.2s ease; }
.stat-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.06); }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; font-weight: 600;}
.stat-value { font-size: 24px; font-weight: 700; color: var(--accent-color); }
.stat-value.ai { color: var(--ai-color); }
.info-box {
background: #F0FDFA; border-left: 4px solid var(--accent-color);
padding: 14px 18px; border-radius: 8px; font-size: 13px; line-height: 1.6; margin-top: 20px;
display: flex; gap: 12px; align-items: flex-start;
}
.info-box.ai-info {
background: #F5F3FF; border-left-color: var(--ai-color);
}
.info-box i { flex-shrink: 0; stroke: currentColor; opacity: 0.7;}
.ai-badge {
display: inline-block; background: var(--ai-color); color: white;
padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600;
vertical-align: middle; margin-left: 6px;
}
.engine-tab.active {
border-color: var(--accent-color) !important;
background: #F0FDFA;
box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}
.engine-tab:hover:not(.active) {
border-color: #94a3b8;
background: #F8FAFC;
}
</style>
<script src="i18n.js?v=1"></script>
</head>
<body>
<div class="container">
<div class="page-header">
<button class="lang-toggle" id="lang-toggle" onclick="switchLang()">🇬🇧 EN</button>
<h1><span data-i18n="admin.header">Scanner AI Control Panel</span><span class="ai-mark">AI</span></h1>
<div class="subtitle" data-i18n="admin.subtitle">GLM-OCR Vision Model · Ollama Local Engine</div>
</div>
<!-- 服务器状态 -->
<div class="card">
<h2><i class="icon" data-lucide="server" style="color:var(--text-muted)"></i> <span data-i18n="admin.card.sys">System Status</span></h2>
<div class="stats-grid">
<div class="stat-item">
<div class="stat-label" data-i18n="admin.stat.server">Server</div>
<div class="stat-value" id="server-status" style="display:flex;align-items:center;justify-content:center;gap:6px;font-size:16px;">
<span style="display:inline-block;width:10px;height:10px;background:var(--success-color);border-radius:50%;box-shadow:0 0 8px rgba(16,185,129,0.5)"></span>
<span data-i18n="admin.stat.running" style="color: var(--success-color)">Running</span>
</div>
</div>
<div class="stat-item">
<div class="stat-label" data-i18n="admin.stat.engine">AI Engine</div>
<div class="stat-value ai" id="ai-engine">GLM-OCR</div>
<div id="model-status" style="font-size:11px;margin-top:6px;font-weight:600;display:flex;align-items:center;justify-content:center;gap:4px">
<span style="display:inline-block;width:8px;height:8px;background:#94a3b8;border-radius:50%"></span>
<span style="color:#94a3b8" data-i18n="admin.stat.checking">检查中...</span>
</div>
</div>
<div class="stat-item">
<div class="stat-label" data-i18n="admin.stat.fps">Scan FPS</div>
<div class="stat-value" id="scan-fps">0.7/s</div>
</div>
<div class="stat-item">
<div class="stat-label">今日扫描</div>
<div class="stat-value" id="scan-today" style="color:#2563eb">0</div>
</div>
</div>
<div class="btn-group">
<button class="btn btn-success btn-sm" onclick="openScanner()"><i class="icon-sm" data-lucide="smartphone"></i> <span data-i18n="admin.btn.open_scanner">Open Scanner</span></button>
<button class="btn btn-secondary btn-sm" onclick="openAdmin()"><i class="icon-sm" data-lucide="refresh-cw"></i> <span data-i18n="admin.btn.refresh">Refresh Panel</span></button>
<button class="btn btn-secondary btn-sm" style="color:var(--danger-color);border-color:var(--danger-color)" onclick="adminReset()"><i class="icon-sm" data-lucide="power"></i> <span data-i18n="admin.btn.reset">Reset Scanner</span></button>
</div>
</div>
<!-- 扫描统计日历 -->
<div class="card" id="scan-calendar-card">
<h2><i class="icon" data-lucide="calendar" style="color:#2563eb"></i> 扫描统计</h2>
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:12px">
<button class="btn btn-secondary btn-sm" onclick="calPrev()" style="padding:4px 12px">◀</button>
<span id="cal-month-label" style="font-weight:600;font-size:15px"></span>
<button class="btn btn-secondary btn-sm" onclick="calNext()" style="padding:4px 12px">▶</button>
</div>
<div id="cal-grid" style="display:grid;grid-template-columns:repeat(7,1fr);gap:4px;text-align:center;font-size:12px"></div>
<div style="display:flex;gap:8px;margin-top:12px;justify-content:center">
<button class="btn btn-secondary btn-sm" onclick="resetSelectedDate()" id="cal-reset-btn" style="display:none;color:var(--danger-color);border-color:var(--danger-color)">重置选中日期</button>
<button class="btn btn-secondary btn-sm" onclick="resetTodayScan()">重置今天</button>
</div>
</div>
<!-- 无线调试 & 多设备管理 -->
<div class="card" id="wifi-card">
<h2 style="display:flex;align-items:center;gap:8px"><i class="icon" data-lucide="wifi" style="color:var(--accent-color)"></i> 手机连接<span id="adb-led" style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#94a3b8;margin-left:4px;box-shadow:0 0 6px rgba(148,163,184,0.4);transition:background 0.3s"></span></h2>
<!-- 步骤引导 -->
<div style="display:flex;gap:6px;margin-bottom:16px;padding:10px 14px;background:linear-gradient(135deg,#f0fdfa,#f8fafc);border-radius:10px;font-size:12px;border:1px solid rgba(20,184,166,0.1)">
<div id="step-1" style="flex:1;text-align:center;padding:8px 4px;border-radius:8px;background:rgba(20,184,166,0.12);font-weight:600;color:var(--accent-color);transition:all 0.3s">1. 连接手机</div>
<div style="display:flex;align-items:center;color:#cbd5e1;font-size:16px">›</div>
<div id="step-2" style="flex:1;text-align:center;padding:8px 4px;border-radius:8px;color:#94a3b8;transition:all 0.3s">2. 开启无线</div>
<div style="display:flex;align-items:center;color:#cbd5e1;font-size:16px">›</div>
<div id="step-3" style="flex:1;text-align:center;padding:8px 4px;border-radius:8px;color:#94a3b8;transition:all 0.3s">3. 拔掉USB线</div>
<div style="display:flex;align-items:center;color:#cbd5e1;font-size:16px">›</div>
<div id="step-4" style="flex:1;text-align:center;padding:8px 4px;border-radius:8px;color:#94a3b8;transition:all 0.3s">4. 无线连接</div>
</div>
<!-- 设备列表 -->
<div id="device-list" style="margin-bottom:12px">
<div style="font-size:12px;color:var(--text-muted);text-align:center;padding:16px">检测设备中...</div>
</div>
<!-- 操作按钮 -->
<div style="display:flex;gap:10px;margin-bottom:14px;flex-wrap:wrap">
<button class="btn btn-secondary btn-sm" style="padding:8px 16px;font-weight:600" id="btn-adb-start-all" onclick="adbWifiStartAll()">⚡ 开启无线连接</button>
<button class="btn btn-secondary btn-sm" style="padding:8px 16px;font-weight:600" id="btn-adb-connect-all" onclick="adbWifiConnectAll()">📡 连接手机</button>
</div>
<!-- 提示文字 -->
<div id="adb-hint" style="font-size:11px;color:#64748B;line-height:1.7;padding:10px 14px;background:rgba(20,184,166,0.04);border-radius:8px;border:1px dashed rgba(20,184,166,0.2)">
<strong style="color:var(--text-main)">操作步骤:</strong>
<ol style="margin:6px 0 0 16px;padding:0;line-height:1.8">
<li>用 USB 线连接手机到电脑</li>
<li>点击「开启无线连接」按钮</li>
<li>拔掉 USB 线</li>
<li>点击「连接手机」按钮</li>
<li>在手机浏览器地址栏输入:<code style="background:rgba(0,0,0,0.06);padding:2px 6px;border-radius:4px;font-size:11px">localhost:8080</code></li>
</ol>
</div>
<!-- iOS Scanning Card -->
<div style="margin-top:16px;border:1px solid rgba(99,102,241,0.15);border-radius:10px;overflow:hidden">
<div onclick="toggleIosCard()" style="display:flex;align-items:center;justify-content:space-between;padding:12px 14px;background:linear-gradient(135deg,#eef2ff,#f5f3ff);cursor:pointer">
<div style="display:flex;align-items:center;gap:8px;font-weight:600;color:#4f46e5;font-size:13px">
<span>🍎</span> iOS 扫描 (Tailscale)
</div>
<span id="ios-chevron" style="color:#6366f1;transition:transform 0.2s">▶</span>
</div>
<div id="ios-content" style="display:none;padding:14px;font-size:12px;color:var(--text-main);line-height:1.8">
<p style="margin:0 0 10px 0">iOS Safari 只允许 HTTPS 网站调用摄像头。Tailscale 会为 Mac 自动生成私有 HTTPS 证书,让 iPhone 安全访问本服务,无需公网 IP。</p>
<div style="background:rgba(99,102,241,0.06);border:1px solid rgba(99,102,241,0.12);border-radius:8px;padding:10px 12px;margin-bottom:10px">
<div style="font-weight:600;color:#4f46e5;margin-bottom:6px">首次配置(只需一次)</div>
<ol style="margin:0 0 0 18px;padding:0">
<li>Mac 与 iPhone 分别从 App Store 安装 <a href="https://tailscale.com/download" target="_blank" style="color:#4f46e5">Tailscale</a></li>
<li>两端登录<strong>同一个账号</strong>(可用 Google/Apple/Microsoft 账号)</li>
<li>Mac 浏览器打开 <a href="https://login.tailscale.com/admin/dns" target="_blank" style="color:#4f46e5">Tailscale 管理后台</a></li>
<li>打开 <strong>HTTPS Certificates</strong> 和 <strong>MagicDNS</strong> 两个开关</li>
</ol>
</div>
<div style="background:rgba(16,185,129,0.06);border:1px solid rgba(16,185,129,0.12);border-radius:8px;padding:10px 12px;margin-bottom:10px">
<div style="font-weight:600;color:#059669;margin-bottom:6px">每次扫描前</div>
<ol style="margin:0 0 0 18px;padding:0">
<li>确认 Mac 菜单栏 Tailscale 图标显示 <strong>Connected</strong></li>
<li>Mac 终端执行以下命令建立隧道:</li>
</ol>
<div style="display:flex;align-items:center;gap:8px;margin:8px 0">
<code id="tailscale-cmd" style="flex:1;background:rgba(0,0,0,0.06);padding:6px 10px;border-radius:4px;font-family:monospace">tailscale serve --bg http://localhost:8080</code>
<button onclick="copyTailscaleCmd()" style="padding:6px 12px;border-radius:6px;border:none;background:#4f46e5;color:#fff;font-size:12px;cursor:pointer;white-space:nowrap">📋 复制</button>
</div>
<div style="margin-bottom:6px">执行成功后,在终端运行 <code style="background:rgba(0,0,0,0.06);padding:2px 6px;border-radius:4px">tailscale status</code> 查看你的设备名。</div>
<div style="background:rgba(0,0,0,0.04);padding:8px 10px;border-radius:6px">
<div style="font-weight:600;margin-bottom:4px">你的专属访问地址:</div>
<code style="background:rgba(0,0,0,0.06);padding:4px 8px;border-radius:4px;display:block">https://<设备名>.<tailnet>.ts.net</code>
<div style="margin-top:4px;color:#64748b;font-size:11px">示例:https://macbook-pro.tail4df118.ts.net</div>
</div>
</div>
<div style="background:rgba(245,158,11,0.06);border:1px solid rgba(245,158,11,0.12);border-radius:8px;padding:10px 12px;margin-bottom:10px">
<div style="font-weight:600;color:#d97706;margin-bottom:6px">iPhone 端操作</div>
<ol style="margin:0 0 0 18px;padding:0">
<li>打开 iPhone 上的 Tailscale App,确认显示 <strong>Connected</strong></li>
<li>打开 Safari,输入上面的 HTTPS 地址访问</li>
<li>首次访问会提示证书信任,点击<strong>继续</strong></li>
<li>允许摄像头权限,即可开始扫描</li>
</ol>
</div>
<div style="background:rgba(239,68,68,0.04);border:1px solid rgba(239,68,68,0.1);border-radius:8px;padding:8px 12px">
<div style="font-weight:600;color:#dc2626;margin-bottom:4px">连不上?</div>
<ul style="margin:0 0 0 18px;padding:0;color:#64748b">
<li>确保 Mac 和 iPhone 的 Tailscale 都显示 Connected</li>
<li>确保两端登录的是<strong>同一个账号</strong></li>
<li>管理后台的 HTTPS Certificates 开关必须打开</li>
<li>地址必须是 <code style="background:rgba(0,0,0,0.06);padding:1px 4px;border-radius:3px">https://</code> 开头,不是 http://</li>
</ul>
</div>
<span id="ios-copy-feedback" style="margin-left:8px;font-size:11px;color:#10b981;opacity:0;transition:opacity 0.3s">已复制!</span>
</div>
</div>
<div id="adb-result" style="display:none;margin-top:8px;padding:10px 12px;background:rgba(16,185,129,0.06);border:1px solid rgba(16,185,129,0.15);border-radius:8px">
<div style="font-size:12px;font-weight:600;color:var(--success-color);margin-bottom:4px">无线连接成功</div>
<div style="font-size:12px;color:var(--text-main)">手机浏览器访问:<span style="font-family:monospace">http://localhost:8080</span></div>
</div>
</div>
<!-- 日志查看器 -->
<div class="card" id="log-card">
<h2 style="display:flex;align-items:center;gap:8px"><i class="icon" data-lucide="file-text" style="color:var(--accent-color)"></i> 系统日志 <span style="font-size:11px;color:var(--text-muted);font-weight:400">AI 调试用</span></h2>
<button onclick="toggleLogCard()" style="font-size:11px;color:var(--text-muted);background:none;border:1px solid var(--border-color);padding:4px 12px;border-radius:6px;cursor:pointer;margin-bottom:8px">显示日志 ▾</button>
<div id="log-content" style="display:none">
<div id="log-viewer" style="font-family:monospace;font-size:11px;line-height:1.5;background:#0f172a;color:#e2e8f0;padding:12px;border-radius:8px;max-height:300px;overflow-y:auto;white-space:pre-wrap;word-break:break-all">
加载日志中...
</div>
<div style="display:flex;gap:8px;margin-top:8px">
<button class="btn btn-secondary btn-sm" onclick="refreshLogs()">刷新</button>
<button class="btn btn-secondary btn-sm" onclick="downloadLogs()">下载日志</button>
<button class="btn btn-secondary btn-sm" onclick="clearLogViewer()">清空显示</button>
</div>
</div>
</div>
<!-- OCR 引擎配置 -->
<div class="card" id="ocr-card">
<h2><i class="icon" data-lucide="brain" style="color:var(--ai-color)"></i> <span data-i18n="admin.card.ocr">OCR Engine</span> <span class="ai-badge">AI</span></h2>
<!-- 引擎选择 - 按钮式切换 -->
<div style="display:flex;gap:10px;margin-bottom:20px;flex-wrap:wrap">
<label style="flex:1;cursor:pointer;min-width:100px">
<input type="radio" name="ocr-engine" value="ollama" checked onchange="switchOcrProvider()" style="display:none"/>
<div id="engine-tab-ollama" class="engine-tab active" style="padding:14px;border-radius:12px;text-align:center;border:2px solid var(--border-color);transition:all 0.2s">
<div style="font-size:24px;margin-bottom:4px">🖥️</div>
<div style="font-weight:700;font-size:13px">Ollama</div>
<div style="font-size:11px;color:var(--text-muted);margin-top:2px">本地 · 免费 · 离线</div>
</div>
</label>
<label style="flex:1;cursor:pointer;min-width:100px">
<input type="radio" name="ocr-engine" value="baidu" onchange="switchOcrProvider()" style="display:none"/>
<div id="engine-tab-baidu" class="engine-tab" style="padding:14px;border-radius:12px;text-align:center;border:2px solid var(--border-color);transition:all 0.2s">
<div style="font-size:24px;margin-bottom:4px">☁️</div>
<div style="font-weight:700;font-size:13px">百度 OCR</div>
<div style="font-size:11px;color:var(--text-muted);margin-top:2px">云端 · 中文最强 · 有免费额度</div>
</div>
</label>
<label style="flex:1;cursor:pointer;min-width:100px">
<input type="radio" name="ocr-engine" value="ocrspace" onchange="switchOcrProvider()" style="display:none"/>
<div id="engine-tab-ocrspace" class="engine-tab" style="padding:14px;border-radius:12px;text-align:center;border:2px solid var(--border-color);transition:all 0.2s">
<div style="font-size:24px;margin-bottom:4px">🌐</div>
<div style="font-weight:700;font-size:13px">OCR.space</div>
<div style="font-size:11px;color:var(--text-muted);margin-top:2px">云端 · 免费25000次/月</div>
</div>
</label>
<label style="flex:1;cursor:pointer;min-width:100px">
<input type="radio" name="ocr-engine" value="paddle" onchange="switchOcrProvider()" style="display:none"/>
<div id="engine-tab-paddle" class="engine-tab" style="padding:14px;border-radius:12px;text-align:center;border:2px solid var(--border-color);transition:all 0.2s">
<div style="font-size:24px;margin-bottom:4px">⚡</div>
<div style="font-weight:700;font-size:13px">PaddleOCR</div>
<div style="font-size:11px;color:var(--text-muted);margin-top:2px">本地 · 极速 · 纯离线</div>
</div>
</label>
</div>
<select id="ocr-provider" style="display:none">
<option value="ollama">Ollama</option>
<option value="baidu">Baidu</option>
<option value="ocrspace">OCR.space</option>
<option value="paddle">PaddleOCR</option>
</select>
<!-- Ollama 配置 -->
<div id="ocr-ollama" class="ocr-provider-config">
<div class="form-group">
<label><span data-i18n="admin.lbl.ollama_model">Model</span><div class="label-desc">Ollama 中的视觉模型名称</div></label>
<input id="ollama-model" type="text" style="width:200px" placeholder="glm-ocr"/>
</div>
<div class="form-group">
<label><span data-i18n="admin.lbl.ollama_keepalive">Keep Alive</span><div class="label-desc">模型驻留内存时间</div></label>
<input id="ollama-keepalive" type="text" style="width:200px" placeholder="10m"/>
</div>
<div class="info-box ai-info">
<i data-lucide="shield-check"></i>
<div><strong>隐私优势:</strong>所有数据完全在本地处理,不发送任何信息到外部网络。</div>
</div>
</div>
<!-- 百度 OCR 配置 -->
<div id="ocr-baidu" class="ocr-provider-config" style="display:none">
<div class="form-group">
<label>API Key<div class="label-desc">百度智能云控制台获取</div></label>
<input id="baidu-apikey" type="password" style="width:260px" placeholder="百度云 API Key"/>
</div>
<div class="form-group">
<label>Secret Key<div class="label-desc">与 API Key 配对使用</div></label>
<input id="baidu-secretkey" type="password" style="width:260px" placeholder="百度云 Secret Key"/>
</div>
<div class="info-box">
<i data-lucide="info" style="color:var(--accent-color)"></i>
<div><strong>免费额度:</strong>通用文字识别(标准版)每月 1000 次免费。高精度版每月 50 次免费。<br/>获取密钥:<a href="https://console.bce.baidu.com/ai/#/ai/ocr/overview/index" target="_blank" style="color:var(--accent-color)">百度智能云 OCR 控制台</a></div>
</div>
</div>
<!-- OCR.space 配置 -->
<div id="ocr-ocrspace" class="ocr-provider-config" style="display:none">
<div class="form-group">
<label>API Key<div class="label-desc">OCR.space 免费注册获取</div></label>
<input id="ocrspace-apikey" type="password" style="width:260px" placeholder="OCR.space API Key"/>
</div>
<div class="form-group">
<label><span data-i18n="admin.lbl.ocrspace_lang">识别语言</span><div class="label-desc">chs = 简体中文</div></label>
<select id="ocrspace-lang" style="width:200px">
<option value="chs">简体中文 (chs)</option>
<option value="cht">繁体中文 (cht)</option>
<option value="eng">英文 (eng)</option>
</select>
</div>
<div class="info-box">
<i data-lucide="info" style="color:var(--accent-color)"></i>
<div><strong>免费额度:</strong>每月 25,000 次免费识别,无需信用卡。<br/>注册获取 API Key:<a href="https://ocr.space/ocrapi" target="_blank" style="color:var(--accent-color)">OCR.space 官网</a></div>
</div>
</div>
<!-- PaddleOCR 配置 -->
<div id="ocr-paddle" class="ocr-provider-config" style="display:none">
<div class="form-group">
<label>GPU 加速<div class="label-desc">启用 GPU 可大幅提升速度(需 CUDA 环境)</div></label>
<select id="paddle-usegpu" style="width:200px">
<option value="false">CPU(默认)</option>
<option value="true">GPU</option>
</select>
</div>
<div class="info-box ai-info">
<i data-lucide="shield-check"></i>
<div><strong>纯离线:</strong>所有识别在本地完成,无需网络,不发送任何数据到外部。</div>
</div>
</div>
<div style="margin-top:16px;display:flex;align-items:center;gap:12px">
<button class="btn btn-secondary btn-sm" onclick="testOcrConnection()"><i class="icon-sm" data-lucide="wifi"></i> <span data-i18n="admin.btn.test_ocr">Test Connection</span></button>
<div id="ocr-test-result" style="font-size:13px;font-weight:600"></div>
</div>
</div>
<!-- 数据导入 -->
<div class="card" id="import-card">
<h2><i class="icon" data-lucide="arrow-down-to-line" style="color:var(--text-muted)"></i> <span data-i18n="admin.card.import">Data Import</span></h2>
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px;margin-bottom:15px">
<a class="btn btn-secondary" href="/api/template" style="display:flex;text-decoration:none"><i class="icon-sm" data-lucide="file-down"></i> <span data-i18n="admin.btn.template">Template</span></a>
<button class="btn btn-secondary" style="display:flex" onclick="viewImportedData()"><i class="icon-sm" data-lucide="list"></i> <span data-i18n="admin.btn.view_list">View List</span></button>
<label class="btn btn-primary" style="display:flex;cursor:pointer"><i class="icon-sm" data-lucide="folder-open"></i> <span data-i18n="admin.btn.select_file">Select File</span><input accept=".xlsx,.csv" id="import-file" onchange="handleImportFile(this)" style="display:none" type="file"/></label>
</div>
<!-- 拖拽区域 -->
<div id="drop-zone" onclick="document.getElementById('import-file').click()" onmouseout="this.style.borderColor='var(--border-color)';this.style.backgroundColor='#F8FAFC'" onmouseover="this.style.borderColor='var(--accent-color)';this.style.backgroundColor='#F0FDFA'" style="border:2px dashed var(--border-color);background:#F8FAFC;border-radius:12px;padding:36px;text-align:center;color:var(--text-muted);transition:all 0.3s;cursor:pointer">
<i class="icon" data-lucide="file-spreadsheet" style="width:36px;height:36px;margin-bottom:12px;opacity:0.6"></i><br/>
<span data-i18n="admin.dz.main" style="font-weight:600">Drop Excel/CSV here, or click to select</span>
<div data-i18n="admin.dz.sub" style="font-size:13px;margin-top:6px;opacity:0.8">Supports .xlsx .csv</div>
</div>
<!-- 解析结果 -->
<div id="import-result" style="display:none;margin-top:15px">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:10px">
<strong id="import-summary"></strong>
<span id="import-mapping" style="font-size:12px;color:var(--text-muted)"></span>
</div>
<!-- 列映射 -->
<div id="column-mapping" style="display:none;margin-bottom:12px;padding:12px;background:#FEF3C7;border-radius:8px">
<div style="font-size:13px;font-weight:600;margin-bottom:8px">⚠️ 未自动识别到列,请手动选择:</div>
<div style="display:flex;gap:10px;flex-wrap:wrap">
<div style="flex:1;min-width:120px">
<label style="font-size:12px">客户名称列</label>
<select id="manual-name-col" style="width:100%"></select>
</div>
<div style="flex:1;min-width:120px">
<label style="font-size:12px">合同总额列 (可选)</label>
<select id="manual-info-col" style="width:100%"><option value="-1"><span data-i18n="msg.none">-- None --</span></option></select>
</div>
<div style="flex:1;min-width:120px">
<label style="font-size:12px">欠款金额列 (可选)</label>
<select id="manual-info2-col" style="width:100%"><option value="-1"><span data-i18n="msg.none">-- None --</span></option></select>
</div>
</div>
<button class="btn btn-secondary" onclick="reMapColumns()" style="margin-top:12px"><i class="icon-sm" data-lucide="refresh-ccw"></i> <span data-i18n="admin.btn.remap">Remap Columns</span></button>
</div>
<!-- 预览表格 -->
<div style="border:1px solid var(--border-color);border-radius:8px;overflow:hidden;margin-bottom:12px;">
<div style="overflow-x:auto;">
<table id="preview-table" style="width:100%;border-collapse:collapse;font-size:13px">
<thead id="preview-head"></thead>
<tbody id="preview-body"></tbody>
</table>
</div>
</div>
<div style="display:flex;gap:12px;margin-top:16px">
<button class="btn btn-secondary" onclick="cancelImport()" style="flex:1"><i class="icon-sm" data-lucide="x"></i> <span data-i18n="admin.btn.cancel">Cancel</span></button>
<button class="btn btn-success" onclick="confirmImport()" style="flex:1"><i class="icon-sm" data-lucide="check"></i> <span data-i18n="admin.btn.confirm">Confirm Import</span></button>
</div>
</div>
<!-- 数据查看区域 -->
<div id="view-imported-data" style="display:none;margin-top:15px"></div>
</div>
<div class="two-column">
<!-- 扫描设置 -->
<div class="card">
<h2><i class="icon" data-lucide="camera" style="color:var(--text-muted)"></i> <span data-i18n="admin.card.camera">Scanning Settings</span></h2>
<div class="form-group">
<label><span data-i18n="admin.lbl.interval">AI Scan Interval (ms)</span><div class="label-desc" data-i18n="admin.desc.interval">Recommended 1500ms+, AI needs inference time</div></label>
<input id="scan-interval" max="5000" min="500" step="100" type="number"/>
</div>
<div class="form-group">
<label><span data-i18n="admin.lbl.res">Camera Resolution</span></label>
<select id="camera-res">
<option value="640x480">VGA (640x480)</option>
<option value="1280x720">HD (1280x720)</option>
<option value="1920x1080">FHD (1920x1080)</option>
</select>
</div>
<div class="info-box ai-info">
<i data-lucide="sparkles"></i>
<div><strong data-i18n="admin.info.ai_title">AI Mode Note:</strong> <span data-i18n="admin.info.ai_desc">GLM-OCR directly interprets raw images without traditional binarization. High perf required, interval 1500ms+ is recommended.</span></div>
</div>
</div>
<!-- 匹配参数 -->
<div class="card">
<h2><i class="icon" data-lucide="target" style="color:var(--text-muted)"></i> <span data-i18n="admin.card.ai">Matching Parameters</span></h2>
<div class="form-group">
<label><span data-i18n="admin.lbl.ratio">Min Match Ratio</span><div class="label-desc" data-i18n="admin.desc.ratio">Require matching X% of target characters</div></label>
<input id="match-ratio" max="0.9" min="0.3" step="0.1" type="range"/>
<span class="range-value" id="match-ratio-val">60%</span>
</div>
<div class="form-group">
<label><span data-i18n="admin.lbl.prefix">Require Prefix Match</span><div class="label-desc" data-i18n="admin.desc.prefix">Must include the starting part of target name</div></label>
<label class="toggle-switch">
<input checked="" id="require-prefix" type="checkbox"/>
<span class="slider"></span>
</label>
</div>
<div class="form-group">
<label><span data-i18n="admin.lbl.length">Min Keyword Length</span><div class="label-desc" data-i18n="admin.desc.length">Minimum N chars to prevent misfires</div></label>
<input id="min-keyword" max="8" min="3" step="1" type="number"/>
</div>
<div class="form-group">
<label><span data-i18n="admin.lbl.distance">Levenshtein Tolerance</span><div class="label-desc" data-i18n="admin.desc.distance">Tolerance for added/missing/wrong chars</div></label>
<input id="levenshtein" max="3" min="0" step="1" type="number"/>
</div>
<div class="info-box">
<i data-lucide="lightbulb" style="color:#EAB308"></i>
<div><strong data-i18n="admin.info.tip_title">Tip:</strong> <span data-i18n="admin.info.tip_desc">With AI, typos are rare. You can increase match ratio to 70%.</span></div>
</div>
</div>
</div>
<!-- ROI区域 -->
<div class="card">
<h2><i class="icon" data-lucide="crop" style="color:var(--text-muted)"></i> <span data-i18n="admin.card.roi">Recognition ROI</span></h2>
<div class="two-column" style="gap:24px;margin-bottom:16px;">
<div>
<div class="form-group" style="margin-bottom:12px;">
<label><span data-i18n="admin.lbl.roix">ROI X</span></label>
<input id="roi-x" max="90" min="0" step="1" style="width:140px;" type="range"/>
<span class="range-value" id="roi-x-val">10%</span>
</div>
<div class="form-group" style="margin-bottom:12px;">
<label><span data-i18n="admin.lbl.roiy">ROI Y</span></label>
<input id="roi-y" max="90" min="0" step="1" style="width:140px;" type="range"/>
<span class="range-value" id="roi-y-val">38%</span>
</div>
</div>
<div>
<div class="form-group" style="margin-bottom:12px;">
<label><span data-i18n="admin.lbl.roiw">ROI Width</span></label>
<input id="roi-w" max="100" min="10" step="1" style="width:140px;" type="range"/>
<span class="range-value" id="roi-w-val">80%</span>
</div>
<div class="form-group" style="margin-bottom:12px;">
<label><span data-i18n="admin.lbl.roih">ROI Height</span></label>
<input id="roi-h" max="100" min="10" step="1" style="width:140px;" type="range"/>
<span class="range-value" id="roi-h-val">25%</span>
</div>
</div>
</div>
<div class="preview-canvas" id="roi-preview">
<div class="roi-overlay" id="roi-rect"></div>
</div>
<div style="display:flex;gap:8px;justify-content:center;margin-top:12px;flex-wrap:wrap;">
<button type="button" class="btn btn-secondary btn-sm" onclick="applyRoiPreset(5,5,90,48)">上半区</button>
<button type="button" class="btn btn-secondary btn-sm" onclick="applyRoiPreset(15,30,70,40)">中央区域</button>
<button type="button" class="btn btn-secondary btn-sm" onclick="applyRoiPreset(0,0,100,100)">全屏</button>
</div>
<div class="info-box">
<i data-lucide="scan" style="color:var(--success-color)"></i>
<div><strong data-i18n="admin.info.roi_title">Feature Note:</strong> <span data-i18n="admin.info.roi_desc">The green box is the actual cropped area sent to AI. Narrowing it speeds up OCR significantly.</span></div>
</div>
</div>
<div class="two-column">
<!-- 调试选项 -->
<div class="card">
<h2><i class="icon" data-lucide="settings-2" style="color:var(--text-muted)"></i> <span data-i18n="admin.card.debug">Debug Options</span></h2>
<div class="form-group">
<label><span data-i18n="admin.lbl.show_log">Show Debug Log</span></label>
<label class="toggle-switch">
<input id="show-debug" type="checkbox"/>
<span class="slider"></span>
</label>
</div>
<div class="form-group">
<label><span data-i18n="admin.lbl.show_overlay">Show Overlay on Phone</span></label>
<label class="toggle-switch">
<input checked="" id="show-overlay" type="checkbox"/>
<span class="slider"></span>
</label>
</div>
</div>
<!-- 关于 -->
<div class="card">
<h2><i class="icon" data-lucide="info" style="color:var(--text-muted)"></i> <span data-i18n="admin.card.about">About System</span></h2>
<div style="font-size:13px; line-height:1.8; color:var(--text-muted)">
<p style="margin:4px 0"><strong data-i18n="admin.about.ocr">OCR Engine</strong><span data-i18n="admin.about.ocr_val">GLM-OCR 0.9B (Zhipu AI Vision Model)</span></p>
<p style="margin:4px 0"><strong data-i18n="admin.about.engine">Inference Engine</strong><span data-i18n="admin.about.engine_val">Ollama (Apple Metal GPU Accel)</span></p>
<p style="margin:4px 0"><strong data-i18n="admin.about.alg">Matching Algorithm</strong><span data-i18n="admin.about.alg_val">Keyword / Prefix / Levenshtein Distance</span></p>
<p style="margin:4px 0"><strong data-i18n="admin.about.db">Built-in Data</strong><span id="target-count" style="font-weight:700;color:var(--accent-color)">--</span> <span data-i18n="admin.about.db_val">targets tracked</span></p>
</div>
</div>
</div>
<div style="display:flex;justify-content:center"><button class="btn btn-primary btn-lg" onclick="saveConfig()"><i class="icon-sm" data-lucide="save"></i> <span data-i18n="admin.btn.save">Save & Apply Config</span></button></div>
<div id="status-msg"></div>
</div>
<script>
// Initialize Lucide icons
if (typeof lucide !== 'undefined') lucide.createIcons();
var currentConfig = {};
async function openScanner() {
showStatus('📱 正在手机上打开扫描器...', 'var(--accent-color)');
try {
const res = await fetch('/api/open-on-phone', { method: 'POST' });
const data = await res.json();
if (data.status === 'success') {
showStatus('✅ 已在手机上打开扫描器', 'green');
setTimeout(() => showStatus('', ''), 3000);
} else {
throw new Error(data.message);
}
} catch (e) {
showStatus('❌ 打开失败: ' + e.message, 'red');
}
}
function openAdmin() { location.reload(); }
async function adminReset() {
if (!confirm('确定要重置扫描器吗?这将断开所有手机连接。')) return;
showStatus('🔄 正在重置扫描器...', 'var(--accent-color)');
try {
const res = await fetch('/api/admin-reset', { method: 'POST' });
const data = await res.json();
if (data.success) {
showStatus('✅ 已重置,断开了 ' + (data.disconnected || 0) + ' 个连接', 'green');
setTimeout(() => showStatus('', ''), 3000);
} else {
throw new Error('重置失败');
}
} catch (e) {
showStatus('❌ 重置失败: ' + e.message, 'red');
}
}
async function loadConfig() {
try {
const res = await fetch('/api/config?t=' + Date.now());
currentConfig = await res.json();
renderConfig();
updateStats();
// Load target count
const compRes = await fetch('/api/targets?t=' + Date.now());
const targets = await compRes.json();
document.getElementById('target-count').textContent = targets.length;
} catch (e) {
console.error('Failed to load config', e);
showStatus('⚠️ 加载配置失败', 'red');
}
}
function renderConfig() {
// Scan
document.getElementById('scan-interval').value = currentConfig.scan.interval;
const resKey = `${currentConfig.scan.width}x${currentConfig.scan.height}`;
document.getElementById('camera-res').value = resKey;
// ROI
document.getElementById('roi-x').value = currentConfig.roi.x;
document.getElementById('roi-y').value = currentConfig.roi.y;
document.getElementById('roi-w').value = currentConfig.roi.width;
document.getElementById('roi-h').value = currentConfig.roi.height;
updateRoiPreview();
// Matching
document.getElementById('match-ratio').value = currentConfig.matching.minMatchRatio || 0.6;
document.getElementById('match-ratio-val').textContent = Math.round((currentConfig.matching.minMatchRatio || 0.6) * 100) + '%';
document.getElementById('require-prefix').checked = currentConfig.matching.requirePrefix !== false;
document.getElementById('min-keyword').value = currentConfig.matching.minKeywordLength || 5;
document.getElementById('levenshtein').value = currentConfig.matching.levenshteinDistance;
// UI
document.getElementById('show-debug').checked = currentConfig.ui.showDebug;
document.getElementById('show-overlay').checked = currentConfig.ui.showOverlay;
// OCR Engine
const ocr = currentConfig.ocr || {};
const provider = ocr.provider || 'ollama';
document.getElementById('ocr-provider').value = provider;
const radioBtn = document.querySelector(`input[name="ocr-engine"][value="${provider}"]`);
if (radioBtn) radioBtn.checked = true;
const ollama = ocr.ollama || {};
document.getElementById('ollama-model').value = ollama.model || 'glm-ocr';
document.getElementById('ollama-keepalive').value = ollama.keepAlive || '10m';
const baidu = ocr.baidu || {};
document.getElementById('baidu-apikey').value = baidu.apiKey || '';
document.getElementById('baidu-secretkey').value = baidu.secretKey || '';
const ocrspace = ocr.ocrspace || {};
document.getElementById('ocrspace-apikey').value = ocrspace.apiKey || '';
document.getElementById('ocrspace-lang').value = ocrspace.language || 'chs';
const paddle = ocr.paddle || {};
document.getElementById('paddle-usegpu').value = paddle.useGpu ? 'true' : 'false';
switchOcrProvider();
}
function switchOcrProvider() {
const selected = document.querySelector('input[name="ocr-engine"]:checked').value;
document.getElementById('ocr-provider').value = selected;
document.querySelectorAll('.ocr-provider-config').forEach(el => el.style.display = 'none');
document.getElementById('ocr-' + selected).style.display = 'block';
document.querySelectorAll('.engine-tab').forEach(tab => tab.classList.remove('active'));
document.getElementById('engine-tab-' + selected).classList.add('active');
}
async function testOcrConnection() {
const resultEl = document.getElementById('ocr-test-result');
resultEl.textContent = '⏳ 保存并测试中...';
resultEl.style.color = 'var(--text-muted)';
try {
// 先保存当前 OCR 配置
const ocrCfg = {
provider: document.getElementById('ocr-provider').value,
ollama: {
baseUrl: (currentConfig.ocr && currentConfig.ocr.ollama && currentConfig.ocr.ollama.baseUrl) || 'http://localhost:11434',
model: document.getElementById('ollama-model').value || 'glm-ocr',
keepAlive: document.getElementById('ollama-keepalive').value || '10m'
},
baidu: {
apiKey: document.getElementById('baidu-apikey').value,
secretKey: document.getElementById('baidu-secretkey').value
},
ocrspace: {
apiKey: document.getElementById('ocrspace-apikey').value,
language: document.getElementById('ocrspace-lang').value
},
paddle: {
useGpu: document.getElementById('paddle-usegpu').value === 'true'
}
};
currentConfig.ocr = ocrCfg;
await fetch('/api/config', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(currentConfig)
});
// 再测试连接
const res = await fetch('/api/ocr-test', { method: 'POST' });
const data = await res.json();
if (data.ok) {
resultEl.textContent = '✅ ' + data.message;
resultEl.style.color = 'var(--success-color)';
} else {
resultEl.textContent = '❌ ' + (data.message || data.detail || '连接失败');
resultEl.style.color = 'var(--danger-color)';
}
} catch (e) {
resultEl.textContent = '❌ 请求失败: ' + e.message;
resultEl.style.color = 'var(--danger-color)';
}
}
function updateRoiPreview() {
const x = parseFloat(document.getElementById('roi-x').value);
const y = parseFloat(document.getElementById('roi-y').value);
const w = parseFloat(document.getElementById('roi-w').value);
const h = parseFloat(document.getElementById('roi-h').value);
document.getElementById('roi-x-val').innerText = x + '%';
document.getElementById('roi-y-val').innerText = y + '%';
document.getElementById('roi-w-val').innerText = w + '%';
document.getElementById('roi-h-val').innerText = h + '%';
const rect = document.getElementById('roi-rect');
rect.style.left = x + '%';
rect.style.top = y + '%';
rect.style.width = w + '%';
rect.style.height = h + '%';
const overflow = (x + w > 100) || (y + h > 100);
rect.style.borderColor = overflow ? 'var(--danger-color)' : 'rgba(16, 185, 129, 0.9)';
rect.style.boxShadow = overflow
? '0 0 0 2000px rgba(239, 68, 68, 0.15)'
: '0 0 0 2000px rgba(15, 23, 42, 0.6)';
}
function applyRoiPreset(x, y, w, h) {
document.getElementById('roi-x').value = x;
document.getElementById('roi-y').value = y;
document.getElementById('roi-w').value = w;
document.getElementById('roi-h').value = h;
updateRoiPreview();
}
function updateMatchRatioLabel() {
const val = document.getElementById('match-ratio').value;
document.getElementById('match-ratio-val').textContent = Math.round(val * 100) + '%';
}
function updateStats() {
const interval = document.getElementById('scan-interval').value;
const fps = (1000 / interval).toFixed(1);
document.getElementById('scan-fps').textContent = fps + '/s';
}
function updateCalendarDayCount(dateStr, count) {
const el = document.querySelector('[data-cal-date="' + dateStr + '"]');
if (!el) return;
const cnt = el.querySelector('.cal-count');
if (!cnt) return;
cnt.textContent = count + ' 次';