-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportal.html
More file actions
977 lines (951 loc) · 57.1 KB
/
Copy pathportal.html
File metadata and controls
977 lines (951 loc) · 57.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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ModelHub — AI 模型 API 中转站</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: { DEFAULT: '#2563eb', light: '#3b82f6', dark: '#1d4ed8', bg: '#eff6ff' },
surface: { DEFAULT: '#ffffff', muted: '#f8fafc', border: '#e2e8f0', hover: '#f1f5f9' },
text: { DEFAULT: '#0f172a', secondary: '#475569', hint: '#94a3b8' },
success: '#16a34a',
warn: '#d97706',
danger: '#dc2626',
},
fontFamily: { sans: ['Inter', 'system-ui', 'sans-serif'] },
}
}
}
</script>
<style>
body { background: #f8fafc; color: #0f172a; font-family: 'Inter', system-ui, sans-serif; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.sidebar-item { transition: all 0.15s ease; }
.sidebar-item:hover { background: #eff6ff; color: #2563eb; }
.sidebar-item.active { background: #eff6ff; color: #2563eb; font-weight: 600; border-right: 3px solid #2563eb; }
.card-hover { transition: all 0.2s ease; }
.card-hover:hover { border-color: #2563eb; box-shadow: 0 4px 12px rgba(37,99,235,0.08); transform: translateY(-1px); }
.stat-gradient-blue { background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); }
.stat-gradient-amber { background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%); }
.stat-gradient-green { background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%); }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.pulse-dot { animation: pulse-dot 2s infinite; }
.login-bg { background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #3b82f6 100%); }
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState, useEffect, useRef } = React;
// ===== SVG Icons =====
const Icons = {
dashboard: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V8.625zM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V4.125z" /></svg>,
key: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M15.75 5.25a3 3 0 013 3m3 0a6 6 0 01-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1121.75 8.25z" /></svg>,
cube: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M21 7.5l-9-5.25L3 7.5m18 0l-9 5.25m9-5.25v9l-9 5.25M3 7.5l9 5.25M3 7.5v9l9 5.25m0-9v9" /></svg>,
receipt: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 14.25l6-6m4.5-3.493V21.75l-3.75-1.5-3.75 1.5-3.75-1.5-3.75 1.5V4.757c0-1.108.806-2.057 1.907-2.185a48.507 48.507 0 0111.186 0c1.1.128 1.907 1.077 1.907 2.185z" /></svg>,
doc: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /></svg>,
copy: <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M15.666 3.888A2.25 2.25 0 0013.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 01-.75.75H9a.75.75 0 01-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 01-2.25 2.25H6.75A2.25 2.25 0 014.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 011.927-.184" /></svg>,
check: <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" /></svg>,
logout: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15m3 0l3-3m0 0l-3-3m3 3H9" /></svg>,
user: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z" /></svg>,
phone: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M2.25 6.75c0 8.284 6.716 15 15 15h2.25a2.25 2.25 0 002.25-2.25v-1.372c0-.516-.351-.966-.852-1.091l-4.423-1.106c-.44-.11-.902.055-1.173.417l-.97 1.293c-.282.376-.769.542-1.21.38a12.035 12.035 0 01-7.143-7.143c-.162-.441.004-.928.38-1.21l1.293-.97c.363-.271.527-.734.417-1.173L6.963 3.102a1.125 1.125 0 00-1.091-.852H4.5A2.25 2.25 0 002.25 4.5v2.25z" /></svg>,
settings: <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" /><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /></svg>,
};
// ===== Mock Data =====
const MOCK = {
user: { name: '恒海实业', email: '[email protected]', role: '企业客户', balance: 386.50, spent: 1613.50, totalRecharge: 2000, joinDate: '2026-03-15' },
keys: [
{ id: 1, name: '生产环境', key: 'sk-henghai-prod-a8f3e7d2c1b4', masked: 'sk-henghai-prod-a8f3****e7d2', created: '2026-03-15 10:30', lastUsed: '2 分钟前', status: 'active' },
{ id: 2, name: '测试环境', key: 'sk-henghai-test-b2c1f4a98d3e', masked: 'sk-henghai-test-b2c1****f4a9', created: '2026-03-15 10:32', lastUsed: '3 天前', status: 'active' },
{ id: 3, name: '方策 AI 工作站', key: 'sk-henghai-fc01-d9e7c3b5a2f1', masked: 'sk-henghai-fc01-d9e7****c3b5', created: '2026-03-20 14:15', lastUsed: '1 小时前', status: 'active' },
],
models: [
{ name: 'deepseek-chat', provider: 'DeepSeek', type: '对话', ctx: '64K', inputPrice: 4, outputPrice: 8, tags: ['高性价比', '中文优化'], status: 'online', color: '#4F46E5' },
{ name: 'deepseek-reasoner', provider: 'DeepSeek', type: '推理', ctx: '64K', inputPrice: 16, outputPrice: 64, tags: ['深度推理', 'CoT'], status: 'online', color: '#7C3AED' },
{ name: 'gpt-4o', provider: 'OpenAI', type: '对话', ctx: '128K', inputPrice: 50, outputPrice: 200, tags: ['多模态', 'Vision'], status: 'online', color: '#10B981' },
{ name: 'gpt-4o-mini', provider: 'OpenAI', type: '对话', ctx: '128K', inputPrice: 4, outputPrice: 16, tags: ['轻量快速', '高性价比'], status: 'online', color: '#10B981' },
{ name: 'claude-sonnet-4-5', provider: 'Anthropic', type: '对话', ctx: '200K', inputPrice: 60, outputPrice: 300, tags: ['超长上下文', '编程强'], status: 'online', color: '#D97706' },
{ name: 'glm-4-flash', provider: '智谱AI', type: '对话', ctx: '128K', inputPrice: 1, outputPrice: 4, tags: ['免费额度', '中文'], status: 'online', color: '#2563EB' },
{ name: 'qwen-plus', provider: '阿里通义', type: '对话', ctx: '128K', inputPrice: 3, outputPrice: 8, tags: ['中文优化', '工具调用'], status: 'online', color: '#F97316' },
{ name: 'cogview-4', provider: '智谱AI', type: '图片生成', ctx: '-', inputPrice: 1, outputPrice: 0, tags: ['文生图', '中文提示'], status: 'online', color: '#EC4899' },
],
bills: [
{ id: 'REQ-20260329-001', time: '2026-03-29 14:32:15', model: 'deepseek-chat', key: 'sk-henghai-prod', inputTokens: 1250, outputTokens: 860, cost: 0.012, status: 'success' },
{ id: 'REQ-20260329-002', time: '2026-03-29 14:28:03', model: 'gpt-4o', key: 'sk-henghai-fc01', inputTokens: 3200, outputTokens: 1500, cost: 0.46, status: 'success' },
{ id: 'REQ-20260329-003', time: '2026-03-29 14:15:42', model: 'deepseek-chat', key: 'sk-henghai-prod', inputTokens: 890, outputTokens: 2100, cost: 0.020, status: 'success' },
{ id: 'REQ-20260329-004', time: '2026-03-29 13:55:18', model: 'claude-sonnet-4-5', key: 'sk-henghai-fc01', inputTokens: 5600, outputTokens: 3200, cost: 1.296, status: 'success' },
{ id: 'REQ-20260329-005', time: '2026-03-29 13:40:07', model: 'deepseek-chat', key: 'sk-henghai-prod', inputTokens: 2100, outputTokens: 1800, cost: 0.023, status: 'success' },
{ id: 'REQ-20260329-006', time: '2026-03-29 12:20:33', model: 'cogview-4', key: 'sk-henghai-test', inputTokens: 0, outputTokens: 0, cost: 1.0, status: 'success' },
{ id: 'REQ-20260329-007', time: '2026-03-29 11:45:19', model: 'deepseek-reasoner', key: 'sk-henghai-prod', inputTokens: 4500, outputTokens: 8200, cost: 0.597, status: 'success' },
{ id: 'REQ-20260329-008', time: '2026-03-29 10:30:44', model: 'gpt-4o-mini', key: 'sk-henghai-fc01', inputTokens: 1800, outputTokens: 950, cost: 0.022, status: 'error' },
],
dailyUsage: [32,45,28,56,41,68,52,73,48,85,62,95,78,110,88,125,92,138,105,142,98,155,118,168,130,175,145,185,158,196],
modelDist: [
{ name: 'deepseek-chat', pct: 45, color: '#4F46E5' },
{ name: 'gpt-4o', pct: 22, color: '#10B981' },
{ name: 'claude-sonnet', pct: 18, color: '#D97706' },
{ name: 'deepseek-reasoner', pct: 8, color: '#7C3AED' },
{ name: '其他', pct: 7, color: '#94a3b8' },
],
};
// ===== Login Page =====
function LoginPage({ onLogin }) {
const [account, setAccount] = useState('');
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const handleLogin = (e) => {
e.preventDefault();
if (!account.trim() || !password.trim()) { setError('请输入账号和密码'); return; }
const a = account.trim(), p = password.trim();
if (a === 'root' && p === 'modelhub2026') {
setLoading(true); setError('');
setTimeout(() => { setLoading(false); onLogin('superadmin'); }, 800);
} else if (a === 'admin' && p === '123456') {
setLoading(true); setError('');
setTimeout(() => { setLoading(false); onLogin('client'); }, 800);
} else {
setError('账号或密码错误');
}
};
return (
<div className="min-h-screen flex">
{/* Left - Brand */}
<div className="hidden lg:flex lg:w-1/2 login-bg items-center justify-center p-12">
<div className="text-white max-w-md">
<div className="flex items-center gap-3 mb-8">
<div className="w-12 h-12 rounded-xl bg-white/20 flex items-center justify-center backdrop-blur">
<span className="text-2xl font-bold">M</span>
</div>
<div>
<div className="text-2xl font-bold">ModelHub</div>
<div className="text-sm text-white/70">AI 模型 API 中转平台</div>
</div>
</div>
<h1 className="text-3xl font-bold leading-tight mb-4">一站式 AI 模型<br/>API 管理平台</h1>
<p className="text-white/70 leading-relaxed mb-8">统一接入 OpenAI、Claude、DeepSeek、智谱等主流 AI 模型。专属 API Key、用量追踪、模型市场,让 AI 能力触手可及。</p>
<div className="grid grid-cols-3 gap-4">
<div className="bg-white/10 rounded-xl p-4 backdrop-blur">
<div className="text-2xl font-bold">20+</div>
<div className="text-xs text-white/60 mt-1">可用模型</div>
</div>
<div className="bg-white/10 rounded-xl p-4 backdrop-blur">
<div className="text-2xl font-bold">99.9%</div>
<div className="text-xs text-white/60 mt-1">服务可用性</div>
</div>
<div className="bg-white/10 rounded-xl p-4 backdrop-blur">
<div className="text-2xl font-bold">50ms</div>
<div className="text-xs text-white/60 mt-1">平均延迟</div>
</div>
</div>
</div>
</div>
{/* Right - Login Form */}
<div className="flex-1 flex items-center justify-center p-8 bg-white">
<div className="w-full max-w-sm">
<div className="lg:hidden flex items-center gap-2 mb-8">
<div className="w-10 h-10 rounded-lg bg-primary flex items-center justify-center">
<span className="text-white font-bold">M</span>
</div>
<span className="text-xl font-bold text-text">ModelHub</span>
</div>
<h2 className="text-2xl font-bold text-text mb-1">欢迎回来</h2>
<p className="text-text-hint text-sm mb-8">登录您的企业账号</p>
<form onSubmit={handleLogin} className="space-y-4">
<div>
<label className="block text-xs font-medium text-text-secondary mb-1.5">账号</label>
<input value={account} onChange={e => setAccount(e.target.value)}
placeholder="请输入企业账号或邮箱"
className="w-full border border-surface-border rounded-lg px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-colors" />
</div>
<div>
<label className="block text-xs font-medium text-text-secondary mb-1.5">密码</label>
<input type="password" value={password} onChange={e => setPassword(e.target.value)}
placeholder="请输入密码"
className="w-full border border-surface-border rounded-lg px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-colors" />
</div>
{error && <p className="text-xs text-danger">{error}</p>}
<button type="submit" disabled={loading}
className={`w-full py-2.5 rounded-lg text-sm font-medium text-white cursor-pointer transition-colors ${loading ? 'bg-primary/60' : 'bg-primary hover:bg-primary-dark'}`}>
{loading ? '登录中...' : '登 录'}
</button>
</form>
<p className="text-xs text-text-hint text-center mt-6">如需开通账号,请联系管理员</p>
</div>
</div>
</div>
);
}
// ===== Sidebar =====
function Sidebar({ active, setActive, onLogout }) {
const items = [
{ id: 'dashboard', icon: Icons.dashboard, label: '用量概览' },
{ id: 'keys', icon: Icons.key, label: 'API Keys' },
{ id: 'models', icon: Icons.cube, label: '模型库' },
{ id: 'billing', icon: Icons.receipt, label: '消费账单' },
{ id: 'account', icon: Icons.user, label: '账号信息' },
];
return (
<aside className="fixed left-0 top-0 bottom-0 w-56 bg-white border-r border-surface-border flex flex-col z-20">
<div className="px-5 py-5 border-b border-surface-border">
<div className="flex items-center gap-2.5">
<div className="w-9 h-9 rounded-lg bg-primary flex items-center justify-center">
<span className="text-white font-bold text-sm">M</span>
</div>
<div>
<div className="font-bold text-text text-sm">ModelHub</div>
<div className="text-[10px] text-text-hint">API 中转平台</div>
</div>
</div>
</div>
<nav className="flex-1 py-3 px-3 space-y-0.5">
{items.map(item => (
<button key={item.id} onClick={() => setActive(item.id)}
className={`sidebar-item w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm cursor-pointer ${active === item.id ? 'active' : 'text-text-secondary'}`}>
{item.icon}
<span>{item.label}</span>
</button>
))}
</nav>
<div className="px-3 py-2 border-t border-surface-border">
<button className="sidebar-item w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm text-text-secondary cursor-pointer">
{Icons.doc}<span>接口文档</span>
</button>
<button className="sidebar-item w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm text-text-secondary cursor-pointer">
{Icons.phone}<span>联系客服</span>
</button>
</div>
{/* User info + logout */}
<div className="px-4 py-4 border-t border-surface-border">
<div className="flex items-center gap-3 mb-3">
<div className="w-8 h-8 rounded-full bg-primary-bg flex items-center justify-center">
<span className="text-primary text-xs font-bold">{MOCK.user.name[0]}</span>
</div>
<div className="flex-1 min-w-0">
<div className="text-sm font-medium text-text truncate">{MOCK.user.name}</div>
<div className="text-[10px] text-text-hint truncate">{MOCK.user.email}</div>
</div>
</div>
<button onClick={onLogout} className="w-full flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs text-text-hint hover:text-danger hover:bg-red-50 cursor-pointer transition-colors">
{Icons.logout}<span>退出登录</span>
</button>
</div>
</aside>
);
}
// ===== TopBar =====
function TopBar({ title }) {
return (
<header className="h-14 bg-white/80 backdrop-blur border-b border-surface-border flex items-center justify-between px-6 sticky top-0 z-10">
<h1 className="text-base font-semibold text-text">{title}</h1>
<div className="flex items-center gap-3">
<div className="flex items-center gap-2 bg-primary-bg px-3 py-1.5 rounded-lg">
<span className="text-xs text-text-secondary">余额</span>
<span className="text-sm font-bold text-primary">¥{MOCK.user.balance.toFixed(2)}</span>
</div>
</div>
</header>
);
}
// ===== Dashboard =====
function DashboardPage() {
const chartRef = useRef(null);
const pieRef = useRef(null);
useEffect(() => {
const ctx = chartRef.current?.getContext('2d');
if (ctx) {
const chart = new Chart(ctx, {
type: 'line',
data: {
labels: Array.from({length: 30}, (_, i) => `${i+1}`),
datasets: [{
label: '请求数', data: MOCK.dailyUsage,
borderColor: '#2563eb', backgroundColor: 'rgba(37,99,235,0.08)',
fill: true, tension: 0.4, pointRadius: 0, pointHoverRadius: 4, borderWidth: 2,
}]
},
options: {
responsive: true, maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: {
x: { grid: { color: '#f1f5f9' }, ticks: { color: '#94a3b8', font: { size: 10 } } },
y: { grid: { color: '#f1f5f9' }, ticks: { color: '#94a3b8', font: { size: 10 } } },
},
}
});
return () => chart.destroy();
}
}, []);
useEffect(() => {
const ctx = pieRef.current?.getContext('2d');
if (ctx) {
const chart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: MOCK.modelDist.map(d => d.name),
datasets: [{ data: MOCK.modelDist.map(d => d.pct), backgroundColor: MOCK.modelDist.map(d => d.color), borderColor: '#ffffff', borderWidth: 3 }]
},
options: {
responsive: true, maintainAspectRatio: false, cutout: '65%',
plugins: { legend: { position: 'right', labels: { color: '#475569', font: { size: 11 }, padding: 12, usePointStyle: true, pointStyleWidth: 8 } } },
}
});
return () => chart.destroy();
}
}, []);
return (
<div className="space-y-6">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div className="stat-gradient-blue rounded-xl border border-blue-100 p-5">
<div className="text-xs text-text-hint uppercase tracking-wide mb-2">账户余额</div>
<div className="text-2xl font-bold text-primary">¥{MOCK.user.balance.toFixed(2)}</div>
<div className="text-xs text-text-hint mt-1">累计充值 ¥{MOCK.user.totalRecharge.toFixed(2)}</div>
</div>
<div className="stat-gradient-amber rounded-xl border border-amber-100 p-5">
<div className="text-xs text-text-hint uppercase tracking-wide mb-2">本月消费</div>
<div className="text-2xl font-bold text-warn">¥{MOCK.user.spent.toFixed(2)}</div>
<div className="text-xs text-text-hint mt-1">日均 ¥{(MOCK.user.spent / 29).toFixed(2)}</div>
</div>
<div className="stat-gradient-green rounded-xl border border-green-100 p-5">
<div className="text-xs text-text-hint uppercase tracking-wide mb-2">本月请求</div>
<div className="text-2xl font-bold text-success">2,847</div>
<div className="text-xs text-text-hint mt-1">成功率 99.6%</div>
</div>
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
<div className="lg:col-span-2 bg-white rounded-xl border border-surface-border p-5 shadow-sm">
<div className="text-sm font-medium text-text mb-4">每日请求趋势 (3月)</div>
<div className="h-56"><canvas ref={chartRef} /></div>
</div>
<div className="bg-white rounded-xl border border-surface-border p-5 shadow-sm">
<div className="text-sm font-medium text-text mb-4">模型消费分布</div>
<div className="h-56"><canvas ref={pieRef} /></div>
</div>
</div>
</div>
);
}
// ===== API Keys =====
function KeysPage() {
const [copied, setCopied] = useState(null);
const handleCopy = (key, id) => { navigator.clipboard?.writeText(key); setCopied(id); setTimeout(() => setCopied(null), 2000); };
return (
<div className="space-y-6">
<div className="bg-white rounded-xl border border-surface-border shadow-sm overflow-hidden">
<div className="px-5 py-3 border-b border-surface-border bg-amber-50">
<p className="text-xs text-warn">API Key 仅在创建时完整显示,请妥善保管。如需新增或重置 Key,请联系管理员。</p>
</div>
<table className="w-full">
<thead>
<tr className="border-b border-surface-border bg-surface-muted">
{['名称', 'API Key', '创建时间', '最近使用', '状态'].map(h => (
<th key={h} className="text-left px-5 py-3 text-xs font-medium text-text-hint uppercase">{h}</th>
))}
</tr>
</thead>
<tbody>
{MOCK.keys.map(k => (
<tr key={k.id} className="border-b border-surface-border/50 hover:bg-surface-hover transition-colors">
<td className="px-5 py-4 text-sm font-medium text-text">{k.name}</td>
<td className="px-5 py-4">
<div className="flex items-center gap-2">
<code className="text-sm text-text-secondary bg-surface-muted px-2.5 py-1 rounded font-mono text-xs">{k.masked}</code>
<button onClick={() => handleCopy(k.key, k.id)} className="text-text-hint hover:text-primary cursor-pointer transition-colors" title="复制完整 Key">
{copied === k.id ? <span className="text-success">{Icons.check}</span> : Icons.copy}
</button>
</div>
</td>
<td className="px-5 py-4 text-sm text-text-hint">{k.created}</td>
<td className="px-5 py-4 text-sm text-text-hint">{k.lastUsed}</td>
<td className="px-5 py-4">
<span className="inline-flex items-center gap-1.5 text-xs text-success font-medium">
<span className="w-1.5 h-1.5 rounded-full bg-success pulse-dot" />活跃
</span>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}
// ===== Models =====
function ModelsPage() {
const [filter, setFilter] = useState('all');
const types = ['all', '对话', '推理', '图片生成'];
const filtered = filter === 'all' ? MOCK.models : MOCK.models.filter(m => m.type === filter);
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div />
<div className="flex gap-1 bg-surface-muted rounded-lg p-1 border border-surface-border">
{types.map(t => (
<button key={t} onClick={() => setFilter(t)}
className={`px-3 py-1.5 rounded-md text-xs cursor-pointer transition-colors ${filter === t ? 'bg-primary text-white shadow-sm' : 'text-text-secondary hover:text-text'}`}>
{t === 'all' ? '全部' : t}
</button>
))}
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
{filtered.map(m => (
<div key={m.name} className="card-hover bg-white rounded-xl border border-surface-border p-5 cursor-pointer shadow-sm">
<div className="flex items-start justify-between mb-3">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-lg flex items-center justify-center text-white font-bold text-xs" style={{background: m.color}}>
{m.provider.slice(0, 2)}
</div>
<div>
<div className="text-sm font-semibold text-text">{m.name}</div>
<div className="text-xs text-text-hint">{m.provider}</div>
</div>
</div>
<span className={`text-[10px] px-2 py-0.5 rounded-full font-medium ${m.status === 'online' ? 'text-success bg-green-50' : 'text-warn bg-amber-50'}`}>
{m.status === 'online' ? '在线' : '维护中'}
</span>
</div>
<div className="flex flex-wrap gap-1.5 mb-4">
{m.tags.map(tag => (
<span key={tag} className="text-[10px] text-text-hint bg-surface-muted px-2 py-0.5 rounded border border-surface-border">{tag}</span>
))}
<span className="text-[10px] text-text-hint bg-surface-muted px-2 py-0.5 rounded border border-surface-border">上下文 {m.ctx}</span>
</div>
<div className="flex items-center justify-between pt-3 border-t border-surface-border">
<div className="text-xs text-text-hint">
输入 <span className="text-primary font-semibold">¥{m.inputPrice}</span>
{m.outputPrice > 0 && <> / 输出 <span className="text-primary font-semibold">¥{m.outputPrice}</span></>}
{m.outputPrice === 0 && m.type === '图片生成' && <span className="text-text-hint"> /张</span>}
</div>
<span className="text-[10px] text-text-hint">/百万token</span>
</div>
</div>
))}
</div>
</div>
);
}
// ===== Billing =====
function BillingPage() {
return (
<div className="space-y-6">
<div className="grid grid-cols-3 gap-4">
<div className="stat-gradient-blue rounded-xl border border-blue-100 p-4">
<div className="text-xs text-text-hint mb-1">总充值</div>
<div className="text-lg font-bold text-primary">¥{MOCK.user.totalRecharge.toFixed(2)}</div>
</div>
<div className="stat-gradient-amber rounded-xl border border-amber-100 p-4">
<div className="text-xs text-text-hint mb-1">已消费</div>
<div className="text-lg font-bold text-warn">¥{MOCK.user.spent.toFixed(2)}</div>
</div>
<div className="stat-gradient-green rounded-xl border border-green-100 p-4">
<div className="text-xs text-text-hint mb-1">剩余额度</div>
<div className="text-lg font-bold text-success">¥{MOCK.user.balance.toFixed(2)}</div>
</div>
</div>
<div className="bg-white rounded-xl border border-surface-border shadow-sm overflow-hidden">
<div className="px-5 py-3 border-b border-surface-border flex items-center justify-between">
<span className="text-sm font-medium text-text">消费明细</span>
<div className="flex gap-2">
<select className="bg-surface-muted border border-surface-border rounded-lg px-3 py-1.5 text-xs text-text-secondary cursor-pointer">
<option>全部模型</option>
{[...new Set(MOCK.bills.map(b => b.model))].map(m => <option key={m}>{m}</option>)}
</select>
</div>
</div>
<table className="w-full">
<thead>
<tr className="border-b border-surface-border bg-surface-muted">
{['请求ID', '时间', '模型', 'API Key', '输入 Token', '输出 Token', '费用', '状态'].map(h => (
<th key={h} className="text-left px-4 py-3 text-xs font-medium text-text-hint uppercase">{h}</th>
))}
</tr>
</thead>
<tbody>
{MOCK.bills.map(b => (
<tr key={b.id} className="border-b border-surface-border/50 hover:bg-surface-hover transition-colors">
<td className="px-4 py-3 text-xs text-text-hint font-mono">{b.id.slice(-7)}</td>
<td className="px-4 py-3 text-xs text-text-hint">{b.time.slice(11)}</td>
<td className="px-4 py-3 text-xs text-text font-medium">{b.model}</td>
<td className="px-4 py-3 text-xs text-text-hint font-mono">{b.key.slice(-8)}</td>
<td className="px-4 py-3 text-xs text-text-secondary">{b.inputTokens.toLocaleString()}</td>
<td className="px-4 py-3 text-xs text-text-secondary">{b.outputTokens.toLocaleString()}</td>
<td className="px-4 py-3 text-xs text-primary font-semibold">¥{b.cost.toFixed(3)}</td>
<td className="px-4 py-3">
<span className={`text-[10px] px-2 py-0.5 rounded-full font-medium ${b.status === 'success' ? 'text-success bg-green-50' : 'text-danger bg-red-50'}`}>
{b.status === 'success' ? '成功' : '失败'}
</span>
</td>
</tr>
))}
</tbody>
</table>
<div className="px-4 py-3 border-t border-surface-border flex items-center justify-between bg-surface-muted">
<span className="text-xs text-text-hint">共 {MOCK.bills.length} 条记录</span>
<div className="flex gap-1">
<button className="px-3 py-1 bg-white border border-surface-border text-xs text-text-hint rounded cursor-pointer hover:bg-surface-hover">上一页</button>
<button className="px-3 py-1 bg-primary text-xs text-white rounded cursor-pointer">1</button>
<button className="px-3 py-1 bg-white border border-surface-border text-xs text-text-hint rounded cursor-pointer hover:bg-surface-hover">下一页</button>
</div>
</div>
</div>
</div>
);
}
// ===== Account =====
function AccountPage() {
return (
<div className="max-w-2xl space-y-6">
<div className="bg-white rounded-xl border border-surface-border shadow-sm p-6">
<h2 className="text-base font-semibold text-text mb-5">基本信息</h2>
<div className="flex items-center gap-4 mb-6">
<div className="w-16 h-16 rounded-full bg-primary-bg flex items-center justify-center">
<span className="text-primary text-xl font-bold">{MOCK.user.name[0]}</span>
</div>
<div>
<div className="text-lg font-bold text-text">{MOCK.user.name}</div>
<div className="text-sm text-text-hint">{MOCK.user.role}</div>
</div>
</div>
<div className="space-y-4">
{[
['企业名称', MOCK.user.name],
['登录邮箱', MOCK.user.email],
['账户角色', MOCK.user.role],
['注册时间', MOCK.user.joinDate],
['API Keys', `${MOCK.keys.length} 个活跃`],
].map(([label, value]) => (
<div key={label} className="flex items-center py-3 border-b border-surface-border last:border-0">
<span className="w-28 text-sm text-text-hint flex-shrink-0">{label}</span>
<span className="text-sm text-text font-medium">{value}</span>
</div>
))}
</div>
</div>
<div className="bg-white rounded-xl border border-surface-border shadow-sm p-6">
<h2 className="text-base font-semibold text-text mb-5">额度信息</h2>
<div className="grid grid-cols-3 gap-4 mb-4">
<div className="text-center p-4 rounded-lg bg-surface-muted">
<div className="text-xl font-bold text-primary">¥{MOCK.user.totalRecharge.toFixed(0)}</div>
<div className="text-xs text-text-hint mt-1">累计充值</div>
</div>
<div className="text-center p-4 rounded-lg bg-surface-muted">
<div className="text-xl font-bold text-warn">¥{MOCK.user.spent.toFixed(0)}</div>
<div className="text-xs text-text-hint mt-1">已消费</div>
</div>
<div className="text-center p-4 rounded-lg bg-surface-muted">
<div className="text-xl font-bold text-success">¥{MOCK.user.balance.toFixed(0)}</div>
<div className="text-xs text-text-hint mt-1">当前余额</div>
</div>
</div>
{/* Usage bar */}
<div>
<div className="flex justify-between text-xs text-text-hint mb-1.5">
<span>额度使用</span>
<span>{((MOCK.user.spent / MOCK.user.totalRecharge) * 100).toFixed(1)}%</span>
</div>
<div className="w-full h-2.5 bg-surface-muted rounded-full overflow-hidden">
<div className="h-full bg-primary rounded-full transition-all" style={{width: `${(MOCK.user.spent / MOCK.user.totalRecharge) * 100}%`}} />
</div>
</div>
</div>
<div className="bg-white rounded-xl border border-surface-border shadow-sm p-6">
<h2 className="text-base font-semibold text-text mb-3">API 对接信息</h2>
<p className="text-xs text-text-hint mb-4">将以下配置填入您的应用 .env 文件即可对接</p>
<div className="bg-slate-900 rounded-lg p-4 font-mono text-xs text-green-400 space-y-1">
<div><span className="text-slate-500"># ModelHub API 配置</span></div>
<div>OPENAI_BASE_URL=<span className="text-blue-300">https://api.modelhub.cn/v1</span></div>
<div>OPENAI_API_KEY=<span className="text-amber-300">sk-henghai-prod-a8f3****e7d2</span></div>
<div>DEFAULT_MODEL=<span className="text-blue-300">deepseek-chat</span></div>
</div>
</div>
</div>
);
}
// ===== Admin: Model Pricing =====
function AdminPricingPage() {
const [models, setModels] = useState([
{ name: 'deepseek-chat', provider: 'DeepSeek', costIn: 1, costOut: 2, sellIn: 4, sellOut: 8, multiplier: 4.0, enabled: true },
{ name: 'deepseek-reasoner', provider: 'DeepSeek', costIn: 4, costOut: 16, sellIn: 16, sellOut: 64, multiplier: 4.0, enabled: true },
{ name: 'gpt-4o', provider: 'OpenAI', costIn: 17.5, costOut: 70, sellIn: 50, sellOut: 200, multiplier: 2.86, enabled: true },
{ name: 'gpt-4o-mini', provider: 'OpenAI', costIn: 1, costOut: 4.2, sellIn: 4, sellOut: 16, multiplier: 3.8, enabled: true },
{ name: 'claude-sonnet-4-5', provider: 'Anthropic', costIn: 21, costOut: 105, sellIn: 60, sellOut: 300, multiplier: 2.86, enabled: true },
{ name: 'glm-4-flash', provider: '智谱AI', costIn: 0.5, costOut: 0.5, sellIn: 1, sellOut: 4, multiplier: 4.0, enabled: true },
{ name: 'qwen-plus', provider: '阿里通义', costIn: 0.8, costOut: 2, sellIn: 3, sellOut: 8, multiplier: 3.75, enabled: true },
{ name: 'cogview-4', provider: '智谱AI', costIn: 0.2, costOut: 0, sellIn: 1, sellOut: 0, multiplier: 5.0, enabled: true },
{ name: 'dall-e-3', provider: 'OpenAI', costIn: 4, costOut: 0, sellIn: 8, sellOut: 0, multiplier: 2.0, enabled: false },
]);
const updateModel = (idx, field, val) => {
setModels(prev => {
const next = [...prev];
const m = { ...next[idx], [field]: val };
if (field === 'multiplier') {
m.sellIn = +(m.costIn * val).toFixed(1);
m.sellOut = +(m.costOut * val).toFixed(1);
}
next[idx] = m;
return next;
});
};
const [saved, setSaved] = useState(false);
const handleSave = () => { setSaved(true); setTimeout(() => setSaved(false), 2000); };
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<p className="text-xs text-text-hint mt-1">设置每个模型的售价倍率,自动计算客户售价</p>
</div>
<button onClick={handleSave} className={`px-4 py-2 rounded-lg text-sm font-medium cursor-pointer transition-colors ${saved ? 'bg-success text-white' : 'bg-primary text-white hover:bg-primary-dark'}`}>
{saved ? '已保存' : '保存配置'}
</button>
</div>
<div className="bg-white rounded-xl border border-surface-border shadow-sm overflow-hidden">
<table className="w-full">
<thead>
<tr className="border-b border-surface-border bg-surface-muted">
{['状态', '模型', '厂商', '成本/入(¥/M)', '成本/出(¥/M)', '倍率', '售价/入(¥/M)', '售价/出(¥/M)', '利润率'].map(h => (
<th key={h} className="text-left px-4 py-3 text-xs font-medium text-text-hint uppercase">{h}</th>
))}
</tr>
</thead>
<tbody>
{models.map((m, i) => {
const margin = m.costIn > 0 ? (((m.sellIn - m.costIn) / m.costIn) * 100).toFixed(0) : '—';
return (
<tr key={m.name} className="border-b border-surface-border/50 hover:bg-surface-hover transition-colors">
<td className="px-4 py-3">
<button onClick={() => updateModel(i, 'enabled', !m.enabled)} className="cursor-pointer">
<span className={`inline-block w-9 h-5 rounded-full relative transition-colors ${m.enabled ? 'bg-success' : 'bg-gray-300'}`}>
<span className={`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform ${m.enabled ? 'left-[18px]' : 'left-0.5'}`} />
</span>
</button>
</td>
<td className="px-4 py-3 text-sm font-medium text-text">{m.name}</td>
<td className="px-4 py-3 text-xs text-text-hint">{m.provider}</td>
<td className="px-4 py-3 text-xs text-text-secondary">¥{m.costIn}</td>
<td className="px-4 py-3 text-xs text-text-secondary">¥{m.costOut}</td>
<td className="px-4 py-3">
<input type="number" step="0.1" min="1" max="10" value={m.multiplier}
onChange={e => updateModel(i, 'multiplier', parseFloat(e.target.value) || 1)}
className="w-16 border border-surface-border rounded px-2 py-1 text-sm text-center font-semibold text-primary focus:outline-none focus:ring-2 focus:ring-primary/30" />
<span className="text-[10px] text-text-hint ml-1">x</span>
</td>
<td className="px-4 py-3 text-sm font-semibold text-primary">¥{m.sellIn}</td>
<td className="px-4 py-3 text-sm font-semibold text-primary">¥{m.sellOut}</td>
<td className="px-4 py-3">
<span className={`text-xs font-medium px-2 py-0.5 rounded-full ${parseInt(margin) >= 200 ? 'text-success bg-green-50' : 'text-warn bg-amber-50'}`}>
+{margin}%
</span>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
);
}
// ===== Admin: Client Management =====
function AdminClientsPage() {
const clients = [
{ name: '恒海实业', email: '[email protected]', keys: 3, balance: 386.50, spent: 1613.50, group: '企业版', status: 'active', lastActive: '2 分钟前' },
{ name: '天降保安', email: '[email protected]', keys: 1, balance: 220.00, spent: 780.00, group: '基础版', status: 'active', lastActive: '1 小时前' },
{ name: '曼时传媒', email: '[email protected]', keys: 2, balance: 1250.00, spent: 4750.00, group: 'VIP', status: 'active', lastActive: '30 分钟前' },
{ name: '瑞华科技', email: '[email protected]', keys: 1, balance: 0, spent: 500.00, group: '基础版', status: 'expired', lastActive: '15 天前' },
{ name: '盛达贸易', email: '[email protected]', keys: 2, balance: 95.00, spent: 905.00, group: '企业版', status: 'active', lastActive: '3 小时前' },
];
const totalRevenue = clients.reduce((s, c) => s + c.spent, 0);
const totalBalance = clients.reduce((s, c) => s + c.balance, 0);
return (
<div className="space-y-6">
<div className="grid grid-cols-4 gap-4">
<div className="stat-gradient-blue rounded-xl border border-blue-100 p-4">
<div className="text-xs text-text-hint mb-1">总客户数</div>
<div className="text-xl font-bold text-primary">{clients.length}</div>
</div>
<div className="stat-gradient-green rounded-xl border border-green-100 p-4">
<div className="text-xs text-text-hint mb-1">活跃客户</div>
<div className="text-xl font-bold text-success">{clients.filter(c => c.status === 'active').length}</div>
</div>
<div className="stat-gradient-amber rounded-xl border border-amber-100 p-4">
<div className="text-xs text-text-hint mb-1">总营收</div>
<div className="text-xl font-bold text-warn">¥{totalRevenue.toFixed(0)}</div>
</div>
<div className="bg-purple-50 rounded-xl border border-purple-100 p-4">
<div className="text-xs text-text-hint mb-1">预存余额</div>
<div className="text-xl font-bold text-purple-600">¥{totalBalance.toFixed(0)}</div>
</div>
</div>
<div className="bg-white rounded-xl border border-surface-border shadow-sm overflow-hidden">
<table className="w-full">
<thead>
<tr className="border-b border-surface-border bg-surface-muted">
{['企业名称', '邮箱', '套餐', 'Keys', '余额', '消费', '最近活跃', '状态'].map(h => (
<th key={h} className="text-left px-4 py-3 text-xs font-medium text-text-hint uppercase">{h}</th>
))}
</tr>
</thead>
<tbody>
{clients.map(c => (
<tr key={c.name} className="border-b border-surface-border/50 hover:bg-surface-hover transition-colors cursor-pointer">
<td className="px-4 py-3 text-sm font-medium text-text">{c.name}</td>
<td className="px-4 py-3 text-xs text-text-hint">{c.email}</td>
<td className="px-4 py-3">
<span className={`text-[10px] px-2 py-0.5 rounded-full font-medium ${
c.group === 'VIP' ? 'text-purple-700 bg-purple-50' :
c.group === '企业版' ? 'text-primary bg-primary-bg' :
'text-text-hint bg-surface-muted'
}`}>{c.group}</span>
</td>
<td className="px-4 py-3 text-sm text-text-secondary">{c.keys}</td>
<td className="px-4 py-3 text-sm font-medium text-success">¥{c.balance.toFixed(0)}</td>
<td className="px-4 py-3 text-sm text-text-secondary">¥{c.spent.toFixed(0)}</td>
<td className="px-4 py-3 text-xs text-text-hint">{c.lastActive}</td>
<td className="px-4 py-3">
<span className={`inline-flex items-center gap-1.5 text-xs font-medium ${c.status === 'active' ? 'text-success' : 'text-danger'}`}>
<span className={`w-1.5 h-1.5 rounded-full ${c.status === 'active' ? 'bg-success pulse-dot' : 'bg-danger'}`} />
{c.status === 'active' ? '活跃' : '过期'}
</span>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}
// ===== Admin: Channels =====
function AdminChannelsPage() {
const channels = [
{ name: 'DeepSeek 主力', provider: 'DeepSeek', endpoint: 'api.deepseek.com', keys: 3, priority: 1, successRate: 99.8, avgLatency: 320, status: 'active', requests24h: 1856 },
{ name: 'OpenAI 官方', provider: 'OpenAI', endpoint: 'api.openai.com', keys: 2, priority: 1, successRate: 99.5, avgLatency: 580, status: 'active', requests24h: 642 },
{ name: 'Anthropic', provider: 'Anthropic', endpoint: 'api.anthropic.com', keys: 1, priority: 1, successRate: 99.2, avgLatency: 450, status: 'active', requests24h: 384 },
{ name: '智谱 GLM', provider: '智谱AI', endpoint: 'open.bigmodel.cn', keys: 2, priority: 2, successRate: 98.9, avgLatency: 280, status: 'active', requests24h: 223 },
{ name: '通义千问', provider: '阿里通义', endpoint: 'dashscope.aliyuncs.com', keys: 1, priority: 2, successRate: 99.1, avgLatency: 350, status: 'active', requests24h: 95 },
{ name: 'DeepSeek 备用', provider: 'DeepSeek', endpoint: 'api.deepseek.com', keys: 1, priority: 3, successRate: 100, avgLatency: 310, status: 'standby', requests24h: 0 },
];
return (
<div className="space-y-6">
<div className="bg-white rounded-xl border border-surface-border shadow-sm overflow-hidden">
<table className="w-full">
<thead>
<tr className="border-b border-surface-border bg-surface-muted">
{['渠道名称', '厂商', '端点', 'Keys', '优先级', '成功率', '平均延迟', '24h请求', '状态'].map(h => (
<th key={h} className="text-left px-4 py-3 text-xs font-medium text-text-hint uppercase">{h}</th>
))}
</tr>
</thead>
<tbody>
{channels.map(c => (
<tr key={c.name} className="border-b border-surface-border/50 hover:bg-surface-hover transition-colors cursor-pointer">
<td className="px-4 py-3 text-sm font-medium text-text">{c.name}</td>
<td className="px-4 py-3 text-xs text-text-hint">{c.provider}</td>
<td className="px-4 py-3 text-xs text-text-hint font-mono">{c.endpoint}</td>
<td className="px-4 py-3 text-sm text-text-secondary">{c.keys}</td>
<td className="px-4 py-3">
<span className={`text-xs font-medium px-2 py-0.5 rounded-full ${c.priority === 1 ? 'text-primary bg-primary-bg' : c.priority === 2 ? 'text-warn bg-amber-50' : 'text-text-hint bg-surface-muted'}`}>
P{c.priority}
</span>
</td>
<td className="px-4 py-3">
<span className={`text-sm font-medium ${c.successRate >= 99.5 ? 'text-success' : c.successRate >= 99 ? 'text-warn' : 'text-danger'}`}>{c.successRate}%</span>
</td>
<td className="px-4 py-3 text-sm text-text-secondary">{c.avgLatency}ms</td>
<td className="px-4 py-3 text-sm text-text-secondary">{c.requests24h.toLocaleString()}</td>
<td className="px-4 py-3">
<span className={`inline-flex items-center gap-1.5 text-xs font-medium ${c.status === 'active' ? 'text-success' : 'text-text-hint'}`}>
<span className={`w-1.5 h-1.5 rounded-full ${c.status === 'active' ? 'bg-success pulse-dot' : 'bg-gray-300'}`} />
{c.status === 'active' ? '运行中' : '待命'}
</span>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}
// ===== Admin: Profit Dashboard =====
function AdminProfitPage() {
const monthly = [
{ month: '2026-01', revenue: 2850, cost: 820, profit: 2030 },
{ month: '2026-02', revenue: 4200, cost: 1150, profit: 3050 },
{ month: '2026-03', revenue: 8548, cost: 2340, profit: 6208 },
];
const chartRef = useRef(null);
useEffect(() => {
const ctx = chartRef.current?.getContext('2d');
if (ctx) {
const chart = new Chart(ctx, {
type: 'bar',
data: {
labels: monthly.map(m => m.month),
datasets: [
{ label: '营收', data: monthly.map(m => m.revenue), backgroundColor: '#2563eb', borderRadius: 4 },
{ label: '成本', data: monthly.map(m => m.cost), backgroundColor: '#94a3b8', borderRadius: 4 },
{ label: '利润', data: monthly.map(m => m.profit), backgroundColor: '#16a34a', borderRadius: 4 },
]
},
options: {
responsive: true, maintainAspectRatio: false,
plugins: { legend: { labels: { color: '#475569', font: { size: 11 } } } },
scales: {
x: { grid: { display: false }, ticks: { color: '#94a3b8' } },
y: { grid: { color: '#f1f5f9' }, ticks: { color: '#94a3b8', callback: v => '¥' + v } },
},
}
});
return () => chart.destroy();
}
}, []);
const latest = monthly[monthly.length - 1];
return (
<div className="space-y-6">
<div className="grid grid-cols-4 gap-4">
<div className="stat-gradient-blue rounded-xl border border-blue-100 p-4">
<div className="text-xs text-text-hint mb-1">本月营收</div>
<div className="text-xl font-bold text-primary">¥{latest.revenue.toLocaleString()}</div>
</div>
<div className="bg-surface-muted rounded-xl border border-surface-border p-4">
<div className="text-xs text-text-hint mb-1">本月成本</div>
<div className="text-xl font-bold text-text-secondary">¥{latest.cost.toLocaleString()}</div>
</div>
<div className="stat-gradient-green rounded-xl border border-green-100 p-4">
<div className="text-xs text-text-hint mb-1">本月利润</div>
<div className="text-xl font-bold text-success">¥{latest.profit.toLocaleString()}</div>
</div>
<div className="stat-gradient-amber rounded-xl border border-amber-100 p-4">
<div className="text-xs text-text-hint mb-1">利润率</div>
<div className="text-xl font-bold text-warn">{((latest.profit / latest.revenue) * 100).toFixed(1)}%</div>
</div>
</div>
<div className="bg-white rounded-xl border border-surface-border shadow-sm p-5">
<div className="text-sm font-medium text-text mb-4">月度营收 / 成本 / 利润</div>
<div className="h-64"><canvas ref={chartRef} /></div>
</div>
<div className="bg-white rounded-xl border border-surface-border shadow-sm overflow-hidden">
<table className="w-full">
<thead>
<tr className="border-b border-surface-border bg-surface-muted">
{['月份', '营收', '成本', '利润', '利润率'].map(h => (
<th key={h} className="text-left px-5 py-3 text-xs font-medium text-text-hint uppercase">{h}</th>
))}
</tr>
</thead>
<tbody>
{monthly.map(m => (
<tr key={m.month} className="border-b border-surface-border/50">
<td className="px-5 py-3 text-sm text-text font-medium">{m.month}</td>
<td className="px-5 py-3 text-sm text-primary font-medium">¥{m.revenue.toLocaleString()}</td>
<td className="px-5 py-3 text-sm text-text-secondary">¥{m.cost.toLocaleString()}</td>
<td className="px-5 py-3 text-sm text-success font-semibold">¥{m.profit.toLocaleString()}</td>
<td className="px-5 py-3">
<span className="text-xs font-medium text-success bg-green-50 px-2 py-0.5 rounded-full">{((m.profit / m.revenue) * 100).toFixed(1)}%</span>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}
// ===== Admin Sidebar =====
function AdminSidebar({ active, setActive, onLogout }) {
const items = [
{ id: 'admin-profit', icon: Icons.dashboard, label: '利润看板' },
{ id: 'admin-pricing', icon: Icons.receipt, label: '模型定价' },
{ id: 'admin-clients', icon: Icons.user, label: '客户管理' },
{ id: 'admin-channels', icon: Icons.cube, label: '渠道管理' },
];
return (
<aside className="fixed left-0 top-0 bottom-0 w-56 bg-white border-r border-surface-border flex flex-col z-20">
<div className="px-5 py-5 border-b border-surface-border">
<div className="flex items-center gap-2.5">
<div className="w-9 h-9 rounded-lg bg-red-600 flex items-center justify-center">
<span className="text-white font-bold text-sm">M</span>
</div>
<div>
<div className="font-bold text-text text-sm">ModelHub</div>
<div className="text-[10px] text-danger font-medium">超级管理员</div>
</div>
</div>
</div>
<nav className="flex-1 py-3 px-3 space-y-0.5">
{items.map(item => (
<button key={item.id} onClick={() => setActive(item.id)}
className={`sidebar-item w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm cursor-pointer ${active === item.id ? 'active' : 'text-text-secondary'}`}>
{item.icon}
<span>{item.label}</span>
</button>
))}
</nav>
<div className="px-4 py-4 border-t border-surface-border">
<div className="flex items-center gap-3 mb-3">
<div className="w-8 h-8 rounded-full bg-red-100 flex items-center justify-center">
<span className="text-danger text-xs font-bold">S</span>
</div>
<div className="flex-1 min-w-0">
<div className="text-sm font-medium text-text">超级管理员</div>
<div className="text-[10px] text-text-hint">[email protected]</div>
</div>
</div>
<button onClick={onLogout} className="w-full flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs text-text-hint hover:text-danger hover:bg-red-50 cursor-pointer transition-colors">
{Icons.logout}<span>退出登录</span>
</button>
</div>
</aside>
);
}
// ===== App =====
const CLIENT_TITLES = { dashboard: '用量概览', keys: 'API Keys', models: '模型库', billing: '消费账单', account: '账号信息' };
const ADMIN_TITLES = { 'admin-profit': '利润看板', 'admin-pricing': '模型定价', 'admin-clients': '客户管理', 'admin-channels': '渠道管理' };
function App() {
const [role, setRole] = useState(null); // null | 'client' | 'superadmin'
const [active, setActive] = useState('dashboard');
if (!role) return <LoginPage onLogin={(r) => { setRole(r); setActive(r === 'superadmin' ? 'admin-profit' : 'dashboard'); }} />;
const handleLogout = () => { setRole(null); setActive('dashboard'); };
if (role === 'superadmin') {
const adminPages = { 'admin-profit': AdminProfitPage, 'admin-pricing': AdminPricingPage, 'admin-clients': AdminClientsPage, 'admin-channels': AdminChannelsPage };
const Page = adminPages[active] || AdminProfitPage;
return (
<div className="min-h-screen bg-surface-muted">
<AdminSidebar active={active} setActive={setActive} onLogout={handleLogout} />
<div className="ml-56">
<TopBar title={ADMIN_TITLES[active] || '管理后台'} />
<main className="p-6"><Page /></main>
</div>
</div>
);
}
const clientPages = { dashboard: DashboardPage, keys: KeysPage, models: ModelsPage, billing: BillingPage, account: AccountPage };
const Page = clientPages[active] || DashboardPage;
return (
<div className="min-h-screen bg-surface-muted">
<Sidebar active={active} setActive={setActive} onLogout={handleLogout} />
<div className="ml-56">
<TopBar title={CLIENT_TITLES[active] || ''} />
<main className="p-6"><Page /></main>
</div>
</div>
);
}
ReactDOM.createRoot(document.getElementById('root')).render(<App />);
</script>
</body>
</html>