File size: 73,636 Bytes
c58b8ed |
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 |
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API日志管理中心</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #e3f2fd 0%, #f0f8ff 100%);
min-height: 100vh;
color: #333;
}
.container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
.header {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
text-align: center;
}
.header h1 {
color: #1976d2;
font-size: 2.5em;
margin-bottom: 10px;
font-weight: 600;
}
.header p {
color: #666;
font-size: 1.1em;
}
.login-form {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 40px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
max-width: 400px;
margin: 50px auto;
}
.login-form h2 {
color: #1976d2;
margin-bottom: 30px;
text-align: center;
font-size: 1.8em;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #555;
}
.form-control {
width: 100%;
padding: 12px 16px;
border: 2px solid #e3f2fd;
border-radius: 12px;
font-size: 14px;
transition: all 0.3s ease;
background: rgba(255, 255, 255, 0.8);
}
.form-control:focus {
outline: none;
border-color: #1976d2;
box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 12px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-block;
text-align: center;
}
.btn-primary {
background: linear-gradient(45deg, #1976d2, #42a5f5);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(25, 118, 210, 0.3);
}
.btn-success {
background: linear-gradient(45deg, #4caf50, #66bb6a);
color: white;
}
.btn-warning {
background: linear-gradient(45deg, #ff9800, #ffb74d);
color: white;
}
.btn-danger {
background: linear-gradient(45deg, #f44336, #ef5350);
color: white;
}
.btn-secondary {
background: linear-gradient(45deg, #6c757d, #868e96);
color: white;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.dashboard {
display: none;
}
.nav-tabs {
display: flex;
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 8px;
margin-bottom: 30px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.nav-tab {
flex: 1;
padding: 12px 20px;
text-align: center;
background: transparent;
border: none;
border-radius: 10px;
cursor: pointer;
font-weight: 500;
transition: all 0.3s ease;
color: #666;
}
.nav-tab.active {
background: linear-gradient(45deg, #1976d2, #42a5f5);
color: white;
box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.card {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.card-title {
color: #1976d2;
font-size: 1.5em;
margin-bottom: 20px;
font-weight: 600;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.stat-card {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 25px;
text-align: center;
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
transition: transform 0.3s ease;
}
.stat-card:hover {
transform: translateY(-5px);
}
.stat-value {
font-size: 2.5em;
font-weight: 700;
color: #1976d2;
margin-bottom: 10px;
}
.stat-label {
color: #666;
font-size: 1em;
font-weight: 500;
}
/* 日志筛选区域样式 */
.log-filters {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.filter-row {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 15px;
margin-bottom: 15px;
}
.filter-row:last-child {
grid-template-columns: 1fr 1fr auto auto auto auto auto;
align-items: end;
}
.filter-group {
display: flex;
flex-direction: column;
}
.filter-group label {
color: #666;
font-size: 12px;
margin-bottom: 5px;
}
.filter-input {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 8px;
font-size: 14px;
background: white;
}
.filter-input:focus {
outline: none;
border-color: #1976d2;
box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}
.date-range {
display: flex;
align-items: center;
gap: 10px;
}
.date-separator {
color: #666;
font-weight: bold;
}
/* 表格样式 */
.table-container {
overflow-x: auto;
border-radius: 15px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
background: white;
}
.logs-table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
.logs-table thead {
background: linear-gradient(45deg, #1976d2, #42a5f5);
}
.logs-table th {
padding: 12px 8px;
text-align: left;
font-weight: 500;
color: white;
font-size: 13px;
white-space: nowrap;
}
.logs-table td {
padding: 10px 8px;
border-bottom: 1px solid #f0f0f0;
font-size: 13px;
vertical-align: middle;
}
.logs-table tbody tr:hover {
background-color: #f8f9fa;
}
.logs-table tbody tr:nth-child(even) {
background-color: #fafafa;
}
/* 日志表格特殊列样式 */
.log-time {
color: #333;
white-space: nowrap;
min-width: 140px;
}
.log-user {
display: flex;
align-items: center;
gap: 8px;
min-width: 100px;
}
.user-avatar {
width: 24px;
height: 24px;
border-radius: 50%;
background: #42a5f5;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-weight: bold;
}
.log-type-badge {
padding: 4px 8px;
border-radius: 12px;
font-size: 11px;
font-weight: 500;
text-align: center;
min-width: 60px;
}
.type-normal {
background: #e8f5e8;
color: #2e7d32;
}
.type-stream {
background: #e3f2fd;
color: #1976d2;
}
.type-fake-stream {
background: #fff3e0;
color: #f57c00;
}
.log-model {
background: #f3e5f5;
color: #7b1fa2;
padding: 4px 8px;
border-radius: 12px;
font-size: 11px;
text-align: center;
font-weight: 500;
}
.log-timing {
color: #4caf50;
font-size: 12px;
}
.log-status {
text-align: center;
}
.status-success {
color: #4caf50;
}
.status-error {
color: #f44336;
}
.log-tokens {
color: #666;
font-size: 12px;
text-align: right;
}
.log-detail {
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 12px;
color: #666;
}
/* 分页样式 */
.pagination-container {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 20px;
padding: 15px 0;
}
.pagination-info {
color: #666;
font-size: 14px;
}
.pagination-controls {
display: flex;
align-items: center;
gap: 10px;
}
.pagination-btn {
padding: 8px 16px;
border: 1px solid #ddd;
border-radius: 8px;
background: white;
cursor: pointer;
font-size: 14px;
transition: all 0.3s ease;
}
.pagination-btn:hover:not(:disabled) {
background: #1976d2;
color: white;
border-color: #1976d2;
}
.pagination-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.pagination-input {
width: 60px;
padding: 6px;
border: 1px solid #ddd;
border-radius: 4px;
text-align: center;
}
.page-size-select {
padding: 6px;
border: 1px solid #ddd;
border-radius: 4px;
}
/* 其他原有样式保持不变 */
.table {
width: 100%;
border-collapse: collapse;
background: white;
border-radius: 15px;
overflow: hidden;
}
.table th {
background: linear-gradient(45deg, #1976d2, #42a5f5);
color: white;
padding: 15px;
text-align: left;
font-weight: 500;
}
.table td {
padding: 15px;
border-bottom: 1px solid #f0f0f0;
transition: background-color 0.3s ease;
}
.table tr:hover td {
background-color: #f8f9fa;
}
.table tr:nth-child(even) {
background-color: #fafafa;
}
.charts-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
gap: 30px;
margin-bottom: 30px;
}
.chart-card {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 30px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.chart-title {
color: #1976d2;
font-size: 1.3em;
margin-bottom: 20px;
font-weight: 600;
text-align: center;
}
.status-badge {
padding: 4px 12px;
border-radius: 20px;
font-size: 0.85em;
font-weight: 500;
}
.status-enabled {
background: linear-gradient(45deg, #4caf50, #66bb6a);
color: white;
}
.status-disabled {
background: linear-gradient(45deg, #ff9800, #ffb74d);
color: white;
}
.alert {
padding: 15px 20px;
border-radius: 12px;
margin-bottom: 20px;
border-left: 4px solid;
}
.alert-success {
background: rgba(76, 175, 80, 0.1);
border-color: #4caf50;
color: #2e7d32;
}
.alert-error {
background: rgba(244, 67, 54, 0.1);
border-color: #f44336;
color: #c62828;
}
.alert-info {
background: rgba(25, 118, 210, 0.1);
border-color: #1976d2;
color: #1565c0;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(5px);
z-index: 1000;
}
.modal-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
border-radius: 20px;
padding: 30px;
max-width: 500px;
width: 90%;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 2px solid #f0f0f0;
}
.modal-title {
color: #1976d2;
font-size: 1.5em;
font-weight: 600;
}
.close {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
color: #999;
transition: color 0.3s ease;
}
.close:hover {
color: #f44336;
}
.form-row {
display: flex;
gap: 15px;
margin-bottom: 20px;
}
.form-row .form-group {
flex: 1;
}
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
flex-wrap: wrap;
gap: 15px;
}
.toolbar-left {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.export-area {
background: #f8f9fa;
border-radius: 12px;
padding: 20px;
margin-top: 20px;
}
.export-content {
background: white;
border-radius: 8px;
padding: 15px;
font-family: 'Courier New', monospace;
font-size: 14px;
border: 2px solid #e3f2fd;
word-break: break-all;
}
.loading {
display: none;
text-align: center;
padding: 40px;
color: #666;
}
.loading.show {
display: block;
}
.spinner {
border: 3px solid #f3f3f3;
border-top: 3px solid #1976d2;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 20px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: #666;
}
.empty-state h3 {
color: #999;
margin-bottom: 10px;
}
/* 编辑别名相关样式 */
.alias-edit {
display: flex;
align-items: center;
gap: 8px;
}
.alias-display {
cursor: pointer;
padding: 4px 8px;
border-radius: 4px;
transition: background-color 0.3s ease;
}
.alias-display:hover {
background-color: #f0f0f0;
}
.alias-edit-input {
padding: 4px 8px;
border: 1px solid #1976d2;
border-radius: 4px;
font-size: 14px;
min-width: 120px;
}
.alias-edit-buttons {
display: flex;
gap: 4px;
}
.btn-icon {
padding: 4px 8px;
font-size: 12px;
min-width: auto;
}
/* 文件日志控制区域 */
.file-logging-control {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 15px;
}
.file-logging-info {
display: flex;
align-items: center;
gap: 15px;
}
.file-logging-actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #1976d2;
}
input:checked + .slider:before {
transform: translateX(26px);
}
@media (max-width: 768px) {
.container {
padding: 10px;
}
.nav-tabs {
flex-direction: column;
gap: 5px;
}
.charts-container {
grid-template-columns: 1fr;
}
.stats-grid {
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.filter-row {
grid-template-columns: 1fr;
}
.filter-row:last-child {
grid-template-columns: 1fr;
}
.date-range {
flex-direction: column;
align-items: stretch;
}
.logs-table {
font-size: 12px;
}
.logs-table th,
.logs-table td {
padding: 8px 4px;
}
.file-logging-control {
flex-direction: column;
align-items: stretch;
}
.file-logging-info {
justify-content: center;
}
.file-logging-actions {
justify-content: center;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🚀 API日志管理中心</h1>
<p>OpenAI to Gemini Proxy 日志监控与管理系统</p>
</div>
<!-- 登录表单 -->
<div id="loginForm" class="login-form">
<h2>🔐 管理员登录</h2>
<div class="form-group">
<label for="password">管理员密码</label>
<input type="password" id="password" class="form-control" placeholder="请输入管理员密码">
</div>
<button onclick="login()" class="btn btn-primary" style="width: 100%;">登录</button>
<div id="loginError" class="alert alert-error" style="display: none; margin-top: 15px;"></div>
</div>
<!-- 管理面板 -->
<div id="dashboard" class="dashboard">
<!-- 导航标签 -->
<div class="nav-tabs">
<button class="nav-tab active" onclick="showTab('overview')">📊 概览统计</button>
<button class="nav-tab" onclick="showTab('logs')">📋 请求日志</button>
<button class="nav-tab" onclick="showTab('keys')">🔑 认证管理</button>
<button class="nav-tab" onclick="showTab('charts')">📈 统计图表</button>
</div>
<!-- 概览统计 -->
<div id="overview-tab" class="tab-content active">
<div class="stats-grid" id="statsGrid">
<!-- 统计卡片将动态生成 -->
</div>
<div class="card">
<h3 class="card-title">📋 最近请求</h3>
<div id="recentLogs">
<div class="loading show">
<div class="spinner"></div>
<p>加载中...</p>
</div>
</div>
</div>
</div>
<!-- 请求日志 -->
<div id="logs-tab" class="tab-content">
<!-- 文件日志控制 -->
<div class="file-logging-control">
<div class="file-logging-info">
<span>📄 文件日志:</span>
<label class="switch">
<input type="checkbox" id="fileLoggingSwitch" onchange="toggleFileLogging()">
<span class="slider"></span>
</label>
<span id="fileLoggingStatus">加载中...</span>
</div>
<div class="file-logging-actions">
<button onclick="downloadLogs('json')" class="btn btn-primary">📥 下载JSON</button>
<button onclick="downloadLogs('csv')" class="btn btn-secondary">📥 下载CSV</button>
</div>
</div>
<!-- 日志筛选器 -->
<div class="log-filters">
<div class="filter-row">
<div class="filter-group">
<label>开始时间 ~ 结束时间</label>
<div class="date-range">
<input type="datetime-local" id="startTime" class="filter-input">
<span class="date-separator">~</span>
<input type="datetime-local" id="endTime" class="filter-input">
</div>
</div>
<div class="filter-group">
<label>令牌名称</label>
<input type="text" id="tokenFilter" class="filter-input" placeholder="搜索...">
</div>
<div class="filter-group">
<label>模型名称</label>
<input type="text" id="modelFilter" class="filter-input" placeholder="搜索...">
</div>
</div>
<div class="filter-row">
<div class="filter-group">
<label>分组</label>
<select id="groupFilter" class="filter-input">
<option value="">全部</option>
</select>
</div>
<div class="filter-group">
<button onclick="applyFilters()" class="btn btn-primary">查询</button>
</div>
<div class="filter-group">
<button onclick="resetFilters()" class="btn btn-secondary">重置</button>
</div>
<div class="filter-group">
<button onclick="refreshLogs()" class="btn btn-warning">刷新</button>
</div>
<div class="filter-group">
<button onclick="clearAllLogs()" class="btn btn-danger">清除所有</button>
</div>
</div>
</div>
<!-- 日志表格 -->
<div class="card">
<div id="logsContainer">
<div class="loading show">
<div class="spinner"></div>
<p>加载日志中...</p>
</div>
</div>
<!-- 分页控制 -->
<div id="logsPagination" class="pagination-container" style="display: none;">
<div class="pagination-info" id="paginationInfo"></div>
<div class="pagination-controls">
<button id="firstPageBtn" class="pagination-btn" onclick="goToPage(1)">首页</button>
<button id="prevPageBtn" class="pagination-btn" onclick="goToPage(currentPage - 1)">上一页</button>
<input type="number" id="pageInput" class="pagination-input" min="1" onchange="goToInputPage()">
<button id="nextPageBtn" class="pagination-btn" onclick="goToPage(currentPage + 1)">下一页</button>
<select id="pageSizeSelect" class="page-size-select" onchange="changePageSize()">
<option value="50">每页50条</option>
<option value="100" selected>每页100条</option>
<option value="200">每页200条</option>
</select>
</div>
</div>
</div>
</div>
<!-- 认证管理 -->
<div id="keys-tab" class="tab-content">
<div class="card">
<div class="toolbar">
<h3 class="card-title">🔑 认证Key管理</h3>
<div>
<button onclick="showAddKeyModal()" class="btn btn-success">➕ 添加Key</button>
<button onclick="exportKeys()" class="btn btn-secondary">📤 导出配置</button>
<button onclick="refreshKeys()" class="btn btn-primary">🔄 刷新</button>
</div>
</div>
<div class="table-container">
<table class="table">
<thead>
<tr>
<th>别名</th>
<th>Token</th>
<th>状态</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="keysTableBody">
<tr>
<td colspan="5" style="text-align: center; padding: 40px;">
<div class="loading show">
<div class="spinner"></div>
<p>加载中...</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="exportArea" class="export-area" style="display: none;">
<h4>环境变量配置</h4>
<p>复制以下内容到您的 .env 文件中:</p>
<div id="exportContent" class="export-content"></div>
</div>
</div>
</div>
<!-- 统计图表 -->
<div id="charts-tab" class="tab-content">
<div class="charts-container">
<div class="chart-card">
<h3 class="chart-title">📊 请求类型分布</h3>
<canvas id="requestTypeChart"></canvas>
</div>
<div class="chart-card">
<h3 class="chart-title">🎯 模型使用统计</h3>
<canvas id="modelUsageChart"></canvas>
</div>
<div class="chart-card">
<h3 class="chart-title">✅ 请求状态分布</h3>
<canvas id="statusChart"></canvas>
</div>
<div class="chart-card">
<h3 class="chart-title">🔑 Key使用对比</h3>
<canvas id="keyUsageChart"></canvas>
</div>
</div>
</div>
</div>
</div>
<!-- 添加Key模态框 -->
<div id="addKeyModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">➕ 添加新的认证Key</h3>
<button class="close" onclick="closeModal('addKeyModal')">×</button>
</div>
<form onsubmit="addKey(event)">
<div class="form-group">
<label for="keyAlias">别名</label>
<input type="text" id="keyAlias" class="form-control" placeholder="为这个Key设置一个别名" required>
</div>
<div class="form-group">
<label for="keyToken">Token</label>
<input type="text" id="keyToken" class="form-control" placeholder="输入认证Token" required>
</div>
<div style="display: flex; gap: 10px; justify-content: flex-end;">
<button type="button" onclick="closeModal('addKeyModal')" class="btn btn-secondary">取消</button>
<button type="submit" class="btn btn-success">添加</button>
</div>
</form>
</div>
</div>
<!-- 编辑别名模态框 -->
<div id="editAliasModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">✏️ 编辑别名</h3>
<button class="close" onclick="closeModal('editAliasModal')">×</button>
</div>
<form onsubmit="saveAlias(event)">
<div class="form-group">
<label for="editAlias">别名</label>
<input type="text" id="editAlias" class="form-control" required>
</div>
<div style="display: flex; gap: 10px; justify-content: flex-end;">
<button type="button" onclick="closeModal('editAliasModal')" class="btn btn-secondary">取消</button>
<button type="submit" class="btn btn-success">保存</button>
</div>
</form>
</div>
</div>
<script>
// 全局变量
let authToken = null;
let currentPage = 1;
let pageSize = 100;
let totalPages = 1;
let chartInstances = {};
let allLogs = [];
let filteredLogs = [];
let authKeys = [];
let currentEditToken = null;
// 日志筛选参数
let filters = {
startTime: '',
endTime: '',
tokenFilter: '',
modelFilter: '',
groupFilter: ''
};
// 登录功能
async function login() {
const password = document.getElementById('password').value;
if (!password) {
showError('loginError', '请输入密码');
return;
}
try {
const response = await fetch('/admin/auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password })
});
const result = await response.json();
if (result.success) {
authToken = result.token;
document.getElementById('loginForm').style.display = 'none';
document.getElementById('dashboard').style.display = 'block';
await initDashboard();
} else {
showError('loginError', '密码错误,请重试');
}
} catch (error) {
showError('loginError', '登录失败,请检查网络连接');
}
}
// 初始化仪表板
async function initDashboard() {
// 设置默认时间范围(最近7天)
const now = new Date();
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
document.getElementById('startTime').value = formatDateForInput(weekAgo);
document.getElementById('endTime').value = formatDateForInput(now);
await Promise.all([
loadStatistics(),
loadAuthKeys(),
loadAllLogs(),
loadRecentLogs(),
loadFileLoggingStatus()
]);
}
// 加载文件日志状态
async function loadFileLoggingStatus() {
try {
const response = await fetch('/admin/file-logging-status');
const result = await response.json();
document.getElementById('fileLoggingSwitch').checked = result.enabled;
document.getElementById('fileLoggingStatus').textContent = result.enabled ? '已启用' : '已禁用(仅内存)';
} catch (error) {
console.error('获取文件日志状态失败:', error);
document.getElementById('fileLoggingStatus').textContent = '状态未知';
}
}
// 切换文件日志状态
async function toggleFileLogging() {
const enabled = document.getElementById('fileLoggingSwitch').checked;
try {
const response = await fetch('/admin/file-logging', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled })
});
const result = await response.json();
if (result.success) {
document.getElementById('fileLoggingStatus').textContent = enabled ? '已启用' : '已禁用(仅内存)';
showSuccess(result.message);
} else {
// 恢复开关状态
document.getElementById('fileLoggingSwitch').checked = !enabled;
alert('设置失败: ' + result.message);
}
} catch (error) {
// 恢复开关状态
document.getElementById('fileLoggingSwitch').checked = !enabled;
alert('设置失败: ' + error.message);
}
}
// 下载日志文件
function downloadLogs(format) {
const timestamp = new Date().toISOString().slice(0, 19).replace(/[:.]/g, '-');
const filename = `api-logs-${timestamp}.${format}`;
const link = document.createElement('a');
link.href = `/admin/download-logs?format=${format}`;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
showSuccess(`正在下载 ${format.toUpperCase()} 格式的日志文件...`);
}
// 格式化日期为input[datetime-local]格式
function formatDateForInput(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${year}-${month}-${day}T${hours}:${minutes}`;
}
// 显示错误信息
function showError(elementId, message) {
const element = document.getElementById(elementId);
element.textContent = message;
element.style.display = 'block';
setTimeout(() => {
element.style.display = 'none';
}, 5000);
}
// 显示成功信息
function showSuccess(message) {
const alertDiv = document.createElement('div');
alertDiv.className = 'alert alert-success';
alertDiv.textContent = message;
alertDiv.style.position = 'fixed';
alertDiv.style.top = '20px';
alertDiv.style.right = '20px';
alertDiv.style.zIndex = '9999';
alertDiv.style.minWidth = '300px';
document.body.appendChild(alertDiv);
setTimeout(() => {
alertDiv.remove();
}, 3000);
}
// 标签切换
function showTab(tabName) {
// 隐藏所有标签内容
const contents = document.querySelectorAll('.tab-content');
contents.forEach(content => content.classList.remove('active'));
// 移除所有标签的active状态
const tabs = document.querySelectorAll('.nav-tab');
tabs.forEach(tab => tab.classList.remove('active'));
// 显示选中的标签内容
document.getElementById(tabName + '-tab').classList.add('active');
// 设置对应按钮为active
event.target.classList.add('active');
// 特殊处理
if (tabName === 'charts') {
setTimeout(() => loadCharts(), 100);
} else if (tabName === 'logs') {
applyFilters();
}
}
// 加载统计信息
async function loadStatistics() {
try {
const response = await fetch('/admin/statistics');
const stats = await response.json();
const statsGrid = document.getElementById('statsGrid');
let totalRequests = 0;
let totalStreamRequests = 0;
let totalNormalRequests = 0;
let totalFakeStreamRequests = 0;
let totalErrorRequests = 0;
// 计算总数
Object.values(stats).forEach(keyStats => {
totalRequests += keyStats.totalRequests;
totalStreamRequests += keyStats.streamRequests;
totalNormalRequests += keyStats.normalRequests;
totalFakeStreamRequests += keyStats.fakeStreamRequests || 0;
totalErrorRequests += keyStats.errorRequests;
});
statsGrid.innerHTML = `
<div class="stat-card">
<div class="stat-value">${totalRequests}</div>
<div class="stat-label">总请求数</div>
</div>
<div class="stat-card">
<div class="stat-value">${totalStreamRequests}</div>
<div class="stat-label">流式请求</div>
</div>
<div class="stat-card">
<div class="stat-value">${totalNormalRequests}</div>
<div class="stat-label">普通请求</div>
</div>
<div class="stat-card">
<div class="stat-value">${totalFakeStreamRequests}</div>
<div class="stat-label">假流式请求</div>
</div>
<div class="stat-card">
<div class="stat-value">${totalErrorRequests}</div>
<div class="stat-label">错误请求</div>
</div>
<div class="stat-card">
<div class="stat-value">${Object.keys(stats).length}</div>
<div class="stat-label">活跃Key数</div>
</div>
<div class="stat-card">
<div class="stat-value">${totalRequests > 0 ? ((totalRequests - totalErrorRequests) / totalRequests * 100).toFixed(1) : 0}%</div>
<div class="stat-label">成功率</div>
</div>
`;
} catch (error) {
console.error('加载统计信息失败:', error);
}
}
// 加载认证Keys
async function loadAuthKeys() {
try {
const response = await fetch('/admin/keys');
const keys = await response.json();
authKeys = keys;
// 更新分组选择器
const groupFilter = document.getElementById('groupFilter');
groupFilter.innerHTML = '<option value="">全部</option>';
keys.forEach(key => {
const option = document.createElement('option');
option.value = key.token;
option.textContent = key.alias;
groupFilter.appendChild(option);
});
// 更新Keys管理表格
updateKeysTable();
} catch (error) {
console.error('加载认证Keys失败:', error);
}
}
// 更新Keys管理表格
function updateKeysTable() {
const tbody = document.getElementById('keysTableBody');
if (authKeys.length === 0) {
tbody.innerHTML = `
<tr>
<td colspan="5" class="empty-state">
<h3>暂无认证Key</h3>
<p>点击"添加Key"按钮创建第一个认证Key</p>
</td>
</tr>
`;
} else {
tbody.innerHTML = authKeys.map(key => `
<tr>
<td>
<div class="alias-edit" id="alias-${key.token}">
<span class="alias-display" onclick="startEditAlias('${key.token}', '${key.alias}')" title="点击编辑别名">
<strong>${key.alias}</strong> ✏️
</span>
</div>
</td>
<td><code>${key.token.substring(0, 15)}...${key.token.substring(key.token.length - 5)}</code></td>
<td>
<span class="status-badge ${key.enabled ? 'status-enabled' : 'status-disabled'}">
${key.enabled ? '✅ 启用' : '❌ 禁用'}
</span>
</td>
<td>${new Date(key.createdAt).toLocaleString()}</td>
<td>
<button onclick="toggleKeyStatus('${key.token}', ${!key.enabled})"
class="btn ${key.enabled ? 'btn-warning' : 'btn-success'}"
style="margin-right: 5px;">
${key.enabled ? '禁用' : '启用'}
</button>
<button onclick="deleteKey('${key.token}')" class="btn btn-danger">删除</button>
</td>
</tr>
`).join('');
}
}
// 开始编辑别名
function startEditAlias(token, currentAlias) {
currentEditToken = token;
document.getElementById('editAlias').value = currentAlias;
document.getElementById('editAliasModal').style.display = 'block';
}
// 保存别名
async function saveAlias(event) {
event.preventDefault();
const newAlias = document.getElementById('editAlias').value.trim();
if (!newAlias) {
alert('别名不能为空');
return;
}
try {
const response = await fetch(`/admin/keys/${encodeURIComponent(currentEditToken)}/alias`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ alias: newAlias })
});
const result = await response.json();
if (result.success) {
showSuccess('别名更新成功');
closeModal('editAliasModal');
await loadAuthKeys();
// 如果当前在日志页面,也需要重新加载日志以更新显示
if (document.getElementById('logs-tab').classList.contains('active')) {
await loadAllLogs();
applyFilters();
}
} else {
alert('更新失败: ' + (result.message || '未知错误'));
}
} catch (error) {
alert('更新失败: ' + error.message);
}
}
// 加载所有日志
async function loadAllLogs() {
try {
const response = await fetch('/admin/all-logs');
allLogs = await response.json();
console.log(`加载了 ${allLogs.length} 条日志`);
} catch (error) {
console.error('加载所有日志失败:', error);
}
}
// 应用筛选器
function applyFilters() {
// 获取筛选条件
filters.startTime = document.getElementById('startTime').value;
filters.endTime = document.getElementById('endTime').value;
filters.tokenFilter = document.getElementById('tokenFilter').value.toLowerCase();
filters.modelFilter = document.getElementById('modelFilter').value.toLowerCase();
filters.groupFilter = document.getElementById('groupFilter').value;
// 筛选日志
filteredLogs = allLogs.filter(log => {
// 时间筛选
if (filters.startTime) {
const logTime = new Date(log.timestamp || log.requestTime);
const startTime = new Date(filters.startTime);
if (logTime < startTime) return false;
}
if (filters.endTime) {
const logTime = new Date(log.timestamp || log.requestTime);
const endTime = new Date(filters.endTime);
if (logTime > endTime) return false;
}
// 令牌筛选
if (filters.tokenFilter && !(log.keyAlias || '').toLowerCase().includes(filters.tokenFilter)) {
return false;
}
// 模型筛选
if (filters.modelFilter && !(log.model || '').toLowerCase().includes(filters.modelFilter)) {
return false;
}
// 分组筛选
if (filters.groupFilter && log.authKey !== filters.groupFilter) {
return false;
}
return true;
});
// 重置到第一页
currentPage = 1;
// 渲染筛选后的日志
renderLogs();
}
// 重置筛选器
function resetFilters() {
document.getElementById('startTime').value = '';
document.getElementById('endTime').value = '';
document.getElementById('tokenFilter').value = '';
document.getElementById('modelFilter').value = '';
document.getElementById('groupFilter').value = '';
// 重新设置默认时间范围
const now = new Date();
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
document.getElementById('startTime').value = formatDateForInput(weekAgo);
document.getElementById('endTime').value = formatDateForInput(now);
applyFilters();
}
// 渲染日志
function renderLogs() {
const container = document.getElementById('logsContainer');
const pagination = document.getElementById('logsPagination');
if (filteredLogs.length === 0) {
container.innerHTML = `
<div class="empty-state">
<h3>暂无符合条件的日志</h3>
<p>尝试调整筛选条件或重新加载数据</p>
</div>
`;
pagination.style.display = 'none';
return;
}
// 计算分页
totalPages = Math.ceil(filteredLogs.length / pageSize);
const startIndex = (currentPage - 1) * pageSize;
const endIndex = Math.min(startIndex + pageSize, filteredLogs.length);
const currentLogs = filteredLogs.slice(startIndex, endIndex);
// 渲染日志表格
container.innerHTML = `
<div class="table-container">
<table class="logs-table">
<thead>
<tr>
<th>时间</th>
<th>用户</th>
<th>类型</th>
<th>模型</th>
<th>用时</th>
<th>提示</th>
<th>补全</th>
<th>详情</th>
</tr>
</thead>
<tbody>
${currentLogs.map((log, index) => `
<tr>
<td class="log-time">${formatLogTime(log.timestamp || log.requestTime)}</td>
<td class="log-user">
<div class="user-avatar">${log.keyAlias ? log.keyAlias.charAt(0).toUpperCase() : 'U'}</div>
${log.keyAlias || 'Unknown'}
</td>
<td>
<span class="log-type-badge ${getTypeClass(log.requestType)}">
${getTypeText(log.requestType)}
</span>
</td>
<td>
<span class="log-model">${log.model || 'unknown'}</span>
</td>
<td class="log-timing">
${log.duration ? log.duration + ' ms' : '-'}
</td>
<td class="log-status ${log.status === 'success' ? 'status-success' : 'status-error'}">
${log.status === 'success' ? '✓' : '✗'}
</td>
<td class="log-tokens">
${log.responseTokens || 0}
</td>
<td class="log-detail" title="${log.responseContent || log.error || '无内容'}">
${getDetailText(log)}
</td>
</tr>
`).join('')}
</tbody>
</table>
</div>
`;
// 更新分页信息
updatePagination();
pagination.style.display = 'flex';
}
// 格式化日志时间
function formatLogTime(timeString) {
const date = new Date(timeString);
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `2025-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
// 获取类型样式类
function getTypeClass(requestType) {
if (requestType === 'stream') return 'type-stream';
if (requestType === 'fake-stream') return 'type-fake-stream';
return 'type-normal';
}
// 获取类型文本
function getTypeText(requestType) {
if (requestType === 'stream') return '流';
if (requestType === 'fake-stream') return '假流';
return '普通';
}
// 获取详情文本
function getDetailText(log) {
if (log.status === 'error' && log.error) {
return `错误: ${log.error}`;
}
if (log.responseContent) {
return log.responseContent;
}
return '无内容';
}
// 更新分页信息
function updatePagination() {
const info = document.getElementById('paginationInfo');
const startRecord = (currentPage - 1) * pageSize + 1;
const endRecord = Math.min(currentPage * pageSize, filteredLogs.length);
info.textContent = `显示第 ${startRecord} 条 - 第 ${endRecord} 条,共 ${filteredLogs.length} 条`;
// 更新按钮状态
document.getElementById('firstPageBtn').disabled = currentPage <= 1;
document.getElementById('prevPageBtn').disabled = currentPage <= 1;
document.getElementById('nextPageBtn').disabled = currentPage >= totalPages;
// 更新页码输入框
document.getElementById('pageInput').value = currentPage;
document.getElementById('pageInput').max = totalPages;
}
// 跳转到指定页
function goToPage(page) {
if (page < 1 || page > totalPages) return;
currentPage = page;
renderLogs();
}
// 跳转到输入的页码
function goToInputPage() {
const inputPage = parseInt(document.getElementById('pageInput').value);
goToPage(inputPage);
}
// 改变每页大小
function changePageSize() {
pageSize = parseInt(document.getElementById('pageSizeSelect').value);
currentPage = 1;
renderLogs();
}
// 刷新日志
async function refreshLogs() {
document.getElementById('logsContainer').innerHTML = `
<div class="loading show">
<div class="spinner"></div>
<p>重新加载日志中...</p>
</div>
`;
await loadAllLogs();
applyFilters();
}
// 清除所有日志
async function clearAllLogs() {
if (!confirm('确定要清除所有Key的日志吗?此操作不可撤销!')) {
return;
}
try {
const deletePromises = authKeys.map(key =>
fetch(`/admin/logs/${key.token}`, { method: 'DELETE' })
);
await Promise.all(deletePromises);
showSuccess('所有日志已清除');
await loadAllLogs();
applyFilters();
await loadStatistics();
await loadRecentLogs();
} catch (error) {
alert('清除日志失败: ' + error.message);
}
}
// 加载最近日志
async function loadRecentLogs() {
try {
const recentLogs = allLogs.slice(0, 10);
const recentLogsContainer = document.getElementById('recentLogs');
if (recentLogs.length === 0) {
recentLogsContainer.innerHTML = `
<div class="empty-state">
<h3>暂无请求日志</h3>
<p>当有API请求时,日志将在这里显示</p>
</div>
`;
} else {
recentLogsContainer.innerHTML = `
<div class="table-container">
<table class="table">
<thead>
<tr>
<th>Key别名</th>
<th>时间</th>
<th>类型</th>
<th>模型</th>
<th>状态</th>
<th>Token数</th>
<th>响应内容</th>
</tr>
</thead>
<tbody>
${recentLogs.map(log => `
<tr>
<td><code>${log.keyAlias || 'Unknown'}</code></td>
<td>${new Date(log.timestamp || log.requestTime).toLocaleString()}</td>
<td>
<span class="status-badge ${log.requestType === 'stream' ? 'status-success' : 'status-secondary'}">
${log.requestType === 'stream' ? '🌊 流式' : log.requestType === 'fake-stream' ? '🎭 假流式' : '📄 普通'}
</span>
</td>
<td>${log.model || '未知'}</td>
<td>
<span class="status-badge ${log.status === 'success' ? 'status-success' : 'status-error'}">
${log.status === 'success' ? '✅ 成功' : '❌ 失败'}
</span>
</td>
<td>${log.responseTokens || 0}</td>
<td style="max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
${log.responseContent || (log.error ? '错误: ' + log.error : '无内容')}
</td>
</tr>
`).join('')}
</tbody>
</table>
</div>
`;
}
} catch (error) {
console.error('加载最近日志失败:', error);
document.getElementById('recentLogs').innerHTML = `
<div class="alert alert-error">加载日志失败,请稍后重试</div>
`;
}
}
// 刷新Keys
function refreshKeys() {
loadAuthKeys();
}
// 显示添加Key模态框
function showAddKeyModal() {
document.getElementById('addKeyModal').style.display = 'block';
}
// 关闭模态框
function closeModal(modalId) {
document.getElementById(modalId).style.display = 'none';
// 清空表单
if (modalId === 'addKeyModal') {
document.getElementById('keyAlias').value = '';
document.getElementById('keyToken').value = '';
} else if (modalId === 'editAliasModal') {
document.getElementById('editAlias').value = '';
currentEditToken = null;
}
}
// 添加Key
async function addKey(event) {
event.preventDefault();
const alias = document.getElementById('keyAlias').value;
const token = document.getElementById('keyToken').value;
try {
const response = await fetch('/admin/keys', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ alias, token })
});
const result = await response.json();
if (result.success) {
showSuccess('认证Key添加成功');
closeModal('addKeyModal');
await loadAuthKeys();
} else {
alert('添加失败: ' + (result.message || '未知错误'));
}
} catch (error) {
alert('添加失败: ' + error.message);
}
}
// 切换Key状态
async function toggleKeyStatus(token, enabled) {
try {
const response = await fetch(`/admin/keys/${encodeURIComponent(token)}/status`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled })
});
const result = await response.json();
if (result.success) {
showSuccess(result.message);
await loadAuthKeys();
} else {
alert('操作失败: ' + (result.message || '未知错误'));
}
} catch (error) {
alert('操作失败: ' + error.message);
}
}
// 删除Key
async function deleteKey(token) {
if (!confirm('确定要删除此认证Key吗?此操作不可撤销!')) {
return;
}
try {
const response = await fetch(`/admin/keys/${encodeURIComponent(token)}`, {
method: 'DELETE'
});
const result = await response.json();
if (result.success) {
showSuccess('认证Key删除成功');
await loadAuthKeys();
} else {
alert('删除失败: ' + (result.message || '未知错误'));
}
} catch (error) {
alert('删除失败: ' + error.message);
}
}
// 导出Keys配置
async function exportKeys() {
try {
const response = await fetch('/admin/export');
const data = await response.json();
document.getElementById('exportContent').textContent = data.envString;
document.getElementById('exportArea').style.display = 'block';
// 滚动到导出区域
document.getElementById('exportArea').scrollIntoView({ behavior: 'smooth' });
} catch (error) {
alert('导出失败: ' + error.message);
}
}
// 加载图表
async function loadCharts() {
try {
const response = await fetch('/admin/statistics');
const stats = await response.json();
// 清除旧图表
Object.values(chartInstances).forEach(chart => chart.destroy());
chartInstances = {};
// 准备数据
const keyLabels = [];
const requestTypeCounts = { stream: 0, normal: 0, 'fake-stream': 0 };
const modelCounts = {};
const statusCounts = { success: 0, error: 0 };
const keyRequestCounts = [];
Object.entries(stats).forEach(([key, keyStats]) => {
const alias = authKeys.find(k => k.token === key)?.alias || key.substring(0, 10) + '...';
keyLabels.push(alias);
keyRequestCounts.push(keyStats.totalRequests);
requestTypeCounts.stream += keyStats.streamRequests;
requestTypeCounts.normal += keyStats.normalRequests;
requestTypeCounts['fake-stream'] += keyStats.fakeStreamRequests || 0;
statusCounts.success += (keyStats.totalRequests - keyStats.errorRequests);
statusCounts.error += keyStats.errorRequests;
Object.entries(keyStats.modelUsage || {}).forEach(([model, count]) => {
modelCounts[model] = (modelCounts[model] || 0) + count;
});
});
// 请求类型分布图
chartInstances.requestType = new Chart(document.getElementById('requestTypeChart'), {
type: 'doughnut',
data: {
labels: ['流式请求', '普通请求', '假流式请求'],
datasets: [{
data: [requestTypeCounts.stream, requestTypeCounts.normal, requestTypeCounts['fake-stream']],
backgroundColor: ['#42a5f5', '#66bb6a', '#ffb74d'],
borderWidth: 2,
borderColor: '#fff'
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'bottom'
}
}
}
});
// 模型使用统计
const modelLabels = Object.keys(modelCounts).slice(0, 8);
const modelData = modelLabels.map(model => modelCounts[model]);
chartInstances.modelUsage = new Chart(document.getElementById('modelUsageChart'), {
type: 'bar',
data: {
labels: modelLabels,
datasets: [{
label: '请求次数',
data: modelData,
backgroundColor: '#42a5f5',
borderColor: '#1976d2',
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
// 请求状态分布
chartInstances.status = new Chart(document.getElementById('statusChart'), {
type: 'pie',
data: {
labels: ['成功', '失败'],
datasets: [{
data: [statusCounts.success, statusCounts.error],
backgroundColor: ['#4caf50', '#f44336'],
borderWidth: 2,
borderColor: '#fff'
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'bottom'
}
}
}
});
// Key使用对比
chartInstances.keyUsage = new Chart(document.getElementById('keyUsageChart'), {
type: 'bar',
data: {
labels: keyLabels,
datasets: [{
label: '请求次数',
data: keyRequestCounts,
backgroundColor: '#66bb6a',
borderColor: '#4caf50',
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
} catch (error) {
console.error('加载图表失败:', error);
}
}
// 页面点击事件 - 关闭模态框
window.addEventListener('click', function(event) {
const modals = document.querySelectorAll('.modal');
modals.forEach(modal => {
if (event.target === modal) {
modal.style.display = 'none';
}
});
});
// 回车登录
document.getElementById('password').addEventListener('keypress', function(event) {
if (event.key === 'Enter') {
login();
}
});
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
// 页面加载时显示正确的日志标签
setTimeout(() => {
if (document.querySelector('.nav-tab[onclick*="logs"]')) {
applyFilters();
}
}, 1000);
});
</script>
</body>
</html>
|