-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultCompare.html
More file actions
253 lines (233 loc) · 8.03 KB
/
Copy pathResultCompare.html
File metadata and controls
253 lines (233 loc) · 8.03 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图片对比工具</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.control-panel {
margin-bottom: 20px;
}
.folder-list {
margin: 10px 0;
}
.folder-item {
margin: 5px 0;
display: flex;
align-items: center;
gap: 10px;
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
th {
background-color: #f4f4f4;
}
.image-cell {
padding: 5px;
}
.image-cell img {
max-width: 100%;
height: auto;
}
.size-control {
display: flex;
align-items: center;
gap: 10px;
margin: 10px 0;
}
button {
padding: 5px 10px;
cursor: pointer;
}
.preview-modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 1000;
}
.preview-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 90%;
max-height: 90%;
}
.preview-content img {
max-width: 100%;
max-height: 90vh;
}
.close-preview {
position: absolute;
top: 10px;
right: 20px;
color: white;
font-size: 30px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="control-panel">
<h2>图片对比工具</h2>
<button onclick="addFolder()">添加文件夹</button>
<div class="size-control">
<label>图片大小:</label>
<input type="range" id="sizeSlider" min="100" max="800" value="300" oninput="updateImageSize(this.value)">
<span id="sizeValue">300px</span>
</div>
<div id="folderList" class="folder-list"></div>
</div>
<table id="comparisonTable">
<thead>
<tr>
<th>文件名</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div id="previewModal" class="preview-modal">
<span class="close-preview" onclick="closePreview()">×</span>
<div class="preview-content">
<img id="previewImage" src="" alt="预览">
</div>
</div>
<script>
let folders = [];
let currentImageSize = 300;
// 添加文件夹
async function addFolder() {
try {
// 创建文件选择器
const input = document.createElement('input');
input.type = 'file';
input.webkitdirectory = true;
input.multiple = true;
input.onchange = function(e) {
const files = Array.from(e.target.files);
const folderName = files[0]?.webkitRelativePath.split('/')[0] || '未命名文件夹';
// 过滤图片文件
const imageFiles = files.filter(file =>
file.type.startsWith('image/') ||
file.name.match(/\.(jpg|jpeg|png|gif|bmp|webp)$/i)
);
folders.push({
name: folderName,
files: imageFiles
});
updateFolderList();
updateTable();
};
input.click();
} catch (error) {
console.error('Error adding folder:', error);
alert('添加文件夹失败: ' + error.message);
}
}
// 更新文件夹列表显示
function updateFolderList() {
const folderList = document.getElementById('folderList');
folderList.innerHTML = folders.map((folder, index) => `
<div class="folder-item">
<input type="text" value="${folder.name}"
onchange="updateFolderName(${index}, this.value)">
<button onclick="removeFolder(${index})">删除</button>
<span>(${folder.files.length} 个图片)</span>
</div>
`).join('');
// 更新表格头部
const headerRow = document.querySelector('#comparisonTable thead tr');
headerRow.innerHTML = '<th>文件名</th>' +
folders.map(folder => `<th>${folder.name}</th>`).join('');
}
// 更新文件夹名称
function updateFolderName(index, newName) {
folders[index].name = newName;
updateFolderList();
}
// 删除文件夹
function removeFolder(index) {
folders.splice(index, 1);
updateFolderList();
updateTable();
}
// 更新图片大小
function updateImageSize(size) {
currentImageSize = size;
document.getElementById('sizeValue').textContent = size + 'px';
updateTable();
}
// 更新表格内容
function updateTable() {
if (folders.length === 0) {
document.querySelector('#comparisonTable tbody').innerHTML = '';
return;
}
// 收集所有唯一的文件名
const allFileNames = new Set();
folders.forEach(folder => {
folder.files.forEach(file => {
allFileNames.add(file.name);
});
});
// 创建表格内容
const tbody = document.querySelector('#comparisonTable tbody');
tbody.innerHTML = Array.from(allFileNames).map(fileName => {
const row = `
<tr>
<td>${fileName}</td>
${folders.map(folder => {
const file = folder.files.find(f => f.name === fileName);
if (file) {
const url = URL.createObjectURL(file);
return `
<td class="image-cell">
<img src="${url}"
alt="${fileName}"
style="max-width: ${currentImageSize}px; max-height: ${currentImageSize}px;"
onclick="showPreview('${url}')">
</td>
`;
}
return '<td>-</td>';
}).join('')}
</tr>
`;
return row;
}).join('');
}
// 显示图片预览
function showPreview(url) {
const modal = document.getElementById('previewModal');
const previewImage = document.getElementById('previewImage');
previewImage.src = url;
modal.style.display = 'block';
}
// 关闭预览
function closePreview() {
const modal = document.getElementById('previewModal');
modal.style.display = 'none';
}
// 点击预览模态框背景关闭预览
document.getElementById('previewModal').addEventListener('click', function(e) {
if (e.target === this) {
closePreview();
}
});
</script>
</body>
</html>