Update app/statics/admin/account.html
Browse files- app/statics/admin/account.html +222 -41
app/statics/admin/account.html
CHANGED
|
@@ -760,6 +760,101 @@
|
|
| 760 |
.audit-table { width:100%; border-collapse:collapse; min-width:560px }
|
| 761 |
.audit-table th { background:#202024; padding:8px 12px; font-size:11px; color:#a1a1aa; border-bottom:1px solid #3f3f46 }
|
| 762 |
.audit-table td { padding:10px 12px; font-size:12px; border-bottom:1px solid #2d2d34; color:#e4e4e7 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 763 |
</style>
|
| 764 |
</head>
|
| 765 |
<body>
|
|
@@ -1165,27 +1260,10 @@
|
|
| 1165 |
|
| 1166 |
<!-- ── Audit Log Modal ─────────────────────────────────────────────────────── -->
|
| 1167 |
<div class="modal-overlay" id="modal-audit">
|
| 1168 |
-
<div class="modal">
|
| 1169 |
<div class="modal-title" id="audit-title">调用审计明细</div>
|
| 1170 |
-
<div class="dialog-body">
|
| 1171 |
-
<
|
| 1172 |
-
<table class="audit-table">
|
| 1173 |
-
<thead>
|
| 1174 |
-
<tr>
|
| 1175 |
-
<th>请求时间</th>
|
| 1176 |
-
<th>设备 IP</th>
|
| 1177 |
-
<th>客户端 (User-Agent)</th>
|
| 1178 |
-
<th>会话 ID (Conversation ID)</th>
|
| 1179 |
-
<th>消耗 Token</th>
|
| 1180 |
-
</tr>
|
| 1181 |
-
</thead>
|
| 1182 |
-
<tbody id="audit-tbody">
|
| 1183 |
-
<tr>
|
| 1184 |
-
<td colspan="5" style="text-align:center;color:#71717a;padding:24px;">暂无审计记录</td>
|
| 1185 |
-
</tr>
|
| 1186 |
-
</tbody>
|
| 1187 |
-
</table>
|
| 1188 |
-
</div>
|
| 1189 |
</div>
|
| 1190 |
<div class="dialog-actions">
|
| 1191 |
<button onclick="closeModal('modal-audit')" class="dialog-btn dialog-btn-primary">关闭</button>
|
|
@@ -1347,7 +1425,7 @@ function updateSortIndicators() {
|
|
| 1347 |
}
|
| 1348 |
|
| 1349 |
// ── Audit Drill-down ───────────────────────────────────────────────────────
|
| 1350 |
-
async function openAuditModal(type) {
|
| 1351 |
const titleMap = {
|
| 1352 |
calls: '调用总数审计明细',
|
| 1353 |
auto: 'Auto 额度调用分布审计',
|
|
@@ -1356,29 +1434,131 @@ async function openAuditModal(type) {
|
|
| 1356 |
heavy: 'Heavy 额度调用分布审计',
|
| 1357 |
console: 'Console 额度调用分布审计'
|
| 1358 |
};
|
|
|
|
| 1359 |
document.getElementById('audit-title').textContent = titleMap[type] || '调用审计明细';
|
| 1360 |
-
const
|
| 1361 |
-
|
| 1362 |
openModal('modal-audit');
|
| 1363 |
|
| 1364 |
-
|
| 1365 |
-
|
| 1366 |
-
|
| 1367 |
-
|
| 1368 |
-
|
| 1369 |
-
|
| 1370 |
-
|
| 1371 |
-
|
| 1372 |
-
|
| 1373 |
-
|
| 1374 |
-
|
| 1375 |
-
|
| 1376 |
-
<
|
| 1377 |
-
|
| 1378 |
-
|
| 1379 |
-
|
| 1380 |
-
|
| 1381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1382 |
}
|
| 1383 |
}
|
| 1384 |
|
|
@@ -1518,6 +1698,7 @@ function isDisabledStatus(status) {
|
|
| 1518 |
return status === 'disabled';
|
| 1519 |
}
|
| 1520 |
|
|
|
|
| 1521 |
function isInvalidStatus(status) {
|
| 1522 |
return !['active', 'cooling', 'disabled'].includes(status);
|
| 1523 |
}
|
|
|
|
| 760 |
.audit-table { width:100%; border-collapse:collapse; min-width:560px }
|
| 761 |
.audit-table th { background:#202024; padding:8px 12px; font-size:11px; color:#a1a1aa; border-bottom:1px solid #3f3f46 }
|
| 762 |
.audit-table td { padding:10px 12px; font-size:12px; border-bottom:1px solid #2d2d34; color:#e4e4e7 }
|
| 763 |
+
|
| 764 |
+
/* ── 新增内存审计多视图动态响应样式 ── */
|
| 765 |
+
.audit-summary-grid {
|
| 766 |
+
display: grid;
|
| 767 |
+
grid-template-columns: repeat(4, minmax(0, 1fr));
|
| 768 |
+
gap: 12px;
|
| 769 |
+
margin-bottom: 18px;
|
| 770 |
+
}
|
| 771 |
+
.audit-grid-box {
|
| 772 |
+
background: #141416;
|
| 773 |
+
padding: 12px;
|
| 774 |
+
border-radius: 8px;
|
| 775 |
+
text-align: center;
|
| 776 |
+
border: 1px solid #3f3f46;
|
| 777 |
+
}
|
| 778 |
+
.audit-grid-box h5 {
|
| 779 |
+
margin: 0 0 6px 0;
|
| 780 |
+
color: #a1a1aa;
|
| 781 |
+
font-size: 11px;
|
| 782 |
+
font-weight: 500;
|
| 783 |
+
}
|
| 784 |
+
.audit-grid-box p {
|
| 785 |
+
margin: 0;
|
| 786 |
+
font-size: 18px;
|
| 787 |
+
font-weight: 600;
|
| 788 |
+
color: #f4f4f5;
|
| 789 |
+
}
|
| 790 |
+
.audit-dist-section {
|
| 791 |
+
display: flex;
|
| 792 |
+
gap: 16px;
|
| 793 |
+
margin-top: 14px;
|
| 794 |
+
}
|
| 795 |
+
.audit-dist-col {
|
| 796 |
+
flex: 1;
|
| 797 |
+
background: #141416;
|
| 798 |
+
padding: 14px;
|
| 799 |
+
border-radius: 8px;
|
| 800 |
+
border: 1px solid #3f3f46;
|
| 801 |
+
min-width: 0;
|
| 802 |
+
}
|
| 803 |
+
.audit-dist-col h4 {
|
| 804 |
+
margin: 0 0 12px 0;
|
| 805 |
+
font-size: 12px;
|
| 806 |
+
color: #fbbf24;
|
| 807 |
+
font-weight: 600;
|
| 808 |
+
}
|
| 809 |
+
.audit-rank-list {
|
| 810 |
+
list-style: none;
|
| 811 |
+
padding: 0;
|
| 812 |
+
margin: 0;
|
| 813 |
+
}
|
| 814 |
+
.audit-rank-list li {
|
| 815 |
+
display: flex;
|
| 816 |
+
justify-content: space-between;
|
| 817 |
+
align-items: center;
|
| 818 |
+
padding: 7px 0;
|
| 819 |
+
border-bottom: 1px solid #2d2d34;
|
| 820 |
+
font-size: 12px;
|
| 821 |
+
}
|
| 822 |
+
.audit-rank-list li:last-child {
|
| 823 |
+
border-bottom: none;
|
| 824 |
+
}
|
| 825 |
+
.audit-rank-lbl {
|
| 826 |
+
overflow: hidden;
|
| 827 |
+
text-overflow: ellipsis;
|
| 828 |
+
white-space: nowrap;
|
| 829 |
+
max-width: 75%;
|
| 830 |
+
color: #e4e4e7;
|
| 831 |
+
}
|
| 832 |
+
.audit-rank-val {
|
| 833 |
+
color: #60a5fa;
|
| 834 |
+
font-weight: 600;
|
| 835 |
+
font-variant-numeric: tabular-nums;
|
| 836 |
+
}
|
| 837 |
+
.audit-pagination-bar {
|
| 838 |
+
display: flex;
|
| 839 |
+
justify-content: center;
|
| 840 |
+
align-items: center;
|
| 841 |
+
gap: 14px;
|
| 842 |
+
margin-top: 14px;
|
| 843 |
+
}
|
| 844 |
+
.audit-badge-status {
|
| 845 |
+
padding: 2px 6px;
|
| 846 |
+
border-radius: 4px;
|
| 847 |
+
font-size: 11px;
|
| 848 |
+
font-weight: 500;
|
| 849 |
+
}
|
| 850 |
+
.audit-bg-success {
|
| 851 |
+
background: rgba(74, 222, 128, 0.15);
|
| 852 |
+
color: #4ade80;
|
| 853 |
+
}
|
| 854 |
+
.audit-bg-fail {
|
| 855 |
+
background: rgba(248, 113, 113, 0.15);
|
| 856 |
+
color: #f87171;
|
| 857 |
+
}
|
| 858 |
</style>
|
| 859 |
</head>
|
| 860 |
<body>
|
|
|
|
| 1260 |
|
| 1261 |
<!-- ── Audit Log Modal ─────────────────────────────────────────────────────── -->
|
| 1262 |
<div class="modal-overlay" id="modal-audit">
|
| 1263 |
+
<div class="modal" style="max-width:820px; width:92%;">
|
| 1264 |
<div class="modal-title" id="audit-title">调用审计明细</div>
|
| 1265 |
+
<div class="dialog-body" id="audit-modal-body-content" style="padding-top:8px;">
|
| 1266 |
+
<!-- 动态视图多看板注入点 -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1267 |
</div>
|
| 1268 |
<div class="dialog-actions">
|
| 1269 |
<button onclick="closeModal('modal-audit')" class="dialog-btn dialog-btn-primary">关闭</button>
|
|
|
|
| 1425 |
}
|
| 1426 |
|
| 1427 |
// ── Audit Drill-down ───────────────────────────────────────────────────────
|
| 1428 |
+
async function openAuditModal(type, page = 1) {
|
| 1429 |
const titleMap = {
|
| 1430 |
calls: '调用总数审计明细',
|
| 1431 |
auto: 'Auto 额度调用分布审计',
|
|
|
|
| 1434 |
heavy: 'Heavy 额度调用分布审计',
|
| 1435 |
console: 'Console 额度调用分布审计'
|
| 1436 |
};
|
| 1437 |
+
|
| 1438 |
document.getElementById('audit-title').textContent = titleMap[type] || '调用审计明细';
|
| 1439 |
+
const container = document.getElementById('audit-modal-body-content');
|
| 1440 |
+
container.innerHTML = `<div style="text-align:center;padding:32px;color:#a1a1aa;">正在从内存同步链读取审计快照...</div>`;
|
| 1441 |
openModal('modal-audit');
|
| 1442 |
|
| 1443 |
+
const key = await adminKey.get();
|
| 1444 |
+
const headers = { 'Authorization': `Bearer ${key}` };
|
| 1445 |
+
|
| 1446 |
+
// 视图 A: 渲染调用总数高并发明细列表(支持无损内存分页)
|
| 1447 |
+
if (type === 'calls') {
|
| 1448 |
+
try {
|
| 1449 |
+
const response = await fetch(`${ADMIN_API}/audit/logs?page=${page}&size=50`, { headers });
|
| 1450 |
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
| 1451 |
+
const data = await response.json();
|
| 1452 |
+
const logs = data.logs || [];
|
| 1453 |
+
|
| 1454 |
+
if (!logs.length) {
|
| 1455 |
+
container.innerHTML = `<div style="text-align:center;color:#71717a;padding:40px 16px;">当前通道近期没有上游日志产生 (直连/历史日志为空)</div>`;
|
| 1456 |
+
return;
|
| 1457 |
+
}
|
| 1458 |
+
|
| 1459 |
+
let html = `
|
| 1460 |
+
<div class="audit-table-wrap">
|
| 1461 |
+
<table class="audit-table">
|
| 1462 |
+
<thead>
|
| 1463 |
+
<tr>
|
| 1464 |
+
<th>请求时间</th>
|
| 1465 |
+
<th>设备 IP</th>
|
| 1466 |
+
<th>客户端 (User-Agent)</th>
|
| 1467 |
+
<th>渠道额度</th>
|
| 1468 |
+
<th>流状态</th>
|
| 1469 |
+
</tr>
|
| 1470 |
+
</thead>
|
| 1471 |
+
<tbody>
|
| 1472 |
+
`;
|
| 1473 |
+
|
| 1474 |
+
logs.forEach(log => {
|
| 1475 |
+
const dateStr = new Date(log.request_time).toLocaleString('zh-CN', { hour12: false });
|
| 1476 |
+
const statusBadge = log.status === 'SUCCESS'
|
| 1477 |
+
? '<span class="audit-badge-status audit-bg-success">成功</span>'
|
| 1478 |
+
: '<span class="audit-badge-status audit-bg-fail">阻断</span>';
|
| 1479 |
+
|
| 1480 |
+
html += `
|
| 1481 |
+
<tr>
|
| 1482 |
+
<td style="font-variant-numeric:tabular-nums; white-space:nowrap;">${dateStr}</td>
|
| 1483 |
+
<td style="font-family:ui-monospace,monospace;color:#f4f4f5;">${log.device_ip || '—'}</td>
|
| 1484 |
+
<td style="max-width:240px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#a1a1aa;" title="${xe(log.user_agent || '')}">${log.user_agent || '—'}</td>
|
| 1485 |
+
<td><span class="q-pill q-f" style="text-transform:capitalize; font-size:10px;">${log.quota_type}</span></td>
|
| 1486 |
+
<td>${statusBadge}</td>
|
| 1487 |
+
</tr>
|
| 1488 |
+
`;
|
| 1489 |
+
});
|
| 1490 |
+
|
| 1491 |
+
html += `</tbody></table></div>`;
|
| 1492 |
+
|
| 1493 |
+
html += `
|
| 1494 |
+
<div class="audit-pagination-bar">
|
| 1495 |
+
<button class="dialog-btn" ${page <= 1 ? 'disabled style="opacity:0.3;cursor:not-allowed;"' : ''} onclick="openAuditModal('calls', ${page - 1})">上一页</button>
|
| 1496 |
+
<span style="font-size:12px;color:#a1a1aa;">第 ${page} 页</span>
|
| 1497 |
+
<button class="dialog-btn" ${logs.length < 50 ? 'disabled style="opacity:0.3;cursor:not-allowed;"' : ''} onclick="openAuditModal('calls', ${page + 1})">下一页</button>
|
| 1498 |
+
</div>
|
| 1499 |
+
`;
|
| 1500 |
+
container.innerHTML = html;
|
| 1501 |
+
} catch (e) {
|
| 1502 |
+
container.innerHTML = `<div style="text-align:center;color:#f87171;padding:32px;">读取审计明细失败: ${e.message}</div>`;
|
| 1503 |
+
}
|
| 1504 |
+
}
|
| 1505 |
+
// 视图 B: 针对各类 Quota 卡片,离散计算并渲染 Top5 分布拓扑
|
| 1506 |
+
else {
|
| 1507 |
+
try {
|
| 1508 |
+
const response = await fetch(`${ADMIN_API}/audit/distribution?type=${type}`, { headers });
|
| 1509 |
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
| 1510 |
+
const data = await response.json();
|
| 1511 |
+
|
| 1512 |
+
const successRate = data.total_calls > 0
|
| 1513 |
+
? ((data.success_calls / data.total_calls) * 100).toFixed(1)
|
| 1514 |
+
: '0.0';
|
| 1515 |
+
|
| 1516 |
+
let html = `
|
| 1517 |
+
<div class="audit-summary-grid">
|
| 1518 |
+
<div class="audit-grid-box"><h5>总计调用</h5><p>${data.total_calls}</p></div>
|
| 1519 |
+
<div class="audit-grid-box"><h5 style="color:#4ade80">成功频次</h5><p style="color:#4ade80">${data.success_calls}</p></div>
|
| 1520 |
+
<div class="audit-grid-box"><h5 style="color:#f87171">失败阻断</h5><p style="color:#f87171">${data.fail_calls}</p></div>
|
| 1521 |
+
<div class="audit-grid-box"><h5>健康合规率</h5><p>${successRate}%</p></div>
|
| 1522 |
+
</div>
|
| 1523 |
+
|
| 1524 |
+
<div class="audit-dist-section">
|
| 1525 |
+
<div class="audit-dist-col">
|
| 1526 |
+
<h4>Top 5 活跃调用设备 IP 排名</h4>
|
| 1527 |
+
`;
|
| 1528 |
+
|
| 1529 |
+
const ipEntries = Object.entries(data.top_ips || {});
|
| 1530 |
+
if (!ipEntries.length) {
|
| 1531 |
+
html += `<div style="text-align:center;color:#71717a;font-size:12px;padding:24px 0;">暂无任何 IP 请求分布捕获</div>`;
|
| 1532 |
+
} else {
|
| 1533 |
+
html += `<ul class="audit-rank-list">`;
|
| 1534 |
+
ipEntries.forEach(([ip, count]) => {
|
| 1535 |
+
html += `<li><span class="audit-rank-lbl" style="font-family:ui-monospace,monospace;">${ip}</span><span class="audit-rank-val">${count} 次</span></li>`;
|
| 1536 |
+
});
|
| 1537 |
+
html += `</ul>`;
|
| 1538 |
+
}
|
| 1539 |
+
|
| 1540 |
+
html += `
|
| 1541 |
+
</div>
|
| 1542 |
+
<div class="audit-dist-col">
|
| 1543 |
+
<h4>Top 5 客户端 (User-Agent) 负载源</h4>
|
| 1544 |
+
`;
|
| 1545 |
+
|
| 1546 |
+
const uaEntries = Object.entries(data.top_user_agents || {});
|
| 1547 |
+
if (!uaEntries.length) {
|
| 1548 |
+
html += `<div style="text-align:center;color:#71717a;font-size:12px;padding:24px 0;">暂无任何 User-Agent 分布捕获</div>`;
|
| 1549 |
+
} else {
|
| 1550 |
+
html += `<ul class="audit-rank-list">`;
|
| 1551 |
+
uaEntries.forEach(([ua, count]) => {
|
| 1552 |
+
html += `<li><span class="audit-rank-lbl" title="${xe(ua)}">${ua}</span><span class="audit-rank-val">${count} 次</span></li>`;
|
| 1553 |
+
});
|
| 1554 |
+
html += `</ul>`;
|
| 1555 |
+
}
|
| 1556 |
+
|
| 1557 |
+
html += `</div></div>`;
|
| 1558 |
+
container.innerHTML = html;
|
| 1559 |
+
} catch (e) {
|
| 1560 |
+
container.innerHTML = `<div style="text-align:center;color:#f87171;padding:32px;">分析额度调用分布失败: ${e.message}</div>`;
|
| 1561 |
+
}
|
| 1562 |
}
|
| 1563 |
}
|
| 1564 |
|
|
|
|
| 1698 |
return status === 'disabled';
|
| 1699 |
}
|
| 1700 |
|
| 1701 |
+
// ── Anti-corruption checking indicators ──
|
| 1702 |
function isInvalidStatus(status) {
|
| 1703 |
return !['active', 'cooling', 'disabled'].includes(status);
|
| 1704 |
}
|