-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1643 lines (1589 loc) · 74.1 KB
/
Copy pathindex.html
File metadata and controls
1643 lines (1589 loc) · 74.1 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 name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenCode · Usage Console</title>
<link rel="icon" type="image/svg+xml" href="opencode-icon.svg">
<!-- SheetJS: 解析 Excel -->
<script src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
<!-- Chart.js: 柱状图 -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
<!-- JetBrains Mono: 数字/英文 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/jetbrains-mono@5.0.20/400.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/jetbrains-mono@5.0.20/600.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/jetbrains-mono@5.0.20/700.css">
<style>
:root {
--bg: #080b10;
--bg-soft: #0d1220;
--card: rgba(17, 24, 38, .72);
--card-solid: #101725;
--border: rgba(148, 163, 184, .14);
--border-strong: rgba(148, 163, 184, .28);
--text: #e6edf6;
--text-dim: #8ea0b8;
--text-faint: #5b6b83;
--accent: #22d3ee;
--accent-2: #818cf8;
--green: #2dd4a7;
--amber: #f5b04c;
--slate: #6d83a5;
--tooltip-bg: rgba(13, 19, 32, .98);
--input-bg: rgba(8, 12, 20, .8);
--seg-bg: rgba(8, 12, 20, .8);
--option-bg: #0d1220;
--chart-grid: rgba(148, 163, 184, .08);
--chart-border: rgba(148, 163, 184, .15);
--chart-tick: rgba(160, 175, 195, .75);
--chart-tick-sub: rgba(160, 175, 195, .6);
--value-grad-from: #f0f7ff;
--mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
--sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
--radius: 14px;
}
[data-theme="light"] {
--bg: #eef2f8;
--bg-soft: #e4eaf3;
--card: rgba(255, 255, 255, .86);
--card-solid: #ffffff;
--border: rgba(18, 36, 66, .12);
--border-strong: rgba(18, 36, 66, .26);
--text: #16233a;
--text-dim: #3e5170;
--text-faint: #5d6b85;
--accent: #0891b2;
--accent-2: #6366f1;
--green: #0d9b7e;
--amber: #b07a10;
--slate: #64748b;
--tooltip-bg: rgba(255, 255, 255, .98);
--input-bg: rgba(255, 255, 255, .9);
--seg-bg: rgba(226, 233, 244, .9);
--option-bg: #ffffff;
--chart-grid: rgba(18, 36, 66, .08);
--chart-border: rgba(18, 36, 66, .16);
--chart-tick: rgba(40, 60, 90, .8);
--chart-tick-sub: rgba(40, 60, 90, .6);
--value-grad-from: #1e2a44;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }
body {
font-family: var(--sans);
background: var(--bg);
color: var(--text);
min-height: 100vh;
overflow-x: hidden;
}
body::before {
content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
background:
radial-gradient(52% 42% at 18% -6%, rgba(34, 211, 238, .10), transparent 62%),
radial-gradient(40% 34% at 88% -4%, rgba(129, 140, 248, .09), transparent 60%),
radial-gradient(70% 60% at 50% 120%, rgba(45, 212, 167, .05), transparent 65%);
}
body::after {
content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
background-image:
linear-gradient(rgba(148, 163, 184, .05) 1px, transparent 1px),
linear-gradient(90deg, rgba(148, 163, 184, .05) 1px, transparent 1px);
background-size: 46px 46px;
mask-image: radial-gradient(80% 70% at 50% 0%, #000 30%, transparent 100%);
-webkit-mask-image: radial-gradient(80% 70% at 50% 0%, #000 30%, transparent 100%);
}
.container { max-width: 1220px; margin: 0 auto; padding: 34px 22px 70px; }
/* ===== Header ===== */
header.top {
display: flex; align-items: center; justify-content: space-between;
flex-wrap: wrap; gap: 16px; margin-bottom: 30px;
animation: fadeUp .55s ease both;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
width: 44px; height: 44px; border-radius: 12px;
display: grid; place-items: center;
background: linear-gradient(145deg, rgba(34, 211, 238, .16), rgba(129, 140, 248, .10));
border: 1px solid rgba(34, 211, 238, .35);
box-shadow: 0 0 22px rgba(34, 211, 238, .18), inset 0 0 12px rgba(34, 211, 238, .06);
}
.logo svg { width: 22px; height: 22px; stroke: var(--accent); }
.brand h1 {
font-family: var(--mono); font-size: 19px; font-weight: 700; letter-spacing: .5px;
line-height: 1.15;
}
.brand h1 span { color: var(--accent); }
.brand .tagline {
font-family: var(--mono); font-size: 11px; color: var(--text-faint);
letter-spacing: 2.4px; text-transform: uppercase; margin-top: 3px;
}
.header-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.update-btn {
font-family: var(--mono); font-size: 12px; font-weight: 600;
color: var(--accent); background: rgba(34, 211, 238, .08);
border: 1px solid rgba(34, 211, 238, .4); border-radius: 999px;
padding: 8px 16px; cursor: pointer; letter-spacing: .5px;
display: inline-flex; align-items: center; gap: 8px;
transition: all .2s;
}
.update-btn .up-ico { display: inline-flex; font-size: 14px; line-height: 1; }
.update-btn.loading .up-ico { animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.update-btn:hover:not(:disabled) { background: rgba(34, 211, 238, .18); box-shadow: 0 0 16px rgba(34, 211, 238, .2); }
.update-btn:active:not(:disabled) { transform: scale(.97); }
.update-btn:disabled { opacity: .55; cursor: wait; }
.icon-btn {
width: 38px; height: 38px; border-radius: 999px; cursor: pointer;
display: grid; place-items: center; font-size: 16px;
background: var(--card); border: 1px solid var(--border); color: var(--text-dim);
backdrop-filter: blur(8px); transition: all .2s;
}
.icon-btn:hover { color: var(--accent); border-color: rgba(34, 211, 238, .45); box-shadow: 0 0 14px rgba(34, 211, 238, .18); transform: rotate(30deg); }
.file-chip {
font-family: var(--mono); font-size: 12px; color: var(--text-dim);
background: var(--card); border: 1px solid var(--border);
border-radius: 999px; padding: 8px 16px;
display: inline-flex; align-items: center; gap: 8px;
max-width: 400px; overflow: hidden; white-space: nowrap;
backdrop-filter: blur(8px);
}
.file-chip .fc-name { overflow: hidden; text-overflow: ellipsis; }
.file-chip .fc-count { color: var(--accent); font-weight: 700; flex-shrink: 0; }
.file-chip::before {
content: ""; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
background: var(--text-faint);
}
.file-chip.loaded::before { background: var(--green); box-shadow: 0 0 8px rgba(45, 212, 167, .7); }
.file-chip.loaded { color: var(--text); border-color: rgba(45, 212, 167, .35); }
.up-status {
font-family: var(--mono); font-size: 11.5px; color: var(--text-dim);
max-width: 320px; line-height: 1.5; min-height: 17px;
display: inline-flex; align-items: center; gap: 7px;
transition: color .2s;
}
.up-status .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.up-status.err { color: #e5484d; }
.up-status.ok { color: var(--green); }
/* ===== Upload ===== */
.upload {
position: relative; border-radius: 18px; text-align: center;
padding: 64px 28px 58px; margin-bottom: 26px;
background: linear-gradient(160deg, rgba(20, 28, 46, .6), rgba(10, 14, 24, .8));
border: 1.5px dashed var(--border-strong);
backdrop-filter: blur(10px);
cursor: pointer;
transition: border-color .25s, box-shadow .25s, transform .25s;
animation: fadeUp .55s .08s ease both;
}
[data-theme="light"] .upload { background: linear-gradient(160deg, rgba(255,255,255,.9), rgba(240,244,250,.95)); }
.upload:hover, .upload.drag {
border-color: var(--accent);
box-shadow: 0 0 0 1px rgba(34, 211, 238, .25), 0 0 44px rgba(34, 211, 238, .12), inset 0 0 30px rgba(34, 211, 238, .03);
}
.upload .chart-icon { display: inline-block; margin-bottom: 18px; }
.upload .chart-icon svg { width: 58px; height: 58px; }
.upload .chart-icon .bar { fill: url(#gradBar); animation: barRise .9s .2s ease both; }
.upload .chart-icon .bar2 { animation-delay: .34s; }
.upload .chart-icon .bar3 { animation-delay: .48s; }
.upload .chart-icon .bar4 { animation-delay: .62s; }
@keyframes barRise { from { transform: scaleY(0); transform-origin: bottom; } to { transform: scaleY(1); transform-origin: bottom; } }
.upload h2 { font-size: 17px; font-weight: 600; color: var(--text); letter-spacing: .2px; }
.upload p { font-size: 13px; color: var(--text-dim); margin-top: 8px; }
.upload .or { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin: 16px 0 14px; letter-spacing: 1px; }
.upload .btn {
font-family: var(--mono); font-size: 13px; font-weight: 600;
color: #04121a; background: linear-gradient(135deg, #67e8f9, #22d3ee);
border: none; border-radius: 10px; padding: 11px 26px; cursor: pointer;
box-shadow: 0 4px 18px rgba(34, 211, 238, .3);
transition: transform .15s, box-shadow .2s, filter .2s;
}
.upload .btn:hover { transform: translateY(-1px); box-shadow: 0 6px 26px rgba(34, 211, 238, .42); filter: brightness(1.06); }
.upload .btn:active { transform: translateY(0); }
.upload input[type=file] { display: none; }
.upload .drop-hint {
position: absolute; top: 14px; right: 16px;
font-family: var(--mono); font-size: 10px; letter-spacing: 1.5px;
color: var(--text-faint); text-transform: uppercase;
border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px;
}
/* ===== Stats ===== */
#statsArea { display: none; }
.stats-grid {
display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
gap: 16px; margin-bottom: 20px;
}
.stat-card {
position: relative;
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
padding: 20px 20px 18px; backdrop-filter: blur(8px);
animation: fadeUp .5s ease both;
}
.stat-card:nth-child(1) { animation-delay: .10s; }
.stat-card:nth-child(2) { animation-delay: .16s; }
.stat-card:nth-child(3) { animation-delay: .22s; }
.stat-card:nth-child(4) { animation-delay: .28s; }
.stat-card::before {
content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
background: var(--bar, var(--accent));
opacity: .85; box-shadow: 0 0 14px var(--bar, var(--accent));
}
.stat-card .label {
font-family: var(--mono); font-size: 11px; letter-spacing: 1.6px;
text-transform: uppercase; color: var(--text-faint); display: flex; align-items: center; gap: 7px;
}
.stat-card .label svg { width: 13px; height: 13px; stroke: var(--bar, var(--accent)); }
.stat-card .value {
font-family: var(--mono); font-size: 30px; font-weight: 700; margin-top: 10px;
letter-spacing: -.5px;
background: linear-gradient(135deg, var(--value-grad-from), var(--bar, var(--accent)));
-webkit-background-clip: text; background-clip: text; color: transparent;
}
.stat-card .sub { font-size: 12px; color: var(--text-faint); margin-top: 7px; font-family: var(--mono); word-spacing: -2px; }
.stat-card:hover { transform: translateY(-2px); border-color: var(--border-strong); z-index: 30; }
.stat-card { transition: transform .2s, border-color .2s; }
.stat-tooltip {
position: absolute; top: calc(100% + 10px); left: 0; width: 252px;
background: var(--tooltip-bg); border: 1px solid var(--border-strong);
border-radius: 10px; padding: 13px 15px; z-index: 40;
box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
font-family: var(--mono); font-size: 12px;
opacity: 0; visibility: hidden; transform: translateY(-5px);
transition: opacity .18s, transform .18s, visibility .18s;
pointer-events: none;
}
.stat-card:hover .stat-tooltip { opacity: 1; visibility: visible; transform: none; }
.stat-tooltip .tt-head {
font-size: 10.5px; letter-spacing: 1.4px; text-transform: uppercase;
color: var(--accent); margin-bottom: 8px; padding-bottom: 8px;
border-bottom: 1px solid var(--border);
}
.stat-tooltip .tt-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.stat-tooltip .tt-row span { color: var(--text-dim); }
.stat-tooltip .tt-row b { color: var(--text); font-weight: 600; }
.stat-tooltip .tt-total { margin-top: 5px; padding-top: 8px; border-top: 1px solid var(--border); }
.stat-tooltip .tt-total span { color: var(--text); }
.stat-tooltip .tt-total b { color: var(--accent); font-size: 13px; }
/* ===== Control bar ===== */
.control-bar {
max-width: 940px; margin: 0 auto 20px;
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
padding: 14px 18px; backdrop-filter: blur(8px);
animation: fadeUp .5s .3s ease both;
}
.control-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px 26px;
}
.ctrl { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.ctrl-label {
font-family: var(--mono); font-size: 11px; letter-spacing: 1.4px;
text-transform: uppercase; color: var(--text-faint);
}
.seg { display: inline-flex; background: var(--seg-bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg button {
font-family: var(--mono); font-size: 12px; font-weight: 600;
border: none; background: transparent; color: var(--text-dim);
padding: 7px 12px; border-radius: 7px; cursor: pointer;
transition: all .18s; letter-spacing: .3px;
}
.seg button:hover { color: var(--text); }
.seg button.active {
color: #062a33; background: linear-gradient(135deg, #67e8f9, #38d3ec);
box-shadow: 0 2px 10px rgba(34, 211, 238, .35);
}
.model-select {
background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px;
color: var(--text); font-family: var(--mono); font-size: 12px;
padding: 7px 10px; max-width: 220px; transition: border-color .2s, box-shadow .2s;
}
.model-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
.model-select option { background: var(--option-bg); color: var(--text); }
.ctrl .range-inputs { display: flex; align-items: center; gap: 8px; }
.range-inputs input[type="datetime-local"] {
background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px;
color: var(--text); font-family: var(--mono); font-size: 12px;
padding: 7px 10px; width: 176px; transition: border-color .2s, box-shadow .2s;
}
.range-inputs input[type="datetime-local"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
.range-inputs .sep { color: var(--text-faint); font-family: var(--mono); }
.range-reset {
font-family: var(--mono); font-size: 11px; font-weight: 600;
color: var(--text-dim); background: transparent; border: 1px solid var(--border);
border-radius: 8px; padding: 7px 12px; cursor: pointer; letter-spacing: .5px;
transition: all .18s; white-space: nowrap;
}
.range-reset:hover { color: var(--accent); border-color: rgba(34, 211, 238, .45); }
/* ===== Chart ===== */
.chart-card {
max-width: 940px; margin: 0 auto;
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
padding: 22px 22px 18px; backdrop-filter: blur(8px);
animation: fadeUp .5s .36s ease both;
}
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.chart-head h3 { font-family: var(--mono); font-size: 15px; font-weight: 600; letter-spacing: .3px; }
.chart-head h3::before { content: "▸ "; color: var(--accent); }
.chart-head p { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-top: 5px; letter-spacing: .5px; }
.hitrate-toggle {
display: inline-flex; align-items: center; gap: 8px;
font-family: var(--mono); font-size: 12px; color: var(--text-dim);
cursor: pointer; user-select: none;
background: var(--card); border: 1px solid var(--border);
border-radius: 999px; padding: 6px 12px; flex-shrink: 0;
transition: border-color .2s, color .2s;
}
.hitrate-toggle:hover { border-color: rgba(34, 211, 238, .45); color: var(--text); }
.hitrate-toggle input { width: 14px; height: 14px; cursor: pointer; accent-color: var(--accent); }
.chart-wrap { position: relative; height: 460px; }
.empty-tip {
display: none; position: absolute; inset: 0;
place-items: center; text-align: center; color: var(--text-faint);
font-family: var(--mono);
}
.empty-tip .big { font-size: 40px; margin-bottom: 10px; opacity: .6; }
.legend-note {
margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
font-family: var(--mono); font-size: 11.5px; color: var(--text-dim);
display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
}
.legend-note .item { display: inline-flex; align-items: center; gap: 7px; }
.legend-note .swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; box-shadow: 0 0 8px rgba(255,255,255,.08); }
footer.hint {
margin-top: 26px; text-align: center;
font-family: var(--mono); font-size: 11px; line-height: 1.9; color: var(--text-faint);
animation: fadeUp .5s .42s ease both;
}
footer.hint b { color: var(--text-dim); font-weight: 600; }
/* ===== Settings Modal ===== */
.modal-mask {
position: fixed; inset: 0; z-index: 100;
background: rgba(4, 7, 12, .62); backdrop-filter: blur(6px);
display: none; place-items: center; padding: 20px;
}
.modal-mask.open { display: grid; }
.modal {
width: 560px; max-width: 100%; max-height: 90vh; overflow-y: auto;
background: var(--card-solid); border: 1px solid var(--border-strong); border-radius: 18px;
box-shadow: 0 30px 80px rgba(0, 0, 0, .5), 0 0 0 1px rgba(34, 211, 238, .06);
animation: modalIn .22s ease both;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head {
display: flex; align-items: center; justify-content: space-between;
padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-family: var(--mono); font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.modal-head h3::before { content: "⚙ "; color: var(--accent); }
.modal-close {
width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
background: transparent; border: 1px solid var(--border); color: var(--text-dim);
font-size: 14px; transition: all .18s;
}
.modal-close:hover { color: var(--text); border-color: var(--border-strong); background: var(--seg-bg); }
.modal-body { padding: 8px 22px 6px; }
.sec { padding: 14px 0; border-bottom: 1px solid var(--border); }
.sec:last-child { border-bottom: none; }
.sec-title {
font-family: var(--mono); font-size: 11px; letter-spacing: 1.6px;
text-transform: uppercase; color: var(--text-faint); margin-bottom: 10px;
}
.set-fields { display: flex; align-items: center; gap: 12px 16px; margin-top: 12px; flex-wrap: wrap; }
.field-group { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.field-group label {
font-family: var(--mono); font-size: 12px; color: var(--text-dim);
}
.field-group input {
background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px;
color: var(--text); font-family: var(--mono); font-size: 12px;
padding: 8px 11px; width: 180px; transition: border-color .2s, box-shadow .2s;
}
.field-group input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
.field-group input::placeholder { color: var(--text-faint); }
.set-fields .hint { width: 100%; font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.field-group input[type="number"] { width: 96px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.set-desc { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
position: absolute; inset: 0; border-radius: 999px; cursor: pointer;
background: var(--seg-bg); border: 1px solid var(--border);
transition: background .25s, border-color .25s;
}
.switch .slider::before {
content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px;
background: var(--text-faint); border-radius: 50%;
transition: transform .25s, background .25s;
}
.switch input:checked + .slider { background: rgba(34, 211, 238, .22); border-color: rgba(34, 211, 238, .55); }
.switch input:checked + .slider::before { transform: translateX(20px); background: var(--accent); box-shadow: 0 0 10px rgba(34, 211, 238, .5); }
.modal-foot {
display: flex; justify-content: flex-end; gap: 12px;
padding: 16px 22px 20px; border-top: 1px solid var(--border);
}
.btn-ghost {
font-family: var(--mono); font-size: 12px; font-weight: 600;
color: var(--text-dim); background: transparent; border: 1px solid var(--border);
border-radius: 9px; padding: 9px 20px; cursor: pointer; transition: all .18s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn-primary {
font-family: var(--mono); font-size: 12px; font-weight: 700;
color: #062a33; background: linear-gradient(135deg, #67e8f9, #38d3ec);
border: none; border-radius: 9px; padding: 9px 24px; cursor: pointer;
box-shadow: 0 3px 14px rgba(34, 211, 238, .3); transition: all .18s;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary:active { transform: none; }
@keyframes fadeUp {
from { opacity: 0; transform: translateY(16px); }
to { opacity: 1; transform: none; }
}
@media (max-width: 680px) {
.chart-wrap { height: 380px; }
.control-bar { gap: 12px 20px; }
.upload { padding: 46px 18px 42px; }
}
</style>
</head>
<body>
<div class="container">
<header class="top">
<div class="brand">
<div class="logo">
<svg viewBox="0 0 24 24" fill="none" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 3v18h18"/><path d="M7 15l4-6 4 3 5-7"/>
</svg>
</div>
<div>
<h1>OPENCODE<span>USAGE</span></h1>
<div class="tagline">Usage · Console</div>
</div>
</div>
<div class="header-right">
<button class="update-btn" id="btnUpdate" title="⟳ update"><span class="up-ico">⟳</span><span data-i18n="update">更新数据</span></button>
<span class="up-status" id="upStatus"><span class="dot" style="display:none"></span><span id="upStatusText"></span></span>
<div class="file-chip" id="fileInfo"><span class="fc-name">NO DATA LOADED</span><span class="fc-count"></span></div>
<button class="icon-btn" id="btnSettings" title="⚙ settings">⚙</button>
</div>
</header>
<section class="upload" id="uploadCard" onclick="document.getElementById('fileInput').click()">
<span class="drop-hint" data-i18n="dropFile">drop file</span>
<div class="chart-icon">
<svg viewBox="0 0 64 64" fill="none">
<defs>
<linearGradient id="gradBar" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color="#67e8f9"/><stop offset="1" stop-color="#22d3ee"/>
</linearGradient>
</defs>
<rect class="bar" x="6" y="32" width="10" height="24" rx="3" fill="url(#gradBar)" opacity=".85"/>
<rect class="bar bar2" x="20" y="20" width="10" height="36" rx="3" fill="url(#gradBar)" opacity=".95"/>
<rect class="bar bar3" x="34" y="10" width="10" height="46" rx="3" fill="url(#gradBar)"/>
<rect class="bar bar4" x="48" y="26" width="10" height="30" rx="3" fill="url(#gradBar)" opacity=".9"/>
<line x1="4" y1="60" x2="60" y2="60" stroke="#22d3ee" stroke-opacity=".3" stroke-width="1.5"/>
</svg>
</div>
<h2 id="uploadTitle" data-i18n="loadingTitle">正在从本地服务自动加载数据…</h2>
<p><span data-i18n="loadingHint">若长时间无响应,请先启动服务:</span><b style="color:var(--text)">python opencode_usage.py</b></p>
<div class="or">— OR —</div>
<button class="btn" onclick="event.stopPropagation();document.getElementById('fileInput').click()" data-i18n="chooseFile">选择 Excel 文件</button>
<input type="file" id="fileInput" accept=".xlsx,.xls">
</section>
<div id="statsArea">
<div class="stats-grid" id="statsGrid"></div>
<div class="control-bar">
<div class="control-row">
<div class="ctrl">
<span class="ctrl-label" data-i18n="model">模型</span>
<select class="model-select" id="selModel">
<option value="all" data-i18n="allModels">所有模型</option>
</select>
</div>
<div class="ctrl">
<span class="ctrl-label" data-i18n="metric">统计方式</span>
<div class="seg" id="segMetric">
<button data-metric="token" class="active" data-i18n="token">Token</button>
<button data-metric="cost" data-i18n="cost">金额</button>
</div>
</div>
<div class="ctrl">
<span class="ctrl-label" data-i18n="gran">时间粒度</span>
<div class="seg" id="segGranularity">
<button data-gran="month" data-i18n="gMonth">按月</button>
<button data-gran="week" data-i18n="gWeek">按周</button>
<button data-gran="day" class="active" data-i18n="gDay">按天</button>
<button data-gran="hour" data-i18n="gHour">按小时</button>
<button data-gran="minute" data-i18n="gMinute">按分钟</button>
</div>
</div>
<div class="ctrl">
<span class="ctrl-label" data-i18n="range">时间范围</span>
<div class="range-inputs">
<input type="datetime-local" id="rangeStart">
<span class="sep">—</span>
<input type="datetime-local" id="rangeEnd">
</div>
<button class="range-reset" id="rangeReset">↺ <span data-i18n="reset">默认</span></button>
</div>
</div>
</div>
<div class="chart-card">
<div class="chart-head">
<div>
<h3 id="chartTitle"></h3>
<p id="chartSub"></p>
</div>
<label class="hitrate-toggle" id="hitrateWrap" style="display:none">
<span data-i18n="hitrateToggle">缓存命中率</span>
<input type="checkbox" id="hitrateToggle">
</label>
</div>
<div class="chart-wrap">
<canvas id="chart"></canvas>
<div class="empty-tip" id="emptyTip">
<div><div class="big">▤</div><div data-i18n="noData">请先选择 Excel 文件</div></div>
</div>
</div>
<div class="legend-note" id="legendNote"></div>
</div>
</div>
<footer class="hint">
<span data-i18n="footerSrc">数据来源</span> <b>opencode_usage_history.xlsx</b> · <span data-i18n="footerTokenNote">Token 图每根柱按</span> <b data-i18n="legendCache">缓存读取</b> → <b data-i18n="legendInput">输入</b> → <b data-i18n="legendOutput">输出</b> → <b data-i18n="legendReasoning">推理</b> <span data-i18n="footerStackNote">堆叠,悬停查看总 Token</span><br>
<span data-i18n="footerGen">生成于</span> <b>scrape_usage.py</b> + <b>opencode_usage.py</b> · <span data-i18n="footerStack">Powered by SheetJS & Chart.js</span>
</footer>
</div>
<!-- ===== 设置弹窗 ===== -->
<div class="modal-mask" id="settingsModal">
<div class="modal">
<div class="modal-head">
<h3 data-i18n="setTitle">设置</h3>
<button class="modal-close" id="settingsClose">✕</button>
</div>
<div class="modal-body">
<div class="sec">
<div class="sec-title" data-i18n="setLang">语言</div>
<div class="seg" id="setLang">
<button data-lang="zh" class="active">中文</button>
<button data-lang="en">English</button>
</div>
</div>
<div class="sec">
<div class="sec-title" data-i18n="setTheme">主题</div>
<div class="seg" id="setTheme">
<button data-theme-opt="system" class="active" data-i18n="themeSystem">跟随系统</button>
<button data-theme-opt="dark" data-i18n="themeDark">深色</button>
<button data-theme-opt="light" data-i18n="themeLight">亮色</button>
</div>
</div>
<div class="sec">
<div class="sec-title" data-i18n="setLogin">登录</div>
<div class="seg" id="setLoginMethod">
<button data-method="github" class="active">GitHub</button>
<button data-method="google">Google</button>
</div>
<div class="set-fields">
<div class="field-group">
<label data-i18n="setAccount">账号</label>
<input type="text" id="setEmail" data-placeholder="accountHint" placeholder="请输入账号">
</div>
<div class="field-group">
<label data-i18n="setPassword">密码</label>
<input type="password" id="setPassword" data-placeholder="pwdHint" placeholder="留空用缓存登录态">
</div>
</div>
<div class="set-fields">
<div class="field-group">
<label data-i18n="setWorkspace">工作区</label>
<input type="text" id="setWorkspace" data-placeholder="wsHint" placeholder="留空自动获取">
</div>
</div>
</div>
<div class="sec">
<div class="sec-title" data-i18n="setTimeRange">更新时间段</div>
<div class="seg" id="setTimeMode">
<button data-mode="all" class="active" data-i18n="timeAll">全部数据</button>
<button data-mode="range" data-i18n="timeSpec">指定时间段</button>
<button data-mode="period" data-i18n="timePeriod">固定周期</button>
</div>
<div class="set-fields" id="rangeFields" style="display:none">
<div class="field-group">
<label data-i18n="timeStart">开始</label>
<input type="date" id="setStart">
</div>
<div class="field-group">
<label data-i18n="timeEnd">结束</label>
<input type="date" id="setEnd">
</div>
<div class="hint" data-i18n="fmtHint">请选择下载的起始与结束日期</div>
</div>
<div class="set-fields" id="periodFields" style="display:none">
<div class="seg" id="setPeriod">
<button data-months="1" class="active" data-i18n="period1">1 个月</button>
<button data-months="3" data-i18n="period3">3 个月</button>
<button data-months="6" data-i18n="period6">6 个月</button>
<button data-months="12" data-i18n="period12">1 年</button>
</div>
</div>
</div>
<div class="sec">
<div class="sec-title" data-i18n="setUpdateMode">更新方式</div>
<div class="set-row">
<span class="set-desc" data-i18n="incrementalDesc">仅更新 Excel 最新记录之后的新数据</span>
<label class="switch">
<input type="checkbox" id="setIncremental">
<span class="slider"></span>
</label>
</div>
</div>
<div class="sec">
<div class="sec-title" data-i18n="autoFetch">自动更新</div>
<div class="set-row">
<span class="set-desc" data-i18n="autoFetchDesc">定时更新</span>
<label class="switch">
<input type="checkbox" id="setAutoFetch">
<span class="slider"></span>
</label>
</div>
<div class="set-fields" id="autoFetchFields" style="display:none">
<div class="field-group">
<label data-i18n="interval">更新时间</label>
<input type="number" id="setInterval" min="1" max="999" value="30">
<div class="seg" id="setUnit">
<button data-unit="min" class="active" data-i18n="unitMin">分钟</button>
<button data-unit="hour" data-i18n="unitHour">小时</button>
<button data-unit="day" data-i18n="unitDay">天</button>
</div>
</div>
</div>
</div>
</div>
<div class="modal-foot">
<button class="btn-ghost" id="settingsCancel" data-i18n="cancel">取消</button>
<button class="btn-primary" id="settingsSave" data-i18n="save">保存</button>
</div>
</div>
</div>
<script>
// ============ 国际化 ============
const I18N = {
zh: {
update: '更新数据', settings: '设置', updating: '更新中…',
loadingTitle: '正在从本地服务自动加载数据…',
loadingHint: '若长时间无响应,请先启动服务:',
chooseFile: '选择 Excel 文件', dropFile: 'drop file',
loadFailTitle: '未能自动连接本地服务,可手动选择 Excel 文件',
model: '模型', allModels: '所有模型',
metric: '统计方式', token: 'Token', cost: '金额',
gran: '时间粒度', gMonth: '按月', gWeek: '按周', gDay: '按天', gHour: '按小时', gMinute: '按分钟',
range: '时间范围', reset: '默认',
noData: '请先选择 Excel 文件', noDataInGran: '该粒度下没有可聚合的数据',
recordCount: 'Record Count', recordCountSub: 'API 调用次数',
totalToken: 'Total Token', totalTokenSub: '缓存 + 输入 + 输出 + 推理',
totalCost: 'Total Cost', totalCostSub: '≈ ',
timeRange: 'Time Range', timeRangeNotSet: '未设置范围',
ttHead: '当前范围 · Token 明细',
ttCache: '缓存读取', ttInput: '输入', ttOutput: '输出', ttReasoning: '推理',
ttTotal: '总 Token', ttCost: '总成本', ttRecords: '记录数', ttHitRate: '缓存命中率', hitrateToggle: '缓存命中率', hitrateLine: '缓存命中率', hitrateAxis: '缓存命中率 (%)',
chartTokenTitle: 'Token 使用量', chartCostTitle: '成本 · USD',
chartBy: '按', chartStat: '统计',
legendCache: '缓存读取', legendInput: '输入', legendOutput: '输出', legendReasoning: '推理',
legendCost: '成本(美元)', barHeightNote: '柱高 = 总 Token(四段之和)',
groups: 'GROUPS', records: 'RECORDS',
updateConnecting: '正在连接本地服务…',
updateSuccess: '更新成功', updateFail: '更新失败', rowsSuffix: '条记录',
serverHint: '请先启动本地服务:python opencode_usage.py',
fmtErr: '✗ 时间段格式应为 YYYY-MM-DD(如 2026-08-05)',
parseErr: '解析失败:', emptyExcel: 'Excel 中没有数据',
colErr: '未找到 输入/缓存读取/输出/推理 列,请确认选择的是 opencode_usage_history.xlsx',
setTitle: '设置', setLang: '语言', setTheme: '主题',
themeSystem: '跟随系统', themeDark: '深色', themeLight: '亮色',
setLogin: '登录', setWorkspace: '工作区', wsHint: '留空自动获取', setAccount: '账号', setPassword: '密码', pwdHint: '留空用缓存登录态', accountHint: '请输入账号',
setTimeRange: '更新时间段', timeAll: '全部数据', timeSpec: '指定时间段', timePeriod: '固定周期',
setUpdateMode: '更新方式',
incrementalDesc: '仅更新 Excel 最新记录之后的新数据',
timeStart: '开始', timeEnd: '结束',
period1: '1 个月', period3: '3 个月', period6: '6 个月', period12: '1 年',
save: '保存', cancel: '取消', fmtHint: '请选择下载的起始与结束日期',
autoFetch: '自动更新', autoFetchDesc: '定时更新', interval: '更新时间',
unitMin: '分钟', unitHour: '小时', unitDay: '天',
footerSrc: '数据来源', footerTokenNote: 'Token 图每根柱按', footerStackNote: '堆叠,悬停查看总 Token',
footerGen: '生成于', footerStack: 'Powered by SheetJS & Chart.js',
},
en: {
update: 'Update Data', settings: 'Settings', updating: 'Updating…',
loadingTitle: 'Loading data from local service…',
loadingHint: 'No response? Start the service first:',
chooseFile: 'Choose Excel File', dropFile: 'drop file',
loadFailTitle: 'Cannot reach local service, choose an Excel file manually',
model: 'Model', allModels: 'All Models',
metric: 'Metric', token: 'Token', cost: 'Cost',
gran: 'Granularity', gMonth: 'Month', gWeek: 'Week', gDay: 'Day', gHour: 'Hour', gMinute: 'Minute',
range: 'Time Range', reset: 'Default',
noData: 'Load an Excel file first', noDataInGran: 'No data to aggregate at this granularity',
recordCount: 'Record Count', recordCountSub: 'API Calls',
totalToken: 'Total Token', totalTokenSub: 'Cache + Input + Output + Reasoning',
totalCost: 'Total Cost', totalCostSub: '≈ ',
timeRange: 'Time Range', timeRangeNotSet: 'Range not set',
ttHead: 'Current Range · Token Detail',
ttCache: 'Cache Read', ttInput: 'Input', ttOutput: 'Output', ttReasoning: 'Reasoning',
ttTotal: 'Total Token', ttCost: 'Total Cost', ttRecords: 'Records', ttHitRate: 'Cache Hit Rate', hitrateToggle: 'Hit Rate', hitrateLine: 'Hit Rate', hitrateAxis: 'Hit Rate (%)',
chartTokenTitle: 'Token Usage', chartCostTitle: 'Cost · USD',
chartBy: 'by', chartStat: '',
legendCache: 'Cache Read', legendInput: 'Input', legendOutput: 'Output', legendReasoning: 'Reasoning',
legendCost: 'Cost (USD)', barHeightNote: 'Bar height = Total Token (sum of 4 parts)',
groups: 'GROUPS', records: 'RECORDS',
updateConnecting: 'Connecting to local service…',
updateSuccess: 'Updated', updateFail: 'Update failed', rowsSuffix: 'records',
serverHint: 'Start the local service first: python opencode_usage.py',
fmtErr: '✗ Date format must be YYYY-MM-DD (e.g. 2026-08-05)',
parseErr: 'Parse error: ', emptyExcel: 'Excel has no data',
colErr: 'Input/Cache/Output/Reasoning columns not found. Please pick opencode_usage_history.xlsx',
setTitle: 'Settings', setLang: 'Language', setTheme: 'Theme',
themeSystem: 'System', themeDark: 'Dark', themeLight: 'Light',
setLogin: 'Login', setWorkspace: 'Workspace', wsHint: 'Leave blank to auto-detect', setAccount: 'Account', setPassword: 'Password', pwdHint: 'Leave blank to reuse cached session', accountHint: 'Enter account',
setTimeRange: 'Update Time Range', timeAll: 'All Data', timeSpec: 'Specific Range', timePeriod: 'Fixed Period',
setUpdateMode: 'Update Mode',
incrementalDesc: 'Only fetch data newer than the latest Excel record',
timeStart: 'Start', timeEnd: 'End',
period1: '1 Month', period3: '3 Months', period6: '6 Months', period12: '1 Year',
save: 'Save', cancel: 'Cancel', fmtHint: 'Pick the start and end dates',
autoFetch: 'Auto Update', autoFetchDesc: 'Scheduled update', interval: 'Update Interval',
unitMin: 'Minutes', unitHour: 'Hours', unitDay: 'Days',
footerSrc: 'Data source', footerTokenNote: 'Each bar stacks', footerStackNote: 'and shows total on hover',
footerGen: 'Generated by', footerStack: 'Powered by SheetJS & Chart.js',
},
};
// ============ 设置(localStorage 持久化,非数据库) ============
const SETTINGS_KEY = 'usageConsoleSettings';
const DEFAULT_SETTINGS = {
lang: 'zh',
theme: 'system',
loginMethod: 'github',
workspace: '',
email: '',
password: '',
timeMode: 'all',
start: '',
end: '',
period: 1,
incremental: false,
autoFetch: false,
autoFetchInterval: 30,
autoFetchUnit: 'min',
};
let settings = loadSettings();
let t = (key) => {
const dict = I18N[settings.lang] || I18N.zh;
// 用 hasOwnProperty 判断,避免字典值为空字符串 '' 时被 || 回退成 key 名
return Object.prototype.hasOwnProperty.call(dict, key) ? dict[key] : key;
};
function loadSettings() {
try {
const raw = localStorage.getItem(SETTINGS_KEY);
if (!raw) return { ...DEFAULT_SETTINGS };
return { ...DEFAULT_SETTINGS, ...JSON.parse(raw) };
} catch (e) {
return { ...DEFAULT_SETTINGS };
}
}
function saveSettings() {
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
}
function applyLang() {
document.querySelectorAll('[data-i18n]').forEach(el => {
const key = el.dataset.i18n;
el.textContent = t(key);
});
document.querySelectorAll('[data-placeholder]').forEach(el => {
el.placeholder = t(el.dataset.placeholder);
});
document.title = 'OpenCode · Usage Console';
if (rawRows.length) {
renderModelSelect(rawRows, resolveColumns(Object.keys(rawRows[0])));
renderAll();
}
}
// 主题:跟随系统 / 深色 / 亮色
const mq = window.matchMedia('(prefers-color-scheme: light)');
function effectiveTheme() {
if (settings.theme === 'system') return mq.matches ? 'light' : 'dark';
return settings.theme;
}
function applyTheme() {
document.documentElement.setAttribute('data-theme', effectiveTheme());
if (rawRows.length) renderAll(); // 图表颜色跟随主题
}
mq.addEventListener('change', () => { if (settings.theme === 'system') applyTheme(); });
// ============ 设置弹窗 ============
function syncModal() {
const setSeg = (id, val) => {
document.querySelectorAll('#' + id + ' button').forEach(b =>
b.classList.toggle('active', b.dataset.lang === val || b.dataset.themeOpt === val ||
b.dataset.method === val || b.dataset.mode === val || b.dataset.months === String(val) ||
b.dataset.unit === val));
};
setSeg('setLang', settings.lang);
setSeg('setTheme', settings.theme);
setSeg('setLoginMethod', settings.loginMethod);
setSeg('setTimeMode', settings.timeMode);
setSeg('setPeriod', settings.period);
setSeg('setUnit', settings.autoFetchUnit);
document.getElementById('setEmail').value = settings.email || '';
document.getElementById('setPassword').value = settings.password || '';
document.getElementById('setWorkspace').value = settings.workspace || '';
document.getElementById('setStart').value = settings.start || '';
document.getElementById('setEnd').value = settings.end || '';
document.getElementById('rangeFields').style.display = settings.timeMode === 'range' ? 'flex' : 'none';
document.getElementById('periodFields').style.display = settings.timeMode === 'period' ? 'flex' : 'none';
document.getElementById('setAutoFetch').checked = !!settings.autoFetch;
document.getElementById('setIncremental').checked = !!settings.incremental;
document.getElementById('setInterval').value = settings.autoFetchInterval || 30;
document.getElementById('autoFetchFields').style.display = settings.autoFetch ? 'flex' : 'none';
}
function openSettings() { syncModal(); document.getElementById('settingsModal').classList.add('open'); }
function closeSettings() { document.getElementById('settingsModal').classList.remove('open'); }
document.getElementById('btnSettings').addEventListener('click', openSettings);
document.getElementById('settingsClose').addEventListener('click', closeSettings);
document.getElementById('settingsCancel').addEventListener('click', closeSettings);
document.getElementById('settingsModal').addEventListener('click', (e) => {
if (e.target.id === 'settingsModal') closeSettings();
});
// 弹窗内 seg 切换
['setLang', 'setTheme', 'setLoginMethod', 'setTimeMode', 'setPeriod', 'setUnit'].forEach(id => {
document.getElementById(id).addEventListener('click', (e) => {
const btn = e.target.closest('button');
if (!btn) return;
document.querySelectorAll('#' + id + ' button').forEach(b => b.classList.toggle('active', b === btn));
});
});
// 自动获取开关联动:开启时显示间隔设置
document.getElementById('setAutoFetch').addEventListener('change', (e) => {
document.getElementById('autoFetchFields').style.display = e.target.checked ? 'flex' : 'none';
});
// 时间模式联动显示
document.getElementById('setTimeMode').addEventListener('click', (e) => {
const btn = e.target.closest('button');
if (!btn) return;
const mode = btn.dataset.mode;
document.getElementById('rangeFields').style.display = mode === 'range' ? 'flex' : 'none';
document.getElementById('periodFields').style.display = mode === 'period' ? 'flex' : 'none';
});
// 保存
document.getElementById('settingsSave').addEventListener('click', () => {
settings.lang = document.querySelector('#setLang button.active').dataset.lang;
settings.theme = document.querySelector('#setTheme button.active').dataset.themeOpt;
settings.loginMethod = document.querySelector('#setLoginMethod button.active').dataset.method;
settings.email = document.getElementById('setEmail').value.trim();
settings.password = document.getElementById('setPassword').value;
settings.workspace = document.getElementById('setWorkspace').value.trim();
settings.timeMode = document.querySelector('#setTimeMode button.active').dataset.mode;
settings.start = document.getElementById('setStart').value.trim();
settings.end = document.getElementById('setEnd').value.trim();
settings.period = Number(document.querySelector('#setPeriod button.active').dataset.months) || 1;
settings.incremental = document.getElementById('setIncremental').checked;
settings.autoFetch = document.getElementById('setAutoFetch').checked;
settings.autoFetchInterval = Math.max(1, Math.floor(Number(document.getElementById('setInterval').value) || 30));
settings.autoFetchUnit = document.querySelector('#setUnit button.active').dataset.unit;
saveSettings();
applyLang();
applyTheme();
syncAutoFetch(); // 同步自动更新配置到后端(后台定时执行)
closeSettings();
});
// ============ 全局状态 ============
let rawRows = [];
let currentMetric = 'token';
let currentGran = 'day';
let currentModel = 'all';
let chart = null, showHitRate = false;
const CARD_META = {
count: { bar: '#22d3ee', icon: '<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/></svg>' },
token: { bar: '#818cf8', icon: '<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2 3 14h7l-1 8 10-12h-7l1-8z"/></svg>' },
cost: { bar: '#2dd4a7', icon: '<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M9.5 15.5c.6.9 1.6 1.5 2.7 1.5 1.8 0 3.1-1.1 3.1-2.6 0-3.4-5.6-2.1-5.6-5.4 0-1.5 1.3-2.6 3-2.6 1.1 0 2 .5 2.6 1.3"/></svg>' },
range: { bar: '#f5b04c', icon: '<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/></svg>' },
};
// ============ Excel 列名柔性匹配 ============
function pickCol(header, rules) {
for (const col of header) {
const key = String(col);
if (rules.every(fn => fn(key))) return key;
}
return null;
}
function resolveColumns(header) {
return {
time: pickCol(header, [k => /日期|时间/.test(k)]) || header[0],
model: pickCol(header, [k => /模型/.test(k)]),
input: pickCol(header, [k => /输入/.test(k) && !/合计/.test(k)]),
cache: pickCol(header, [k => /缓存/.test(k)]),
output: pickCol(header, [k => /输出/.test(k) && !/合计/.test(k)]),
reasoning: pickCol(header, [k => /推理/.test(k)]),
cost: pickCol(header, [k => /成本/.test(k) && !/显示/.test(k)]),
};
}
function num(v) {
const n = typeof v === 'number' ? v : parseFloat(v);
return isFinite(n) ? n : 0;
}
// ============ 文件读取 ============
function applyData(json, name) {
const header = Object.keys(json[0]);
const cols = resolveColumns(header);
if (!cols.input || !cols.cache || !cols.output || !cols.reasoning) {
throw new Error(t('colErr'));
}
rawRows = json;
const chip = document.getElementById('fileInfo');
chip.querySelector('.fc-name').textContent = 'LOADED · ' + name + ' · ';
chip.querySelector('.fc-count').textContent = json.length + ' rows';
chip.classList.add('loaded');
document.getElementById('uploadCard').style.display = 'none';
document.getElementById('statsArea').style.display = 'block';
document.getElementById('emptyTip').style.display = 'none';
renderModelSelect(json, cols);
applyDefaultRange(currentGran);
renderAll();
return json.length;
}
function handleFile(file) {
const reader = new FileReader();
reader.onload = (e) => {
try {
const wb = XLSX.read(new Uint8Array(e.target.result), { type: 'array' });
const ws = wb.Sheets[wb.SheetNames[0]];
const json = XLSX.utils.sheet_to_json(ws, { defval: null });
if (!json.length) throw new Error(t('emptyExcel'));
applyData(json, file.name);
} catch (err) {
alert(t('parseErr') + err.message);
console.error(err);
}
};
reader.readAsArrayBuffer(file);
}