-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin.html
More file actions
1369 lines (1262 loc) · 47.1 KB
/
admin.html
File metadata and controls
1369 lines (1262 loc) · 47.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>ModelScope API 转换器 - 管理后台</title>
<style>
:root {
--bg-primary: #0f172a;
--bg-secondary: #1e293b;
--bg-card: #1e293b;
--bg-hover: #334155;
--bg-input: #0f172a;
--border: #334155;
--text-primary: #f1f5f9;
--text-secondary: #94a3b8;
--text-muted: #64748b;
--accent: #3b82f6;
--accent-hover: #2563eb;
--success: #22c55e;
--warning: #f59e0b;
--danger: #ef4444;
--info: #06b6d4;
--radius: 8px;
}
* { margin:0; padding:0; box-sizing:border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
/* Header */
.header {
background: var(--bg-secondary);
border-bottom: 1px solid var(--border);
padding: 0 24px;
display: flex;
align-items: center;
justify-content: space-between;
height: 56px;
}
.header-title {
font-size: 16px;
font-weight: 600;
display: flex;
align-items: center;
gap: 10px;
}
.header-title .dot {
width: 8px; height: 8px;
border-radius: 50%;
background: var(--success);
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
.header-right {
display: flex;
align-items: center;
gap: 12px;
font-size: 13px;
color: var(--text-secondary);
}
/* Sticky Top */
.sticky-top {
position: sticky;
top: 0;
z-index: 100;
background: var(--bg-secondary);
}
/* Nav Tabs */
.nav-tabs {
display: flex;
background: var(--bg-secondary);
border-bottom: 1px solid var(--border);
padding: 0 24px;
gap: 0;
}
.nav-tab {
padding: 12px 20px;
font-size: 14px;
color: var(--text-secondary);
cursor: pointer;
border-bottom: 2px solid transparent;
transition: all 0.2s;
user-select: none;
}
.nav-tab:hover { color: var(--text-primary); }
.nav-tab.active {
color: var(--accent);
border-bottom-color: var(--accent);
font-weight: 500;
}
/* Main */
.main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.tab-content { display: none; }
.tab-content.active { display: block; }
/* Cards */
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 20px;
margin-bottom: 16px;
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
}
.card-title {
font-size: 15px;
font-weight: 600;
}
/* Stats Grid */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
margin-bottom: 16px;
}
.stat-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 20px;
}
.stat-label {
font-size: 12px;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 8px;
}
.stat-value {
font-size: 28px;
font-weight: 700;
}
.stat-sub {
font-size: 12px;
color: var(--text-secondary);
margin-top: 4px;
}
.stat-value.text-success { color: var(--success); }
.stat-value.text-danger { color: var(--danger); }
.stat-value.text-warning { color: var(--warning); }
.stat-value.text-info { color: var(--info); }
/* Buttons */
.btn {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 7px 14px;
border: none;
border-radius: 6px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { opacity: 0.9; }
.btn-outline {
background: transparent;
color: var(--text-secondary);
border: 1px solid var(--border);
}
.btn-outline:hover {
background: var(--bg-hover);
color: var(--text-primary);
}
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* Table */
.table-wrap { overflow-x: auto; }
table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
}
th, td {
padding: 10px 14px;
text-align: left;
border-bottom: 1px solid var(--border);
}
th {
font-weight: 600;
color: var(--text-secondary);
font-size: 12px;
text-transform: uppercase;
letter-spacing: 0.5px;
background: var(--bg-primary);
position: sticky; top: 0;
}
tr:hover td { background: var(--bg-hover); }
/* Badges */
.badge {
display: inline-block;
padding: 2px 8px;
border-radius: 9999px;
font-size: 11px;
font-weight: 600;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-info { background: rgba(6,182,212,0.15); color: var(--info); }
/* Log Viewer */
.log-toolbar {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
flex-wrap: wrap;
}
.log-viewer {
background: #020617;
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 12px;
font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
font-size: 12px;
line-height: 1.6;
max-height: 600px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-all;
}
.log-line { padding: 1px 0; }
.log-line:hover { background: var(--bg-hover); }
.log-line .time { color: var(--text-muted); }
.log-line .level-DEBUG { color: var(--text-muted); }
.log-line .level-INFO { color: var(--info); }
.log-line .level-WARNING { color: var(--warning); }
.log-line .level-ERROR { color: var(--danger); }
.log-line .msg { color: var(--text-primary); }
/* Form */
.form-group {
margin-bottom: 16px;
}
.form-label {
display: block;
font-size: 13px;
font-weight: 500;
color: var(--text-secondary);
margin-bottom: 6px;
}
.form-input, .form-select {
width: 100%;
padding: 8px 12px;
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: 6px;
color: var(--text-primary);
font-size: 14px;
outline: none;
transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus {
border-color: var(--accent);
}
.form-hint {
font-size: 12px;
color: var(--text-muted);
margin-top: 4px;
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
/* Toast */
.toast-container {
position: fixed;
top: 70px;
right: 24px;
z-index: 9999;
display: flex;
flex-direction: column;
gap: 8px;
}
.toast {
padding: 12px 20px;
border-radius: var(--radius);
font-size: 13px;
font-weight: 500;
animation: slideIn 0.3s ease;
min-width: 280px;
box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--info); color: #fff; }
@keyframes slideIn {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
/* Loading Spinner */
.spinner {
display: inline-block;
width: 16px; height: 16px;
border: 2px solid var(--border);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Empty State */
.empty-state {
text-align: center;
padding: 40px;
color: var(--text-muted);
}
.empty-state .icon { font-size: 36px; margin-bottom: 12px; }
/* Config Display */
.config-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 0;
border-bottom: 1px solid var(--border);
}
.config-item:last-child { border-bottom: none; }
.config-key {
font-size: 13px;
font-weight: 500;
color: var(--text-secondary);
}
.config-value {
font-size: 14px;
font-family: 'Cascadia Code', monospace;
color: var(--text-primary);
}
/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* Responsive */
@media (max-width: 768px) {
.main { padding: 16px; }
.stats-grid { grid-template-columns: 1fr 1fr; }
.form-row { grid-template-columns: 1fr; }
.nav-tab { padding: 10px 14px; font-size: 13px; }
}
</style>
</head>
<body>
<div class="sticky-top">
<div class="header">
<div class="header-title">
<span class="dot" id="statusDot"></span>
ModelScope API 转换器
</div>
<div class="header-right">
<span id="headerUptime">--</span>
<span>|</span>
<span id="headerModelCount">-- 个模型</span>
<span>|</span>
<button class="btn btn-outline btn-sm" onclick="handleLogout()" style="padding:4px 12px;font-size:12px;">退出登录</button>
</div>
</div>
<div class="nav-tabs">
<div class="nav-tab active" data-tab="dashboard">仪表盘</div>
<div class="nav-tab" data-tab="models">模型管理</div>
<div class="nav-tab" data-tab="stats">Token 统计</div>
<div class="nav-tab" data-tab="logs">日志查看</div>
<div class="nav-tab" data-tab="config">配置管理</div>
</div>
</div>
<div class="main">
<!-- ==================== 仪表盘 ==================== -->
<div class="tab-content active" id="tab-dashboard">
<div class="stats-grid">
<div class="stat-card">
<div class="stat-label">总模型数</div>
<div class="stat-value text-info" id="statTotal">-</div>
<div class="stat-sub">>= 4B 文本模型</div>
</div>
<div class="stat-card">
<div class="stat-label">可用模型</div>
<div class="stat-value text-success" id="statActive">-</div>
<div class="stat-sub">当前可正常使用</div>
</div>
<div class="stat-card">
<div class="stat-label">已禁用</div>
<div class="stat-value text-danger" id="statDisabled">-</div>
<div class="stat-sub">今日 400/404/500 错误</div>
</div>
<div class="stat-card">
<div class="stat-label">冷却中</div>
<div class="stat-value text-warning" id="statCooldown">-</div>
<div class="stat-sub">429 限速冷却</div>
</div>
<div class="stat-card">
<div class="stat-label">当前模型</div>
<div class="stat-value text-warning" id="statCurrent" style="font-size:16px;word-break:break-all;">-</div>
<div class="stat-sub">正在使用的模型</div>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">系统信息</div>
</div>
<div id="systemInfo">
<div class="config-item">
<span class="config-key">服务版本</span>
<span class="config-value" id="sysVersion">-</span>
</div>
<div class="config-item">
<span class="config-key">运行时间</span>
<span class="config-value" id="sysUptime">-</span>
</div>
<div class="config-item">
<span class="config-key">虚拟模型名</span>
<span class="config-value" id="sysVirtualModel">-</span>
</div>
<div class="config-item">
<span class="config-key">代理端口</span>
<span class="config-value" id="sysPort">-</span>
</div>
<div class="config-item">
<span class="config-key">参数下限</span>
<span class="config-value" id="sysMinParam">-</span>
</div>
<div class="config-item">
<span class="config-key">刷新间隔</span>
<span class="config-value" id="sysRefreshInterval">-</span>
</div>
<div class="config-item">
<span class="config-key">上次刷新</span>
<span class="config-value" id="sysLastRefresh">-</span>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">快速操作</div>
</div>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
<button class="btn btn-primary" onclick="refreshModels()">刷新模型列表</button>
<button class="btn btn-warning" onclick="resetDisabled()">重置所有禁用</button>
</div>
</div>
</div>
<!-- ==================== 模型管理 ==================== -->
<div class="tab-content" id="tab-models">
<div class="card">
<div class="card-header">
<div class="card-title">添加模型</div>
</div>
<div style="display:flex;gap:8px;align-items:flex-end;flex-wrap:wrap;">
<div class="form-group" style="flex:2;min-width:240px;margin-bottom:0;">
<label class="form-label">模型 ID</label>
<input class="form-input" id="addModelId" placeholder="如: Qwen/Qwen2.5-72B-Instruct">
<div class="form-hint">输入 ModelScope 上的完整模型 ID,自动解析参数量</div>
</div>
<div class="form-group" style="flex:1;min-width:120px;margin-bottom:0;">
<label class="form-label">参数量 (B)</label>
<input class="form-input" id="addModelParamB" type="number" min="0" step="0.1" placeholder="自动检测">
<div class="form-hint">可选,留空自动检测</div>
</div>
<button class="btn btn-primary" onclick="addCustomModel()" style="height:36px;">添加</button>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">模型列表</div>
<div style="display:flex;gap:8px;">
<button class="btn btn-primary btn-sm" onclick="refreshModels()">刷新列表</button>
<button class="btn btn-warning btn-sm" onclick="resetDisabled()">重置禁用</button>
</div>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>#</th>
<th>模型 ID</th>
<th>参数量</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody id="modelsTableBody">
<tr><td colspan="5" class="empty-state">加载中...</td></tr>
</tbody>
</table>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">被禁用的模型</div>
</div>
<div id="disabledList" class="empty-state">暂无被禁用的模型</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">自定义添加的模型</div>
</div>
<div id="customIncludeList" class="empty-state">暂无自定义添加的模型</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">已屏蔽的模型</div>
<div class="form-hint" style="margin:0;">屏蔽后模型不会出现在可用列表中,刷新模型列表也不会恢复</div>
</div>
<div id="customExcludeList" class="empty-state">暂无屏蔽的模型</div>
</div>
</div>
<!-- ==================== Token 统计 ==================== -->
<div class="tab-content" id="tab-stats">
<div class="stats-grid">
<div class="stat-card">
<div class="stat-label">总请求数</div>
<div class="stat-value text-info" id="statsTotalReq">-</div>
<div class="stat-sub">自服务启动</div>
</div>
<div class="stat-card">
<div class="stat-label">成功请求</div>
<div class="stat-value text-success" id="statsTotalSuccess">-</div>
<div class="stat-sub" id="statsSuccessRate">成功率 -</div>
</div>
<div class="stat-card">
<div class="stat-label">失败请求</div>
<div class="stat-value text-danger" id="statsTotalErrors">-</div>
<div class="stat-sub">含 429/4xx/5xx</div>
</div>
<div class="stat-card">
<div class="stat-label">总 Token 用量</div>
<div class="stat-value text-warning" id="statsTotalTokens">-</div>
<div class="stat-sub" id="statsTokenDetail">输入 - 输出 -</div>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">按模型统计</div>
<div style="display:flex;gap:8px;align-items:center;">
<button class="btn btn-outline btn-sm" onclick="loadStats()">刷新</button>
<button class="btn btn-danger btn-sm" onclick="resetStats()">重置统计</button>
</div>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>模型</th>
<th>请求数</th>
<th>成功</th>
<th>429</th>
<th>其他错误</th>
<th>输入 Token</th>
<th>输出 Token</th>
<th>总 Token</th>
</tr>
</thead>
<tbody id="statsModelTable">
<tr><td colspan="8" class="empty-state">加载中...</td></tr>
</tbody>
</table>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">近 24 小时趋势</div>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>小时</th>
<th>请求数</th>
<th>Token 用量</th>
</tr>
</thead>
<tbody id="statsTrendTable">
<tr><td colspan="3" class="empty-state">暂无数据</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- ==================== 日志查看 ==================== -->
<div class="tab-content" id="tab-logs">
<div class="card">
<div class="log-toolbar">
<select class="form-select" id="logLevel" style="width:120px;" onchange="loadLogs()">
<option value="ALL">全部级别</option>
<option value="DEBUG">DEBUG</option>
<option value="INFO">INFO</option>
<option value="WARNING">WARNING</option>
<option value="ERROR">ERROR</option>
</select>
<input class="form-input" id="logSearch" placeholder="搜索关键词..." style="width:240px;" onkeydown="if(event.key==='Enter')loadLogs()">
<select class="form-select" id="logLines" style="width:120px;" onchange="loadLogs()">
<option value="100">100 行</option>
<option value="200" selected>200 行</option>
<option value="500">500 行</option>
<option value="1000">1000 行</option>
</select>
<button class="btn btn-outline btn-sm" onclick="loadLogs()">刷新</button>
<button class="btn btn-outline btn-sm" id="autoRefreshBtn" onclick="toggleAutoRefresh()">自动刷新: 关</button>
<button class="btn btn-danger btn-sm" onclick="clearCurrentLog()">清空当前日志</button>
<span style="margin-left:auto;font-size:12px;color:var(--text-muted);" id="logCount"></span>
</div>
<div class="log-viewer" id="logViewer">加载中...</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">日志文件</div>
</div>
<div id="logFilesList"></div>
</div>
</div>
<!-- ==================== 配置管理 ==================== -->
<div class="tab-content" id="tab-config">
<div class="card">
<div class="card-header">
<div class="card-title">当前配置</div>
<button class="btn btn-outline btn-sm" onclick="loadConfig()">刷新</button>
</div>
<div id="configDisplay"></div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">修改配置</div>
</div>
<div class="form-group">
<label class="form-label">ModelScope API Key</label>
<div style="display:flex;gap:8px;">
<input class="form-input" id="cfgApiKey" type="password" placeholder="ms-xxxxxxxx">
<button class="btn btn-outline btn-sm" onclick="toggleApiKeyVisibility()" style="white-space:nowrap;">显示</button>
</div>
<div class="form-hint">ModelScope API 密钥(必须以 ms- 开头),修改后自动刷新模型列表</div>
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">虚拟模型名</label>
<input class="form-input" id="cfgVirtualModelName" placeholder="modelscope-auto">
<div class="form-hint">对外暴露的统一模型名称</div>
</div>
<div class="form-group">
<label class="form-label">参数下限 (B)</label>
<input class="form-input" id="cfgMinParamB" type="number" min="1" placeholder="4">
<div class="form-hint">仅保留参数量 >= 此值的大模型</div>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">刷新间隔 (秒)</label>
<input class="form-input" id="cfgRefreshInterval" type="number" min="60" placeholder="86400">
<div class="form-hint">多久重新获取模型列表</div>
</div>
<div class="form-group">
<label class="form-label">日志级别</label>
<select class="form-select" id="cfgLogLevel">
<option value="DEBUG">DEBUG</option>
<option value="INFO">INFO</option>
<option value="WARNING">WARNING</option>
<option value="ERROR">ERROR</option>
</select>
<div class="form-hint">日志输出级别</div>
</div>
</div>
<div class="form-group">
<label class="form-label">日志保留天数</label>
<input class="form-input" id="cfgLogRetention" type="number" min="0" placeholder="30" style="max-width:200px;">
<div class="form-hint">0 表示永不清空,超过天数的旧日志文件自动删除</div>
</div>
<div class="form-group">
<label class="form-label">回复头部模型标识</label>
<select class="form-select" id="cfgShowModelTag" style="max-width:200px;">
<option value="false">关闭(默认,vibe coding 推荐)</option>
<option value="true">开启(在每条回复前加 [模型名])</option>
</select>
<div class="form-hint">开启后,每条 AI 回复文本开头会自动注入 [Kimi-K2.5] 等模型标识,便于了解当前使用的模型</div>
</div>
<div style="margin-top:16px;">
<button class="btn btn-primary" onclick="saveConfig()">保存配置</button>
<span style="margin-left:12px;font-size:12px;color:var(--text-muted);">修改后自动保存到 .env 并即时生效</span>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="card-title">修改密码</div>
</div>
<div class="form-group">
<label class="form-label">当前密码</label>
<input class="form-input" id="pwdCurrent" type="password" placeholder="输入当前密码">
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">新密码</label>
<input class="form-input" id="pwdNew" type="password" placeholder="至少 6 位">
<div class="form-hint">建议使用 8 位以上包含字母和数字的密码</div>
</div>
<div class="form-group">
<label class="form-label">确认新密码</label>
<input class="form-input" id="pwdConfirm" type="password" placeholder="再次输入新密码">
</div>
</div>
<div style="margin-top:8px;">
<button class="btn btn-primary" onclick="changePassword()">修改密码</button>
<span style="margin-left:12px;font-size:12px;color:var(--text-muted);">修改后下次登录生效,当前会话不受影响</span>
</div>
</div>
<div class="card">
</div>
<pre style="background:var(--bg-primary);border:1px solid var(--border);border-radius:6px;padding:16px;font-size:13px;overflow-x:auto;font-family:'Cascadia Code','Fira Code','Consolas',monospace;line-height:1.6;color:var(--text-secondary);"><code id="apiExample">加载中...</code></pre>
</div>
</div>
</div>
<div class="toast-container" id="toastContainer"></div>
<script>
// ── 工具函数 ────────────────────────────────────────
const API_BASE = '/admin/api';
function toast(msg, type = 'info') {
const el = document.createElement('div');
el.className = `toast toast-${type}`;
el.textContent = msg;
document.getElementById('toastContainer').appendChild(el);
setTimeout(() => el.remove(), 3500);
}
async function api(path, opts = {}) {
try {
const res = await fetch(API_BASE + path, {
headers: { 'Content-Type': 'application/json' },
...opts,
});
if (res.status === 401) {
window.location.href = '/admin/login';
return null;
}
const data = await res.json().catch(() => ({}));
if (!res.ok) {
toast(data.error || data.detail || `请求失败 (${res.status})`, 'error');
return null;
}
return data;
} catch (e) {
toast('网络错误: ' + e.message, 'error');
return null;
}
}
function formatBytes(bytes) {
if (bytes < 1024) return bytes + ' B';
if (bytes < 1048576) return (bytes / 1024).toFixed(1) + ' KB';
return (bytes / 1048576).toFixed(1) + ' MB';
}
function escapeHtml(s) {
const d = document.createElement('div');
d.textContent = s;
return d.innerHTML;
}
// ── Tab 切换 ────────────────────────────────────────
document.querySelectorAll('.nav-tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('.nav-tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
document.getElementById('tab-' + tab.dataset.tab).classList.add('active');
if (tab.dataset.tab === 'dashboard') loadDashboard();
if (tab.dataset.tab === 'models') loadModels();
if (tab.dataset.tab === 'stats') loadStats();
if (tab.dataset.tab === 'logs') loadLogs();
if (tab.dataset.tab === 'config') loadConfig();
});
});
// ── 仪表盘 ──────────────────────────────────────────
async function loadDashboard() {
const data = await api('/status');
if (!data) return;
document.getElementById('statTotal').textContent = data.model_stats.total;
document.getElementById('statActive').textContent = data.model_stats.active;
document.getElementById('statDisabled').textContent = data.model_stats.disabled_today;
document.getElementById('statCooldown').textContent = data.model_stats.cooldown_count ?? 0;
document.getElementById('statCurrent').textContent = data.model_stats.current_model
? data.model_stats.current_model.id
: '无可用模型';
document.getElementById('sysVersion').textContent = data.version;
document.getElementById('sysUptime').textContent = data.uptime;
document.getElementById('sysVirtualModel').textContent = data.virtual_model;
document.getElementById('sysPort').textContent = data.proxy_port;
document.getElementById('sysMinParam').textContent = data.min_param_b + 'B';
document.getElementById('sysRefreshInterval').textContent = _formatInterval(data.refresh_interval);
document.getElementById('sysLastRefresh').textContent = data.last_refresh;
// Header
document.getElementById('headerUptime').textContent = data.uptime;
document.getElementById('headerModelCount').textContent = data.model_stats.active + '/' + data.model_stats.total + ' 个模型';
document.getElementById('statusDot').style.background =
data.model_stats.active > 0 ? 'var(--success)' : 'var(--danger)';
}
function _formatInterval(sec) {
if (sec >= 86400) return (sec / 86400).toFixed(0) + ' 天';
if (sec >= 3600) return (sec / 3600).toFixed(0) + ' 小时';
return sec + ' 秒';
}
// ── 模型管理 ────────────────────────────────────────
async function loadModels() {
const data = await api('/models');
if (!data) return;
const tbody = document.getElementById('modelsTableBody');
if (!data.models || data.models.length === 0) {
tbody.innerHTML = '<tr><td colspan="5" class="empty-state">暂无模型数据</td></tr>';
return;
}
tbody.innerHTML = data.models.map((m, i) => {
const isActive = m.is_active;
const isCooldown = m.is_cooldown;
const isDisabled = m.is_disabled;
const isCustom = m.is_custom;
let statusBadge;
if (isActive) {
statusBadge = '<span class="badge badge-success">可用</span>';
} else if (isCooldown) {
statusBadge = '<span class="badge badge-warning">冷却中(429)</span>';
} else if (isDisabled) {
statusBadge = '<span class="badge badge-danger">已禁用</span>';
} else {
statusBadge = '<span class="badge badge-danger">不可用</span>';
}
if (isCustom) {
statusBadge += ' <span class="badge badge-info">手动添加</span>';
}
const actionBtns = [];
if (isActive || isCooldown) {
actionBtns.push(`<button class="btn btn-danger btn-sm" onclick="disableModel('${escapeHtml(m.id)}')">禁用</button>`);
actionBtns.push(`<button class="btn btn-warning btn-sm" onclick="blockModel('${escapeHtml(m.id)}')">屏蔽</button>`);
} else {
actionBtns.push(`<button class="btn btn-success btn-sm" onclick="enableModel('${escapeHtml(m.id)}')">启用</button>`);
}
if (isCustom) {
actionBtns.push(`<button class="btn btn-outline btn-sm" onclick="removeCustomModel('${escapeHtml(m.id)}')">移除</button>`);
}
return `<tr>
<td>${i + 1}</td>
<td style="font-family:monospace;font-size:12px;word-break:break-all;">${escapeHtml(m.id)}</td>
<td>${m.param_b ? m.param_b + 'B' : '-'}</td>
<td>${statusBadge}</td>
<td style="display:flex;gap:4px;flex-wrap:wrap;">${actionBtns.join('')}</td>
</tr>`;
}).join('');
// 被禁用的模型列表
const disabledDiv = document.getElementById('disabledList');
if (data.disabled_list && data.disabled_list.length > 0) {
disabledDiv.innerHTML = data.disabled_list.map(d =>
`<div style="display:flex;align-items:center;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--border);">
<span style="font-family:monospace;font-size:13px;">${escapeHtml(d.id)}</span>
<div style="display:flex;align-items:center;gap:8px;">
<span style="font-size:12px;color:var(--text-muted);">禁用于 ${d.disabled_date}</span>
<button class="btn btn-success btn-sm" onclick="enableModel('${escapeHtml(d.id)}')">启用</button>
</div>
</div>`
).join('');
} else {
disabledDiv.innerHTML = '<div class="empty-state">暂无被禁用的模型</div>';
}
// 自定义添加的模型列表
const customIncludeDiv = document.getElementById('customIncludeList');
if (data.custom_include && data.custom_include.length > 0) {
customIncludeDiv.innerHTML = data.custom_include.map(m =>
`<div style="display:flex;align-items:center;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--border);">
<div>
<span style="font-family:monospace;font-size:13px;">${escapeHtml(m.id)}</span>
<span style="font-size:12px;color:var(--text-muted);margin-left:8px;">${m.param_b ? m.param_b + 'B' : '-'}</span>
</div>
<button class="btn btn-outline btn-sm" onclick="removeCustomModel('${escapeHtml(m.id)}')">移除</button>
</div>`
).join('');
} else {
customIncludeDiv.innerHTML = '<div class="empty-state">暂无自定义添加的模型</div>';
}
// 已屏蔽的模型列表
const customExcludeDiv = document.getElementById('customExcludeList');
if (data.custom_exclude && data.custom_exclude.length > 0) {
customExcludeDiv.innerHTML = data.custom_exclude.map(id =>
`<div style="display:flex;align-items:center;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--border);">
<span style="font-family:monospace;font-size:13px;">${escapeHtml(id)}</span>
<button class="btn btn-success btn-sm" onclick="unblockModel('${escapeHtml(id)}')">解除屏蔽</button>
</div>`
).join('');
} else {
customExcludeDiv.innerHTML = '<div class="empty-state">暂无屏蔽的模型</div>';
}
}
async function enableModel(modelId) {
const data = await api(`/models/enable`, { method: 'POST', body: JSON.stringify({ model_id: modelId }) });
if (data) {
toast(data.message, 'success');
loadModels();
}
}
async function disableModel(modelId) {
const data = await api(`/models/disable`, { method: 'POST', body: JSON.stringify({ model_id: modelId }) });
if (data) {
toast(data.message, 'success');
loadModels();
}
}
async function refreshModels() {
const data = await api('/refresh', { method: 'POST' });
if (data) {
toast('模型列表已刷新', 'success');
loadDashboard();
loadModels();
}
}
async function resetDisabled() {
if (!confirm('确定要重置所有被禁用的模型吗?')) return;
const data = await api('/reset-disabled', { method: 'POST' });
if (data) {
toast(data.message, 'success');
loadDashboard();
loadModels();
}
}
async function addCustomModel() {
const modelId = document.getElementById('addModelId').value.trim();
if (!modelId) { toast('请输入模型 ID', 'error'); return; }
const paramB = parseFloat(document.getElementById('addModelParamB').value) || 0;
const data = await api('/models/add', {
method: 'POST',
body: JSON.stringify({ model_id: modelId, param_b: paramB }),
});
if (data) {
toast(data.message, 'success');
document.getElementById('addModelId').value = '';