yaoqifa commited on
Commit
b09c3f8
·
verified ·
1 Parent(s): 8c36c80

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +77 -65
static/index.html CHANGED
@@ -54,7 +54,6 @@
54
  border-color: var(--accent-color);
55
  }
56
 
57
- /* --- 修正样式:支持多图预览 --- */
58
  .file-upload-wrapper {
59
  position: relative;
60
  border: 2px dashed #4a5568;
@@ -80,10 +79,10 @@
80
  margin-top: 10px;
81
  position: relative;
82
  flex-wrap: wrap;
83
- gap: 8px;
84
  }
85
 
86
- /* 缩略图样式 */
87
  .thumb-wrapper {
88
  position: relative;
89
  width: 80px;
@@ -97,24 +96,39 @@
97
  border: 1px solid #4a5568;
98
  }
99
 
100
- .clear-preview-btn {
 
101
  position: absolute;
102
- top: -10px;
103
- right: -10px;
104
  background: var(--danger-color);
105
  color: white;
106
  border: none;
107
  border-radius: 50%;
108
- width: 24px;
109
- height: 24px;
110
  cursor: pointer;
 
111
  font-weight: bold;
112
- line-height: 24px;
113
  text-align: center;
114
  padding: 0;
115
- z-index: 10;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  }
117
- /* --------------------------------- */
118
 
119
  button {
120
  width: 100%;
@@ -281,13 +295,14 @@
281
  <label>参考图 (支持多选,Chat模型可理解多图)</label>
282
  <div class="file-upload-wrapper" id="upload-box">
283
  <span class="upload-placeholder" id="upload-text">点击或拖拽上传图片 (支持多选)</span>
284
- <!-- 增加了 multiple 属性 -->
285
  <input type="file" id="init_image_input" accept="image/jpeg, image/png" multiple>
286
  </div>
287
  <div class="preview-container" id="preview-container">
288
- <button class="clear-preview-btn" onclick="clearImagePreview()">×</button>
289
- <!-- 动态插入缩略图 -->
290
- </div>
 
 
291
  </div>
292
  <div class="disclaimer-box">
293
  <strong>⚠️ 免责声明 (Disclaimer)</strong>
@@ -311,73 +326,73 @@
311
  </div>
312
 
313
  <script>
314
- let initImagesList = []; // 改为数组存储多张图片
315
 
316
- // 处理图片上传
317
  const fileInput = document.getElementById('init_image_input');
318
  const previewContainer = document.getElementById('preview-container');
319
  const uploadBox = document.getElementById('upload-box');
320
- const uploadText = document.getElementById('upload-text');
321
 
322
  fileInput.addEventListener('change', async function(e) {
323
  const files = Array.from(e.target.files);
324
  if (!files.length) return;
325
 
326
- // 清空旧数据(或者你可以选择追加,这里选择覆盖逻辑)
327
- initImagesList = [];
328
- // 移除除了清除按钮外的所有子元素
329
- while (previewContainer.children.length > 1) {
330
- previewContainer.removeChild(previewContainer.lastChild);
331
- }
332
 
333
- const readPromises = files.map(file => {
334
- return new Promise((resolve) => {
335
- if (file.size > 10 * 1024 * 1024) {
336
- console.warn(`文件 ${file.name} 太大,已跳过`);
337
- resolve(null);
338
- return;
339
- }
340
  const reader = new FileReader();
341
- reader.onload = function(event) {
342
- resolve({
343
- name: file.name,
344
- data: event.target.result
345
- });
346
- };
347
  reader.readAsDataURL(file);
348
  });
349
- });
350
 
351
- const results = await Promise.all(readPromises);
352
-
353
- results.forEach(res => {
354
- if (res) {
355
- initImagesList.push(res.data);
356
-
357
- // 创建缩略图元素
358
- const div = document.createElement('div');
359
- div.className = 'thumb-wrapper';
360
- const img = document.createElement('img');
361
- img.className = 'thumb-img';
362
- img.src = res.data;
363
- div.appendChild(img);
364
- previewContainer.appendChild(div);
365
  }
366
- });
367
-
368
- if (initImagesList.length > 0) {
369
- previewContainer.style.display = 'flex';
370
- uploadBox.style.display = 'none';
371
  }
 
372
  });
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  function clearImagePreview() {
375
  fileInput.value = '';
376
  initImagesList = [];
377
- // 清空预览DOM
378
- while (previewContainer.children.length > 1) {
379
- previewContainer.removeChild(previewContainer.lastChild);
380
- }
 
381
  previewContainer.style.display = 'none';
382
  uploadBox.style.display = 'block';
383
  }
@@ -423,7 +438,7 @@
423
  ratio: document.getElementById('ratio').value,
424
  scale: document.getElementById('scale').value,
425
  format: document.getElementById('format').value,
426
- init_images: initImagesList // 发送数组
427
  };
428
 
429
  try {
@@ -450,13 +465,10 @@
450
  } catch (error) {
451
  console.error(error);
452
  statusText.innerText = "网络请求失败";
453
- alert("网络请求失败,请检查控制台");
454
  } finally {
455
  if (document.getElementById('agree_chk').checked) {
456
  btn.disabled = false;
457
  btn.innerText = "🚀 开始生成";
458
- } else {
459
- btn.innerText = "🚫 请先勾选免责声明";
460
  }
461
  loader.style.display = 'none';
462
  }
 
54
  border-color: var(--accent-color);
55
  }
56
 
 
57
  .file-upload-wrapper {
58
  position: relative;
59
  border: 2px dashed #4a5568;
 
79
  margin-top: 10px;
80
  position: relative;
81
  flex-wrap: wrap;
82
+ gap: 12px;
83
  }
