Spaces:
Running
Running
File size: 24,055 Bytes
7416023 082ede4 7416023 88be5d0 082ede4 7416023 082ede4 7416023 082ede4 7416023 88be5d0 7416023 88be5d0 7416023 88be5d0 7416023 082ede4 7416023 88be5d0 7416023 88be5d0 7416023 88be5d0 7416023 88be5d0 7416023 88be5d0 7416023 88be5d0 7416023 88be5d0 7416023 88be5d0 7416023 88be5d0 |
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 |
<!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);
}
.date-filter-container {
display: flex;
align-items: center;
gap: 15px;
margin-top: 20px;
flex-wrap: wrap;
}
.date-input-group {
display: flex;
align-items: center;
gap: 8px;
}
.date-input-group label {
font-weight: 500;
color: #495057;
min-width: 60px;
}
.date-input-group input[type="date"] {
padding: 10px 15px;
border: 2px solid #e9ecef;
border-radius: 8px;
font-size: 14px;
background: white;
cursor: pointer;
transition: all 0.3s ease;
}
.date-input-group input[type="date"]:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.date-shortcuts {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.date-shortcut-btn {
padding: 8px 15px;
border: 1px solid #e9ecef;
background: white;
border-radius: 8px;
cursor: pointer;
font-size: 13px;
color: #495057;
transition: all 0.3s ease;
}
.date-shortcut-btn:hover {
background: #667eea;
color: white;
border-color: #667eea;
}
.date-shortcut-btn.active {
background: #667eea;
color: white;
border-color: #667eea;
}
.main {
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 {
width: 200px;
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 {
width: 300px;
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;
}
.date-filter-container {
flex-direction: column;
align-items: stretch;
}
.date-input-group {
flex-direction: column;
}
.date-input-group label {
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 class="date-filter-container">
<div class="date-input-group">
<label for="fromDate">开始日期:</label>
<input type="date" id="fromDate">
</div>
<div class="date-input-group">
<label for="toDate">结束日期:</label>
<input type="date" id="toDate">
</div>
<button class="btn btn-primary" onclick="filterByDate()">过滤</button>
<div class="date-shortcuts">
<button class="date-shortcut-btn" onclick="setDateRange('today')">今天</button>
<button class="date-shortcut-btn" onclick="setDateRange('week')">最近7天</button>
<button class="date-shortcut-btn" onclick="setDateRange('month')">最近30天</button>
<button class="date-shortcut-btn" onclick="setDateRange('all')">全部</button>
</div>
</div>
</div>
<div class="main">
<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 = '';
let currentDateFilter = null; // 记录当前的日期过滤范围
// 初始化页面
function initPage() {
// 从URL参数中读取日期范围
const urlParams = new URLSearchParams(window.location.search);
const fromDate = urlParams.get('from_date');
const toDate = urlParams.get('to_date');
if (fromDate) {
document.getElementById('fromDate').value = fromDate;
}
if (toDate) {
document.getElementById('toDate').value = toDate;
}
renderLogs();
updatePagination();
}
// 获取今天的日期(YYYY-MM-DD格式)
function getTodayDate() {
const today = new Date();
return today.toISOString().split('T')[0];
}
// 获取指定天数前的日期
function getDateBefore(days) {
const date = new Date();
date.setDate(date.getDate() - days);
return date.toISOString().split('T')[0];
}
// 设置日期范围快捷选项
function setDateRange(range) {
const today = getTodayDate();
switch(range) {
case 'today':
document.getElementById('fromDate').value = today;
document.getElementById('toDate').value = today;
break;
case 'week':
document.getElementById('fromDate').value = getDateBefore(6);
document.getElementById('toDate').value = today;
break;
case 'month':
document.getElementById('fromDate').value = getDateBefore(29);
document.getElementById('toDate').value = today;
break;
case 'all':
document.getElementById('fromDate').value = '';
document.getElementById('toDate').value = '';
break;
}
// 更新快捷按钮的active状态
updateShortcutButtons(range);
}
// 更新快捷按钮的样式
function updateShortcutButtons(active) {
const buttons = document.querySelectorAll('.date-shortcut-btn');
buttons.forEach((btn, index) => {
const ranges = ['today', 'week', 'month', 'all'];
btn.classList.remove('active');
if (ranges[index] === active) {
btn.classList.add('active');
}
});
}
// 按日期过滤
function filterByDate() {
const fromDate = document.getElementById('fromDate').value;
const toDate = document.getElementById('toDate').value;
if (!fromDate && !toDate) {
// 如果两个都为空,加载所有数据
currentDateFilter = null;
refreshFromServer(null, null);
return;
}
if (fromDate && toDate) {
if (fromDate > toDate) {
alert('开始日期不能晚于结束日期');
return;
}
}
// 记录当前的日期过滤
currentDateFilter = { from_date: fromDate, to_date: toDate };
// 刷新并带上日期参数
refreshFromServer(fromDate, toDate);
}
// 从服务器刷新数据,支持日期参数
function refreshFromServer(fromDate, toDate) {
let url = window.location.pathname;
const params = new URLSearchParams();
if (fromDate) {
params.append('from_date', fromDate);
}
if (toDate) {
params.append('to_date', toDate);
}
if (params.toString()) {
url += '?' + params.toString();
}
// 重新加载页面
window.location.href = url;
}
// 改变每页显示数量
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() {
// 如果有日期过滤,使用带日期参数的刷新
if (currentDateFilter) {
refreshFromServer(currentDateFilter.from_date, currentDateFilter.to_date);
} else {
// 获取当前的URL参数
const urlParams = new URLSearchParams(window.location.search);
const fromDate = urlParams.get('from_date');
const toDate = urlParams.get('to_date');
if (fromDate || toDate) {
refreshFromServer(fromDate, toDate);
} else {
// 模拟刷新数据
console.log('刷新日志数据...');
currentPage = 1;
renderLogs();
updatePagination();
}
}
}
// 监听回车键搜索
document.getElementById('searchInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
searchLogs();
}
});
// 监听日期输入框的回车键
document.getElementById('fromDate').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
filterByDate();
}
});
document.getElementById('toDate').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
filterByDate();
}
});
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', initPage);
</script>
</body>
</html>
|