Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
2353 lines (2280 loc) · 111 KB
/
Copy pathindex.html
File metadata and controls
2353 lines (2280 loc) · 111 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; flex: none; }
.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;
}
/* 右侧块用零基准伸缩:不这样它按 max-content 参与父级换行判断,日志一长整块就掉到品牌下方。
内容靠右对齐,空闲空间留在品牌与按钮之间,视觉与原来一致 */
.header-right {
display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
flex: 1 1 0; min-width: 0; justify-content: flex-end;
}
.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; }
/* 导出按钮:从本地库现生成报表,样式比"更新数据"弱一档,避免两个主操作抢注意力 */
.export-btn {
font-family: var(--mono); font-size: 12px; font-weight: 600;
color: var(--text-dim); background: var(--card);
border: 1px solid var(--border); border-radius: 999px;
padding: 8px 14px; cursor: pointer; letter-spacing: .5px;
display: inline-flex; align-items: center; gap: 8px;
backdrop-filter: blur(8px); transition: all .2s;
}
.export-btn:hover:not(:disabled) { color: var(--accent); border-color: rgba(34, 211, 238, .45); }
.export-btn:active:not(:disabled) { transform: scale(.97); }
.export-btn:disabled { opacity: .55; cursor: progress; }
.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;
flex: 0 1 auto; min-width: 0; max-width: 400px; overflow: hidden; white-space: nowrap;
backdrop-filter: blur(8px);
}
.file-chip .fc-name { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.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); }
/* 说明行挂在文件条下方但不占布局:header 仍是单行高度,按钮/文件条保持齐平 */
.file-block { position: relative; flex: 0 1 auto; min-width: 0; }
.auto-line {
position: absolute; top: calc(100% + 5px); right: 6px; white-space: nowrap;
display: inline-flex; align-items: center; gap: 6px;
font-family: var(--mono); font-size: 11px; color: var(--text-dim); letter-spacing: .07em;
}
.auto-line .dot {
width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
background: var(--green); box-shadow: 0 0 8px rgba(45, 212, 167, .7);
}
.auto-line.off .dot { background: var(--text-faint); box-shadow: none; }
.auto-line .t { color: var(--text); font-weight: 600; letter-spacing: 0; }
.auto-line.off .t { color: var(--text-faint); font-weight: 400; }
.file-chip.flash { border-color: rgba(45, 212, 167, .6); background: rgba(45, 212, 167, .1); }
/* 爬虫一行日志可能很长:状态条只占它需要的宽度并可收缩(省略号截断),
既不撑高 header,也不把文件条/设置按钮挤到第二行 */
.up-status {
font-family: var(--mono); font-size: 11.5px; color: var(--text-dim);
flex: 0 1 auto; min-width: 0; max-width: 260px;
line-height: 17px; height: 17px;
display: inline-flex; align-items: center; gap: 7px;
transition: color .2s;
}
.up-status #upStatusText { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.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 {
position: relative;
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; }
.chart-opts { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.chart-opt {
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;
}
.chart-opt:hover { border-color: rgba(34, 211, 238, .45); color: var(--text); }
.chart-opt 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; }
/* 图例只留这一份(Chart.js 自带图例关掉,否则两份重复、模型一多就吃掉半屏) */
.legend-note {
margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--border);
font-family: var(--mono); font-size: 11.5px; color: var(--text-dim);
display: flex; flex-wrap: wrap; gap: 7px 14px; align-items: center;
}
.legend-note .item {
display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
border: 1px solid transparent; border-radius: 7px; padding: 2px 7px 2px 5px;
transition: background .15s, opacity .15s, border-color .15s;
}
.legend-note .item:hover { background: var(--seg-bg); border-color: var(--border); }
.legend-note .item.off { opacity: .34; }
.legend-note .item.off .swatch { filter: grayscale(1); }
.legend-note .item b { font-weight: 600; color: var(--text-faint); font-size: 10.5px; }
.legend-note .swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; box-shadow: 0 0 8px rgba(255,255,255,.08); flex: none; }
.legend-note .hint { color: var(--text-faint); }
.legend-more {
font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--accent);
background: transparent; border: 1px solid rgba(34, 211, 238, .35);
border-radius: 7px; padding: 3px 10px; cursor: pointer; transition: all .18s; white-space: nowrap;
}
.legend-more:hover { background: rgba(34, 211, 238, .1); border-color: rgba(34, 211, 238, .6); }
/* 悬停图例色块时的单模型信息卡:只讲这一个模型,不掺别系列 */
.legend-card {
position: absolute; z-index: 40; display: none; pointer-events: none;
min-width: 208px; padding: 9px 12px 10px;
background: var(--tooltip-bg); border: 1px solid var(--border-strong); border-radius: 10px;
box-shadow: 0 14px 34px rgba(0, 0, 0, .38);
font-family: var(--mono); font-size: 11px; line-height: 1.75; color: var(--text-dim);
}
.legend-card .lc-name { display: flex; align-items: center; gap: 7px; color: var(--text); font-weight: 700; margin-bottom: 3px; }
.legend-card .lc-sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-card b { color: var(--text); font-weight: 600; }
.legend-card .lc-hi { color: var(--accent); }
/* ===== 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(行内标签)与 .acc-field(标签在上)共用 */
.field-group input, .acc-field 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, .acc-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
.field-group input::placeholder, .acc-field 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; }
/* 账号列表:一行一个账号,状态点 + 名称 + 信息芯片,删除按钮固定在右侧垂直居中 */
.acc-list { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.acc-row {
display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px;
background: var(--input-bg); cursor: pointer; transition: border-color .2s, background .2s;
}
.acc-row:hover { border-color: var(--border-strong); background: rgba(34, 211, 238, .04); }
.acc-row.active { border-color: rgba(34, 211, 238, .45); background: rgba(34, 211, 238, .06); }
.acc-main { min-width: 0; }
.acc-name { display: flex; align-items: center; gap: 8px; min-width: 0;
font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--text); }
.acc-name .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--text-faint); }
.acc-dot.on { background: var(--green); box-shadow: 0 0 8px rgba(45, 212, 167, .6); }
.acc-name .tag {
flex: none; font-size: 9.5px; font-weight: 500; letter-spacing: .6px; color: var(--accent);
border: 1px solid rgba(34, 211, 238, .4); border-radius: 5px; padding: 1px 5px;
}
/* 同步时间放名称行右侧:卡片恒为"名称 + 芯片"两行,多账号列表高度整齐 */
.acc-sync { flex: none; margin-left: auto; font-family: var(--mono); font-size: 10px;
color: var(--text-faint); white-space: nowrap; }
.acc-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip {
font-family: var(--mono); font-size: 10px; line-height: 1.5; letter-spacing: .3px;
color: var(--text-dim); background: var(--seg-bg); border: 1px solid var(--border);
border-radius: 6px; padding: 1px 7px; max-width: 100%;
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.method { color: var(--text); border-color: var(--border-strong); text-transform: capitalize; }
.chip.ok { color: var(--green); border-color: rgba(45, 212, 167, .32); }
.chip.warn { color: var(--amber); border-color: rgba(245, 176, 76, .32); }
.acc-del {
font-family: var(--mono); font-size: 11px; color: var(--text-dim); background: transparent;
border: 1px solid var(--border); border-radius: 8px; padding: 6px 11px; cursor: pointer;
transition: all .18s; white-space: nowrap;
}
.acc-del:hover { color: #e5484d; border-color: rgba(229, 72, 77, .5); background: rgba(229, 72, 77, .07); }
.acc-empty {
font-family: var(--mono); font-size: 11.5px; color: var(--text-faint);
border: 1px dashed var(--border-strong); border-radius: 12px; padding: 14px; text-align: center;
}
/* 添加账号:标签置于输入框上方,两列栅格对齐,操作与提示同处一行 */
.acc-form {
margin-top: 12px; border: 1px solid var(--border); border-radius: 12px; padding: 13px;
background: var(--bg-soft);
}
.acc-form-title {
font-family: var(--mono); font-size: 10px; letter-spacing: 1.4px; text-transform: uppercase;
color: var(--text-faint); margin-bottom: 11px;
}
.acc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px 14px; }
.acc-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.acc-field > label {
font-family: var(--mono); font-size: 10px; letter-spacing: 1.2px;
text-transform: uppercase; color: var(--text-faint);
}
.acc-field input { width: 100%; }
.acc-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 12px; margin-top: 13px; }
.acc-hint { flex: 1 1 200px; min-width: 0; font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.acc-status { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.acc-status.ok { color: var(--green); }
.acc-status.err { color: #e5484d; }
@media (max-width: 560px) { .acc-grid { grid-template-columns: minmax(0, 1fr); } }
.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; }
}
/* 窄屏先收紧两个"可截断"的元素(状态条/文件条),保证 header 仍是一行;再窄才整体换行 */
@media (max-width: 1180px) {
.up-status { max-width: 170px; }
.file-chip { max-width: 230px; }
}
@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>
<button class="export-btn" id="btnExport" title="⬇ xlsx"><span data-i18n="export">导出 Excel</span></button>
<span class="up-status" id="upStatus"><span class="dot" style="display:none"></span><span id="upStatusText"></span></span>
<div class="file-block">
<div class="file-chip" id="fileInfo"><span class="fc-name" data-i18n="chipNone">尚未加载数据</span><span class="fc-count"></span></div>
<div class="auto-line" id="autoInfo"><span class="dot"></span><span>AUTO</span><span class="t"></span></div>
</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" id="ctrlAccount">
<span class="ctrl-label" data-i18n="account">账号</span>
<select class="model-select" id="selAccount">
<option value="all" data-i18n="allAccounts">所有账号</option>
</select>
</div>
<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>
<div class="chart-opts">
<!-- 细分与命中率并列:都是"这张图怎么看"的选项,不该占控制栏 -->
<label class="chart-opt" id="byModelWrap">
<span data-i18n="byModel">按模型细分</span>
<input type="checkbox" id="byModelToggle">
</label>
<label class="chart-opt" id="hitrateWrap" style="display:none">
<span data-i18n="hitrateToggle">缓存命中率</span>
<input type="checkbox" id="hitrateToggle">
</label>
</div>
</div>
<div class="chart-wrap">
<canvas id="chart"></canvas>
<div class="empty-tip" id="emptyTip">
<div><div class="big">▤</div><div data-i18n="noData">还没有数据</div></div>
</div>
</div>
<div class="legend-note" id="legendNote"></div>
<div class="legend-card" id="legendCard"></div>
</div>
</div>
</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="setAccounts">账号管理</div>
<div class="acc-list" id="accList"></div>
<div class="acc-form">
<div class="acc-form-title" data-i18n="accFormTitle">添加 / 更新账号</div>
<div class="acc-grid">
<div class="acc-field">
<label data-i18n="accEmail">邮箱</label>
<input type="text" id="setAccEmail" data-placeholder="accountHint" placeholder="请输入账号">
</div>
<div class="acc-field">
<label data-i18n="accLabel">备注名</label>
<input type="text" id="setAccLabel" data-placeholder="labelHint" placeholder="留空用邮箱">
</div>
<div class="acc-field">
<label data-i18n="accPwd">密码</label>
<input type="password" id="setAccPwd" data-placeholder="pwdHint" placeholder="留空沿用已存密码">
</div>
<div class="acc-field">
<label data-i18n="accMethod">登录方式</label>
<div class="seg" id="setAccMethod">
<button data-method="github" class="active">GitHub</button>
<button data-method="google">Google</button>
<button data-method="email">Email</button>
</div>
</div>
<div class="acc-field">
<label data-i18n="setWorkspace">工作区</label>
<input type="text" id="setWorkspace" data-placeholder="wsHint" placeholder="留空自动获取">
</div>
</div>
<div class="acc-actions">
<span class="acc-hint" data-i18n="accHint">重复提交同一邮箱只更新密码;首次添加会弹浏览器人工验证。</span>
<span class="acc-status" id="accStatus"></span>
<button class="btn-primary" id="btnAccAdd" data-i18n="accAdd">保存账号</button>
</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">只抓取各账号已有记录之后的新数据</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: '更新中…',
export: '导出 Excel', exporting: '正在生成报表…', exportDone: '✓ 报表已导出', exportFail: '✗ 导出失败:',
loadingTitle: '正在从本地库加载数据…',
loadingHint: '若长时间无响应,请先启动服务:',
chooseFile: '选择 Excel 文件', dropFile: 'drop file',
dbFailTitle: '本地库读取失败,请确认服务已启动且 opencode_usage.db 可读',
// 本地库是唯一数据源:文件条只可能显示"本地库"或用户手动选的文件
chipNone: '尚未加载数据', chipLoaded: '已加载', chipRows: '条',
srcDb: '本地库 opencode_usage.db',
account: '账号', allAccounts: '所有账号',
model: '模型', allModels: '所有模型',
metric: '统计方式', token: 'Token', cost: '金额',
byModel: '按模型细分',
gran: '时间粒度', gMonth: '按月', gWeek: '按周', gDay: '按天', gHour: '按小时', gMinute: '按分钟',
range: '时间范围', reset: '默认',
noData: '还没有数据', 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(四段之和)',
modelTokenNote: '已按模型细分:每段是一种模型的 Token', modelCostNote: '已按模型细分:每段是一种模型的成本',
legendClick: '点击隐藏 / 显示该系列', legendExpand: '展开', legendFold: '收起',
lcTotal: '合计', lcRecords: '记录', lcPeak: '峰值',
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: '亮色',
setAccounts: '账号管理', setWorkspace: '工作区', wsHint: '留空自动获取',
pwdHint: '留空沿用已存密码', accountHint: '请输入账号',
accLabel: '备注名', labelHint: '留空用邮箱', accEmail: '邮箱', accPwd: '密码', accMethod: '登录方式',
accFormTitle: '添加 / 更新账号', accAdd: '保存账号', accDel: '删除',
accEmpty: '还没有账号,用下面的表单添加',
accHint: '重复提交同一邮箱只更新密码;首次添加会弹浏览器人工验证,邮箱方式还要到邮箱点验证链接。',
accTagCurrent: '当前', accState: '登录态已缓存', accNoState: '未登录', accSync: '同步', accNever: '从未同步', accOrg: '组织',
accClick: '点击切换为该账号', accSwitched: '✓ 已切为当前账号',
accAdded: '✓ 账号已保存', accRemoved: '✓ 账号已删除', accFail: '✗ 账号操作失败:', accNeedEmail: '✗ 请填写账号邮箱',
setTimeRange: '更新时间段', timeAll: '全部数据', timeSpec: '指定时间段', timePeriod: '固定周期',
setUpdateMode: '更新方式',
incrementalDesc: '只抓取各账号已有记录之后的新数据',
timeStart: '开始', timeEnd: '结束',
period1: '1 个月', period3: '3 个月', period6: '6 个月', period12: '1 年',
save: '保存', cancel: '取消', fmtHint: '请选择下载的起始与结束日期',
autoFetch: '自动更新', autoFetchDesc: '定时更新', interval: '更新时间',
unitMin: '分钟', unitHour: '小时', unitDay: '天',
autoTipOn: '每 {n} {u}自动更新一次',
autoTipOff: '自动更新已关闭',
},
en: {
update: 'Update Data', settings: 'Settings', updating: 'Updating…',
export: 'Export Excel', exporting: 'Building report…', exportDone: '✓ Report exported', exportFail: '✗ Export failed: ',
loadingTitle: 'Loading data from the local database…',
loadingHint: 'No response? Start the service first:',
chooseFile: 'Choose Excel File', dropFile: 'drop file',
dbFailTitle: 'Cannot read the local database — make sure the service runs and opencode_usage.db is readable',
// The local SQLite DB is the only store; the chip shows it, or a file the user picked
chipNone: 'no data loaded', chipLoaded: 'LOADED', chipRows: 'rows',
srcDb: 'local DB opencode_usage.db',
account: 'Account', allAccounts: 'All Accounts',
model: 'Model', allModels: 'All Models',
metric: 'Metric', token: 'Token', cost: 'Cost',
byModel: 'Break down by model',
gran: 'Granularity', gMonth: 'Month', gWeek: 'Week', gDay: 'Day', gHour: 'Hour', gMinute: 'Minute',
range: 'Time Range', reset: 'Default',
noData: 'No data yet', 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)',
modelTokenNote: 'Broken down by model — each segment is one model (tokens)', modelCostNote: 'Broken down by model — each segment is one model (cost)',
legendClick: 'Click to hide / show this series', legendExpand: 'expand', legendFold: 'collapse',
lcTotal: 'Total', lcRecords: 'Requests', lcPeak: 'Peak',
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',
setAccounts: 'Accounts', setWorkspace: 'Workspace', wsHint: 'Leave blank to auto-detect',
pwdHint: 'Leave blank to keep saved password', accountHint: 'Enter account',
accLabel: 'Label', labelHint: 'Blank = use email', accEmail: 'Email', accPwd: 'Password', accMethod: 'Login',
accFormTitle: 'Add / update account', accAdd: 'Save account', accDel: 'Delete',
accEmpty: 'No account yet — add one below',
accHint: 'Re-submitting an email only updates its password; first login needs manual hCaptcha, and email sign-in also asks you to open the link in your inbox.',
accTagCurrent: 'current', accState: 'signed in', accNoState: 'not signed in', accSync: 'sync', accNever: 'never synced', accOrg: 'org',
accClick: 'Click to switch to this account', accSwitched: '✓ now the current account',
accAdded: '✓ Account saved', accRemoved: '✓ Account removed', accFail: '✗ Account operation failed: ', accNeedEmail: '✗ Email is required',
setTimeRange: 'Update Time Range', timeAll: 'All Data', timeSpec: 'Specific Range', timePeriod: 'Fixed Period',
setUpdateMode: 'Update Mode',
incrementalDesc: 'Only fetch data newer than each account’s existing records',
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',
autoTipOn: 'Auto-update every {n} {u}',
autoTipOff: 'Auto-update is off',
},
};
// ============ 设置(localStorage 持久化,非数据库) ============
const SETTINGS_KEY = 'usageConsoleSettings';
const DEFAULT_SETTINGS = {
lang: 'zh',
theme: 'system',
workspace: '',
// 凭据不在这里:账号列表由后端注册表管(/api/accounts),前端只缓存脱敏视图
accounts: [],
timeMode: 'all',
start: '',
end: '',
period: 1,
incremental: false,
autoFetch: false,
autoFetchInterval: 30,
autoFetchUnit: 'min',
// 显示偏好:看哪个账号、是否按模型分色(切换 Token/金额时保持不变)
accountFilter: 'all',
byModel: false,
};
let settings = loadSettings();
let t = (key) => {