84
 
85
+ /* 缩略图包裹层 */
86
  .thumb-wrapper {
87
  position: relative;
88
  width: 80px;
 
96
  border: 1px solid #4a5568;
97
  }
98
 
99
+ /* 单独删除按钮样式 */
100
+ .single-remove-btn {
101
  position: absolute;
102
+ top: -8px;
103
+ right: -8px;
104
  background: var(--danger-color);
105
  color: white;
106
  border: none;
107
  border-radius: 50%;
108
+ width: 20px;
109
+ height: 20px;
110
  cursor: pointer;
111
+ font-size: 14px;
112
  font-weight: bold;
113
+ line-height: 20px;
114
  text-align: center;
115
  padding: 0;
116
+ z-index: 11;
117
+ box-shadow: 0 2px 4px rgba(0,0,0,0.3);
118
+ }
119
+
120
+ /* 顶部一键清除按钮(可选保留) */
121
+ .clear-preview-btn {
122
+ background: #4a5568;
123
+ color: white;
124
+ border: none;
125
+ border-radius: 4px;
126
+ padding: 2px 8px;
127
+ cursor: pointer;
128
+ font-size: 0.75rem;
129
+ margin-bottom: 8px;
130
+ width: auto;
131
  }
 
132
 
133
  button {
134
  width: 100%;
 
295
  <label>参考图 (支持多选,Chat模型可理解多图)</label>
296
  <div class="file-upload-wrapper" id="upload-box">
297
  <span class="upload-placeholder" id="upload-text">点击或拖拽上传图片 (支持多选)</span>
 
298
  <input type="file" id="init_image_input" accept="image/jpeg, image/png" multiple>
299
  </div>
300
  <div class="preview-container" id="preview-container">
301
+ <div style="width: 100%; display: flex; justify-content: space-between; align-items: center;">
302
+ <span style="font-size: 0.8rem; color: #a0aec0;">已选择的图片:</span>
303
+ <button class="clear-preview-btn" onclick="clearImagePreview()">全部清空</button>
304
+ </div>
305
+ </div>
306
  </div>
307
  <div class="disclaimer-box">
308
  <strong>⚠️ 免责声明 (Disclaimer)</strong>
 
326
  </div>
327
 
328
  <script>
329
+ let initImagesList = [];
330
 
 
331
  const fileInput = document.getElementById('init_image_input');
332
  const previewContainer = document.getElementById('preview-container');
333
  const uploadBox = document.getElementById('upload-box');
 
334
 
335
  fileInput.addEventListener('change', async function(e) {
336
  const files = Array.from(e.target.files);
337
  if (!files.length) return;
338
 
339
+ previewContainer.style.display = 'flex';
340
+ uploadBox.style.display = 'none';
341
+
342
+ for (const file of files) {
343
+ if (file.size > 10 * 1024 * 1024) continue;
 
344
 
345
+ const base64Data = await new Promise((resolve) => {
 
 
 
 
 
 
346
  const reader = new FileReader();
347
+ reader.onload = (ev) => resolve(ev.target.result);
 
 
 
 
 
348
  reader.readAsDataURL(file);
349
  });
 
350
 
351
+ if (base64Data) {
352
+ initImagesList.push(base64Data);
353
+ renderThumbnail(base64Data);
 
 
 
 
 
 
 
 
 
 
 
354
  }
 
 
 
 
 
355
  }
356
+ e.target.value = ''; // 重置以允许重新选择同一张图
357
  });
358
 
359
+ // 渲染单个缩略图及其删除按钮
360
+ function renderThumbnail(data) {
361
+ const wrapper = document.createElement('div');
362
+ wrapper.className = 'thumb-wrapper';
363
+
364
+ const img = document.createElement('img');
365
+ img.className = 'thumb-img';
366
+ img.src = data;
367
+
368
+ const removeBtn = document.createElement('button');
369
+ removeBtn.className = 'single-remove-btn';
370
+ removeBtn.innerHTML = '×';
371
+ removeBtn.onclick = function() {
372
+ // 从数据列表中删除
373
+ const index = initImagesList.indexOf(data);
374
+ if (index > -1) initImagesList.splice(index, 1);
375
+ // 从界面删除
376
+ wrapper.remove();
377
+ // 如果删光了,恢复上传状态
378
+ if (initImagesList.length === 0) {
379
+ clearImagePreview();
380
+ }
381
+ };
382
+
383
+ wrapper.appendChild(img);
384
+ wrapper.appendChild(removeBtn);
385
+ previewContainer.appendChild(wrapper);
386
+ }
387
+
388
  function clearImagePreview() {
389
  fileInput.value = '';
390
  initImagesList = [];
391
+ // 删除除了标题栏(第一个子节点)外的所有缩略图
392
+ const header = previewContainer.firstElementChild;
393
+ previewContainer.innerHTML = '';
394
+ previewContainer.appendChild(header);
395
+
396
  previewContainer.style.display = 'none';
397
  uploadBox.style.display = 'block';
398
  }
 
438
  ratio: document.getElementById('ratio').value,
439
  scale: document.getElementById('scale').value,
440
  format: document.getElementById('format').value,
441
+ init_images: initImagesList
442
  };
443
 
444
  try {
 
465
  } catch (error) {
466
  console.error(error);
467
  statusText.innerText = "网络请求失败";
 
468
  } finally {
469
  if (document.getElementById('agree_chk').checked) {
470
  btn.disabled = false;
471
  btn.innerText = "🚀 开始生成";
 
 
472
  }
473
  loader.style.display = 'none';
474
  }