-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensitive_data_viewer.html
More file actions
843 lines (717 loc) · 30.1 KB
/
sensitive_data_viewer.html
File metadata and controls
843 lines (717 loc) · 30.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
<!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: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', Arial, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f5f5f5;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
header {
background-color: #2c3e50;
color: white;
padding: 20px;
text-align: center;
}
.upload-section {
padding: 30px;
text-align: center;
border-bottom: 1px solid #eee;
}
.upload-btn {
background-color: #3498db;
color: white;
border: none;
padding: 12px 24px;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
margin-bottom: 15px;
}
.upload-btn:hover {
background-color: #2980b9;
}
#file-input {
display: none;
}
.file-info {
margin-top: 15px;
color: #666;
font-style: italic;
}
.filters {
padding: 20px;
background-color: #f9f9f9;
border-bottom: 1px solid #eee;
}
.filter-group {
display: flex;
flex-wrap: wrap;
gap: 15px;
align-items: flex-end;
}
.filter-item {
flex: 1;
min-width: 200px;
}
.filter-item label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.filter-item input,
.filter-item select {
width: 100%;
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
.results-section {
padding: 20px;
}
.db-table-map-section {
margin-bottom: 30px;
padding: 20px;
background-color: #f8f9fa;
border-radius: 8px;
}
.db-table-map-section h3 {
margin-bottom: 15px;
color: #333;
font-size: 18px;
}
.table-list {
list-style-type: none;
padding-left: 10px;
margin: 0;
}
.table-list li {
padding: 2px 0;
position: relative;
}
.table-list li::before {
content: '•';
color: #3498db;
font-weight: bold;
position: absolute;
left: -10px;
}
.table-count {
font-weight: bold;
color: #e74c3c;
}
.results-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.results-count {
color: #666;
}
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.data-table th,
.data-table td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #eee;
word-break: break-word;
}
.sample-data-cell {
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
cursor: help;
position: relative;
}
.sample-data-cell:hover {
white-space: normal;
background-color: #f9f9f9;
z-index: 1;
}
.data-table th {
background-color: #f2f2f2;
font-weight: bold;
color: #555;
cursor: pointer;
position: relative;
}
.data-table th:hover {
background-color: #e9e9e9;
}
.data-table th:after {
content: ' ';
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
}
.data-table th.sort-asc:after {
border-bottom: 5px solid #666;
}
.data-table th.sort-desc:after {
border-top: 5px solid #666;
}
.data-table tr:hover {
background-color: #f9f9f9;
}
.highlight {
background-color: #fffacd;
font-weight: bold;
}
.pagination {
margin-top: 20px;
display: flex;
justify-content: center;
gap: 10px;
}
.page-btn {
padding: 8px 12px;
border: 1px solid #ddd;
background-color: white;
cursor: pointer;
border-radius: 4px;
transition: all 0.3s;
}
.page-btn:hover:not(:disabled) {
background-color: #f2f2f2;
}
.page-btn.active {
background-color: #3498db;
color: white;
border-color: #3498db;
}
.page-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.summary-stats {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 20px;
}
.stat-card {
flex: 1;
min-width: 150px;
background-color: #f8f9fa;
padding: 20px;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}
.stat-number {
font-size: 28px;
font-weight: bold;
color: #3498db;
margin-bottom: 5px;
}
.stat-label {
color: #666;
font-size: 14px;
}
.loading {
text-align: center;
padding: 40px;
color: #666;
}
.loading::after {
content: '加载中...';
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.no-data {
text-align: center;
padding: 40px;
color: #666;
font-style: italic;
}
@media (max-width: 768px) {
.filter-group {
flex-direction: column;
}
.filter-item {
min-width: 100%;
}
.data-table {
font-size: 12px;
}
.data-table th,
.data-table td {
padding: 8px 5px;
}
.summary-stats {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>敏感数据探测结果可视化</h1>
<p>上传JSON文件,以表格形式查看敏感数据探测结果</p>
</header>
<div class="upload-section">
<button class="upload-btn" onclick="document.getElementById('file-input').click()">选择JSON文件</button>
<input type="file" id="file-input" accept=".json" />
<div class="file-info" id="file-info">未选择文件</div>
</div>
<div class="filters" id="filters" style="display: none;">
<h3>筛选条件</h3>
<div class="filter-group">
<div class="filter-item">
<label for="db-filter">数据库</label>
<select id="db-filter"></select>
</div>
<div class="filter-item">
<label for="table-filter">表名</label>
<select id="table-filter"></select>
</div>
<div class="filter-item">
<label for="keyword-filter">关键词</label>
<select id="keyword-filter"></select>
</div>
<div class="filter-item">
<label for="search-input">搜索</label>
<input type="text" id="search-input" placeholder="输入搜索内容..." />
</div>
</div>
</div>
<div class="results-section">
<div class="summary-stats" id="summary-stats" style="display: none;">
<div class="stat-card">
<div class="stat-number" id="total-records">0</div>
<div class="stat-label">总记录数</div>
</div>
<div class="stat-card">
<div class="stat-number" id="total-databases">0</div>
<div class="stat-label">涉及数据库</div>
</div>
<div class="stat-card">
<div class="stat-number" id="total-tables">0</div>
<div class="stat-label">敏感表数</div>
</div>
<div class="stat-card">
<div class="stat-number" id="total-fields">0</div>
<div class="stat-label">敏感字段</div>
</div>
</div>
<div class="db-table-map-section">
<h3>敏感信息数据库-表映射</h3>
<div id="db-table-map-container" style="display: none;">
<div class="no-data">暂无映射数据</div>
</div>
</div>
<div class="results-header">
<h2>敏感数据探测结果</h2>
<div class="results-count">显示 <span id="showing-count">0</span> 条记录</div>
</div>
<div id="results-container">
<div class="no-data">请上传JSON文件以查看结果</div>
</div>
</div>
</div>
<script>
let originalData = [];
let filteredData = [];
let currentPage = 1;
const rowsPerPage = 10;
let sortColumn = '';
let sortDirection = 'asc';
// 监听文件选择
document.getElementById('file-input').addEventListener('change', handleFileSelect);
// 监听筛选条件变化
document.getElementById('db-filter').addEventListener('change', applyFilters);
document.getElementById('table-filter').addEventListener('change', applyFilters);
document.getElementById('keyword-filter').addEventListener('change', applyFilters);
document.getElementById('search-input').addEventListener('input', applyFilters);
// 处理文件选择
function handleFileSelect(event) {
const file = event.target.files[0];
if (!file) return;
if (file.type !== 'application/json' && !file.name.endsWith('.json')) {
alert('请上传JSON格式的文件!');
return;
}
document.getElementById('file-info').textContent = `已选择文件: ${file.name}`;
document.getElementById('results-container').innerHTML = '<div class="loading"></div>';
const reader = new FileReader();
reader.onload = function(e) {
try {
originalData = JSON.parse(e.target.result);
if (!Array.isArray(originalData)) {
// 如果JSON不是数组,尝试查找包含敏感数据的数组
if (originalData.sensitive_data && Array.isArray(originalData.sensitive_data)) {
originalData = originalData.sensitive_data;
} else {
throw new Error('JSON格式不正确,需要包含敏感数据数组');
}
}
// 检查数据格式是否符合预期
if (originalData.length > 0 && !originalData[0].hasOwnProperty('敏感字段详情')) {
throw new Error('JSON格式不符合敏感数据探测结果的格式要求');
}
initializeFilters();
updateSummaryStats();
applyFilters();
renderDatabaseTableMap();
document.getElementById('filters').style.display = 'block';
document.getElementById('summary-stats').style.display = 'flex';
} catch (error) {
document.getElementById('results-container').innerHTML = `<div class="no-data">解析JSON文件失败: ${error.message}</div>`;
console.error('解析JSON失败:', error);
}
};
reader.readAsText(file);
}
// 初始化筛选器
function initializeFilters() {
// 提取唯一值
const databases = [...new Set(originalData.map(item =>
`${item['数据库类型']}-${item['数据库名']}` || 'N/A'
))];
const tables = [...new Set(originalData.map(item => item['表名'] || 'N/A'))];
// 从敏感字段详情中提取所有敏感关键词
const keywordsSet = new Set();
originalData.forEach(item => {
if (item['敏感字段详情'] && Array.isArray(item['敏感字段详情'])) {
item['敏感字段详情'].forEach(field => {
if (field.is_sensitive && field.sensitive_type) {
keywordsSet.add(field.sensitive_type);
}
});
}
});
const keywords = Array.from(keywordsSet);
// 填充下拉框
populateSelect('db-filter', databases);
populateSelect('table-filter', tables);
populateSelect('keyword-filter', keywords);
}
// 填充下拉框
function populateSelect(elementId, options) {
const select = document.getElementById(elementId);
select.innerHTML = '<option value="">全部</option>';
options.sort().forEach(option => {
if (option && option.trim()) {
const opt = document.createElement('option');
opt.value = option;
opt.textContent = option;
select.appendChild(opt);
}
});
}
// 更新统计信息
function updateSummaryStats() {
const databases = [...new Set(originalData.map(item =>
`${item['数据库类型']}-${item['数据库名']}` || 'N/A'
))];
const tables = [...new Set(originalData.map(item => item['表名'] || 'N/A'))];
// 计算敏感字段总数
let sensitiveFieldsCount = 0;
originalData.forEach(item => {
sensitiveFieldsCount += item['敏感字段数'] || 0;
});
document.getElementById('total-records').textContent = originalData.length;
document.getElementById('total-databases').textContent = databases.filter(db => db !== 'N/A').length;
document.getElementById('total-tables').textContent = tables.filter(table => table !== 'N/A').length;
document.getElementById('total-fields').textContent = sensitiveFieldsCount;
}
// 应用筛选条件
function applyFilters() {
const dbFilter = document.getElementById('db-filter').value;
const tableFilter = document.getElementById('table-filter').value;
const keywordFilter = document.getElementById('keyword-filter').value;
const searchTerm = document.getElementById('search-input').value.toLowerCase();
// 扁平化数据,将每个表的敏感字段详情转换为独立行
let flattenedData = [];
originalData.forEach(item => {
if (item['敏感字段详情'] && Array.isArray(item['敏感字段详情'])) {
item['敏感字段详情'].forEach(field => {
if (field.is_sensitive) {
flattenedData.push({
'数据库类型': item['数据库类型'],
'数据库名': item['数据库名'],
'完整数据库': `${item['数据库类型']}-${item['数据库名']}`,
'表名': item['表名'],
'字段名': field.column_name,
'字段类型': field.column_type,
'敏感类型': field.sensitive_type,
'字段注释': field.column_comment,
'样本数据': extractSampleData(item, field.column_name)
});
}
});
}
});
filteredData = flattenedData.filter(item => {
// 数据库筛选
if (dbFilter && item['完整数据库'] !== dbFilter) return false;
// 表名筛选
if (tableFilter && item['表名'] !== tableFilter) return false;
// 关键词筛选
if (keywordFilter && item['敏感类型'] !== keywordFilter) return false;
// 搜索筛选
if (searchTerm) {
const searchFields = [
item['完整数据库'] || '',
item['表名'] || '',
item['字段名'] || '',
item['字段类型'] || '',
item['敏感类型'] || '',
item['字段注释'] || '',
item['样本数据'] || ''
];
return searchFields.some(field =>
field.toLowerCase().includes(searchTerm)
);
}
return true;
});
// 更新统计信息显示
document.getElementById('showing-count').textContent = filteredData.length;
// 应用排序
if (sortColumn) {
sortData(sortColumn, sortDirection);
}
currentPage = 1;
renderTable();
}
// 从数据行中提取样本数据
function extractSampleData(tableItem, columnName) {
if (tableItem.rows && Array.isArray(tableItem.rows) && tableItem.rows.length > 0) {
const firstRow = tableItem.rows[0];
if (firstRow.hasOwnProperty(columnName)) {
return String(firstRow[columnName]);
}
}
return '无';
}
// 排序数据
function sortData(column, direction) {
filteredData.sort((a, b) => {
let aValue = a[column] || '';
let bValue = b[column] || '';
// 转换为字符串进行比较
if (typeof aValue !== 'string') aValue = String(aValue);
if (typeof bValue !== 'string') bValue = String(bValue);
if (direction === 'asc') {
return aValue.localeCompare(bValue, 'zh-CN');
} else {
return bValue.localeCompare(aValue, 'zh-CN');
}
});
}
// 处理表头点击排序
function handleSort(column) {
if (sortColumn === column) {
// 切换排序方向
sortDirection = sortDirection === 'asc' ? 'desc' : 'asc';
} else {
// 新列排序,重置为升序
sortColumn = column;
sortDirection = 'asc';
}
// 更新表头样式
document.querySelectorAll('.data-table th').forEach(th => {
th.classList.remove('sort-asc', 'sort-desc');
});
document.querySelector(`[data-sort="${column}"]`).classList.add(`sort-${sortDirection}`);
applyFilters();
}
// 渲染数据库-表映射表格
function renderDatabaseTableMap() {
// 创建数据库-表映射
const dbTableMap = {};
originalData.forEach(item => {
const dbName = `${item['数据库类型']}-${item['数据库名']}` || 'N/A';
const tableName = item['表名'] || 'N/A';
if (dbName !== 'N/A' && tableName !== 'N/A') {
if (!dbTableMap[dbName]) {
dbTableMap[dbName] = new Set();
}
dbTableMap[dbName].add(tableName);
}
});
const container = document.getElementById('db-table-map-container');
if (Object.keys(dbTableMap).length === 0) {
container.innerHTML = '<div class="no-data">没有找到敏感信息的数据库和表</div>';
container.style.display = 'block';
return;
}
let tableHTML = `
<table class="data-table">
<thead>
<tr>
<th>数据库名称</th>
<th>包含敏感信息的表</th>
<th>表数量</th>
</tr>
</thead>
<tbody>
`;
Object.entries(dbTableMap).forEach(([dbName, tables]) => {
const tablesArray = Array.from(tables);
const tablesCount = tablesArray.length;
tableHTML += `<tr>
<td style="vertical-align: top;">${dbName}</td>
<td style="vertical-align: top;">
<ul class="table-list">
${tablesArray.map(table => `<li>${table}</li>`).join('')}
</ul>
</td>
<td style="vertical-align: top;" class="table-count">${tablesCount}</td>
</tr>`;
});
tableHTML += '</tbody></table>';
container.innerHTML = tableHTML;
container.style.display = 'block';
}
// 渲染表格
function renderTable() {
const startIndex = (currentPage - 1) * rowsPerPage;
const endIndex = startIndex + rowsPerPage;
const currentData = filteredData.slice(startIndex, endIndex);
if (currentData.length === 0) {
document.getElementById('results-container').innerHTML = '<div class="no-data">没有符合条件的记录</div>';
return;
}
let tableHTML = `
<table class="data-table">
<thead>
<tr>
<th data-sort="完整数据库" onclick="handleSort('完整数据库')">数据库</th>
<th data-sort="表名" onclick="handleSort('表名')">表名</th>
<th data-sort="字段名" onclick="handleSort('字段名')">字段名</th>
<th data-sort="字段类型" onclick="handleSort('字段类型')">字段类型</th>
<th data-sort="敏感类型" onclick="handleSort('敏感类型')">敏感类型</th>
<th data-sort="字段注释" onclick="handleSort('字段注释')">字段注释</th>
<th data-sort="样本数据" onclick="handleSort('样本数据')">数据样本</th>
</tr>
</thead>
<tbody>
`;
const searchTerm = document.getElementById('search-input').value.toLowerCase();
currentData.forEach(row => {
tableHTML += '<tr>';
// 数据库
let dbCell = row['完整数据库'] || 'N/A';
if (searchTerm && dbCell.toLowerCase().includes(searchTerm)) {
dbCell = highlightText(dbCell, searchTerm);
}
tableHTML += `<td>${dbCell}</td>`;
// 表名
let tableCell = row['表名'] || 'N/A';
if (searchTerm && tableCell.toLowerCase().includes(searchTerm)) {
tableCell = highlightText(tableCell, searchTerm);
}
tableHTML += `<td>${tableCell}</td>`;
// 字段名
let fieldCell = row['字段名'] || 'N/A';
if (searchTerm && fieldCell.toLowerCase().includes(searchTerm)) {
fieldCell = highlightText(fieldCell, searchTerm);
}
tableHTML += `<td>${fieldCell}</td>`;
// 字段类型
let typeCell = row['字段类型'] || 'N/A';
if (searchTerm && typeCell.toLowerCase().includes(searchTerm)) {
typeCell = highlightText(typeCell, searchTerm);
}
tableHTML += `<td>${typeCell}</td>`;
// 敏感类型
let sensitiveCell = row['敏感类型'] || 'N/A';
if (searchTerm && sensitiveCell.toLowerCase().includes(searchTerm)) {
sensitiveCell = highlightText(sensitiveCell, searchTerm);
}
tableHTML += `<td>${sensitiveCell}</td>`;
// 字段注释
let commentCell = row['字段注释'] || 'N/A';
if (searchTerm && commentCell.toLowerCase().includes(searchTerm)) {
commentCell = highlightText(commentCell, searchTerm);
}
tableHTML += `<td>${commentCell}</td>`;
// 数据样本
let fullSampleCell = row['样本数据'] || '无';
let sampleCell = fullSampleCell;
if (sampleCell.length > 50) {
sampleCell = sampleCell.substring(0, 50) + '...';
}
if (searchTerm && sampleCell.toLowerCase().includes(searchTerm)) {
sampleCell = highlightText(sampleCell, searchTerm);
}
tableHTML += `<td class="sample-data-cell" title="${fullSampleCell}">${sampleCell}</td>`;
tableHTML += '</tr>';
});
tableHTML += '</tbody></table>';
// 添加分页
const totalPages = Math.ceil(filteredData.length / rowsPerPage);
let paginationHTML = '<div class="pagination">';
paginationHTML += `<button class="page-btn" onclick="changePage(1)" ${currentPage === 1 ? 'disabled' : ''}>首页</button>`;
paginationHTML += `<button class="page-btn" onclick="changePage(${currentPage - 1})" ${currentPage === 1 ? 'disabled' : ''}>上一页</button>`;
// 页码按钮
const maxVisiblePages = 5;
let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
if (endPage - startPage + 1 < maxVisiblePages) {
startPage = Math.max(1, endPage - maxVisiblePages + 1);
}
for (let i = startPage; i <= endPage; i++) {
paginationHTML += `<button class="page-btn ${currentPage === i ? 'active' : ''}" onclick="changePage(${i})")>${i}</button>`;
}
paginationHTML += `<button class="page-btn" onclick="changePage(${currentPage + 1})" ${currentPage === totalPages ? 'disabled' : ''}>下一页</button>`;
paginationHTML += `<button class="page-btn" onclick="changePage(${totalPages})" ${currentPage === totalPages ? 'disabled' : ''}>末页</button>`;
paginationHTML += '</div>';
document.getElementById('results-container').innerHTML = tableHTML + paginationHTML;
// 应用排序样式
if (sortColumn) {
document.querySelector(`[data-sort="${sortColumn}"]`).classList.add(`sort-${sortDirection}`);
}
}
// 高亮搜索文本
function highlightText(text, searchTerm) {
const regex = new RegExp(`(${searchTerm})`, 'gi');
return text.replace(regex, '<span class="highlight">$1</span>');
}
// 切换页面
function changePage(page) {
currentPage = page;
renderTable();
}
</script>
</body>
</html>