Spaces:
Running
Running
File size: 16,038 Bytes
7416023 |
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 |
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>日志管理</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 15px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
font-weight: 300;
}
.header p {
opacity: 0.9;
font-size: 1.1rem;
}
.controls {
padding: 30px;
background: #f8f9fa;
border-bottom: 1px solid #e9ecef;
}
.search-container {
display: flex;
gap: 15px;
align-items: center;
flex-wrap: wrap;
}
.search-input {
flex: 1;
min-width: 250px;
padding: 12px 20px;
border: 2px solid #e9ecef;
border-radius: 25px;
font-size: 16px;
transition: all 0.3s ease;
}
.search-input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.btn {
padding: 12px 25px;
border: none;
border-radius: 25px;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: all 0.3s ease;
text-decoration: none;
display: inline-block;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}
.btn-secondary {
background: #6c757d;
color: white;
}
.btn-secondary:hover {
background: #5a6268;
transform: translateY(-2px);
}
.page-size-container {
display: flex;
align-items: center;
gap: 10px;
margin-top: 20px;
}
.page-size-container label {
font-weight: 500;
color: #495057;
}
.page-size-container select {
padding: 8px 15px;
border: 2px solid #e9ecef;
border-radius: 8px;
font-size: 14px;
background: white;
cursor: pointer;
transition: all 0.3s ease;
}
.page-size-container select:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.content {
padding: 30px;
}
.log-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 30px;
background: white;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.log-table th {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 15px;
text-align: left;
font-weight: 500;
}
.log-table td {
padding: 15px;
border-bottom: 1px solid #e9ecef;
vertical-align: middle;
}
.log-table tr:hover {
background: #f8f9fa;
}
.log-table tr:last-child td {
border-bottom: none;
}
.username {
font-weight: 600;
color: #495057;
}
.token {
font-family: 'Courier New', monospace;
background: #f8f9fa;
padding: 8px 12px;
border-radius: 4px;
font-size: 0.85rem;
color: #6c757d;
word-break: break-all;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
border: 1px solid #e9ecef;
}
.token:hover {
background: #e9ecef;
border-color: #667eea;
}
.token::after {
content: "点击复制";
position: absolute;
top: -30px;
left: 50%;
transform: translateX(-50%);
background: #333;
color: white;
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s ease;
white-space: nowrap;
}
.token:hover::after {
opacity: 1;
}
.copy-success {
background: #d4edda !important;
border-color: #28a745 !important;
color: #155724 !important;
}
.content {
word-wrap: break-word;
line-height: 1.4;
}
.timestamp {
color: #6c757d;
font-size: 0.9rem;
}
.pagination {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
margin-top: 30px;
flex-wrap: wrap;
}
.pagination .page-size-container {
margin: 0;
}
.pagination-controls {
display: flex;
align-items: center;
gap: 10px;
}
.pagination button {
padding: 8px 12px;
border: 1px solid #dee2e6;
background: white;
cursor: pointer;
border-radius: 5px;
transition: all 0.3s ease;
}
.pagination button:hover:not(:disabled) {
background: #667eea;
color: white;
border-color: #667eea;
}
.pagination button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.pagination .active {
background: #667eea;
color: white;
border-color: #667eea;
}
.page-info {
color: #6c757d;
margin: 0 15px;
}
.no-data {
text-align: center;
padding: 60px 20px;
color: #6c757d;
}
.no-data i {
font-size: 4rem;
margin-bottom: 20px;
opacity: 0.5;
}
@media (max-width: 768px) {
.container {
margin: 10px;
border-radius: 10px;
}
.header {
padding: 20px;
}
.header h1 {
font-size: 2rem;
}
.controls {
padding: 20px;
}
.search-container {
flex-direction: column;
align-items: stretch;
}
.search-input {
min-width: auto;
}
.stats {
justify-content: center;
}
.content {
padding: 20px;
}
.log-table {
font-size: 0.9rem;
}
.log-table th,
.log-table td {
padding: 10px 8px;
}
.error-content {
max-width: 200px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>日志管理系统</h1>
</div>
<div class="controls">
<div class="search-container">
<input type="text" id="searchInput" class="search-input" placeholder="搜索用户名...">
<button class="btn btn-primary" onclick="searchLogs()">搜索</button>
<button class="btn btn-secondary" onclick="refreshLogs()">刷新</button>
</div>
</div>
<div class="content">
<table class="log-table" id="logTable">
<thead>
<tr>
<th>Type</th>
<th>Source</th>
<th>UID</th>
<th>Username</th>
<th>Token</th>
<th>Content</th>
<th>Timestamp</th>
</tr>
</thead>
<tbody id="logTableBody">
</tbody>
</table>
<div class="no-data" id="noData" style="display: none;">
<div>📋</div>
<h3>暂无数据</h3>
<p>没有找到匹配的错误日志</p>
</div>
<div class="pagination" id="pagination">
<div class="page-size-container">
<label for="pageSize">每页显示:</label>
<select id="pageSize" onchange="changePageSize()">
<option value="20" selected>20条</option>
<option value="40">40条</option>
<option value="60">60条</option>
</select>
</div>
<div class="pagination-controls">
<button onclick="goToPage(1)" id="firstBtn">首页</button>
<button onclick="goToPage(currentPage - 1)" id="prevBtn">上一页</button>
<span class="page-info" id="pageInfo">第 1 页,共 1 页</span>
<button onclick="goToPage(currentPage + 1)" id="nextBtn">下一页</button>
<button onclick="goToPage(totalPages)" id="lastBtn">末页</button>
</div>
</div>
</div>
</div>
<script>
const data = {{ data | tojson}};
// 分页配置
let currentPage = 1;
let pageSize = 20;
let totalPages = 1;
let filteredLogs = [...data];
let searchTerm = '';
// 初始化页面
function initPage() {
renderLogs();
updatePagination();
}
// 改变每页显示数量
function changePageSize() {
const select = document.getElementById('pageSize');
pageSize = parseInt(select.value);
currentPage = 1; // 重置到第一页
renderLogs();
updatePagination();
}
// 渲染日志表格
function renderLogs() {
const tbody = document.getElementById('logTableBody');
const noData = document.getElementById('noData');
const table = document.getElementById('logTable');
if (filteredLogs.length === 0) {
table.style.display = 'none';
noData.style.display = 'block';
return;
}
table.style.display = 'table';
noData.style.display = 'none';
totalPages = Math.ceil(filteredLogs.length / pageSize);
const startIndex = (currentPage - 1) * pageSize;
const endIndex = startIndex + pageSize;
const currentLogs = filteredLogs.slice(startIndex, endIndex);
tbody.innerHTML = '';
currentLogs.forEach(log => {
const row = document.createElement('tr');
row.innerHTML = `
<td>
<div class="type">${log.type}</div>
</td>
<td>
<div class="uid">${log.source}</div>
</td>
<td>
<div class="uid">${log.uid}</div>
</td>
<td>
<div class="username">${log.username}</div>
</td>
<td>
<div class="token" onclick="copyToken('${log.token}')" title="点击复制">${log.token}</div>
</td>
<td>
<div class="content">${log.content}</div>
</td>
<td>
<div class="timestamp">${log.timestamp}</div>
</td>
`;
tbody.appendChild(row);
});
}
// 复制token到剪贴板
function copyToken(token) {
navigator.clipboard.writeText(token).then(function() {
// 显示复制成功的视觉反馈
const tokenElements = document.querySelectorAll('.token');
tokenElements.forEach(el => {
if (el.textContent === token) {
el.classList.add('copy-success');
setTimeout(() => {
el.classList.remove('copy-success');
}, 1000);
}
});
}).catch(function(err) {
console.error('复制失败: ', err);
// 降级方案:使用旧的复制方法
const textArea = document.createElement('textarea');
textArea.value = token;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
});
}
// 更新分页控件
function updatePagination() {
const pageInfo = document.getElementById('pageInfo');
const firstBtn = document.getElementById('firstBtn');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
const lastBtn = document.getElementById('lastBtn');
pageInfo.textContent = `第 ${currentPage} 页,共 ${totalPages} 页`;
firstBtn.disabled = currentPage === 1;
prevBtn.disabled = currentPage === 1;
nextBtn.disabled = currentPage === totalPages;
lastBtn.disabled = currentPage === totalPages;
}
// 跳转到指定页面
function goToPage(page) {
if (page < 1 || page > totalPages) return;
currentPage = page;
renderLogs();
updatePagination();
}
// 搜索日志
function searchLogs() {
searchTerm = document.getElementById('searchInput').value.trim();
if (searchTerm === '') {
filteredLogs = [...data];
} else {
filteredLogs = data.filter(log =>
log.username.toLowerCase().includes(searchTerm.toLowerCase())
);
}
currentPage = 1;
renderLogs();
updatePagination();
}
// 刷新日志
function refreshLogs() {
// 模拟刷新数据
console.log('刷新日志数据...');
initPage();
}
// 监听回车键搜索
document.getElementById('searchInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
searchLogs();
}
});
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', initPage);
</script>
</body>
</html> |