wapadil Claude commited on
Commit
fb4225a
·
1 Parent(s): 1603bfe

[UX] 核心体验优化 - 图像尺寸修复 + 空状态增强 + 移动端操作栏

Browse files

修复问题:
- 上传图像不再自动修改用户设置的尺寸参数
- 移除所有 updateCustomSizeFromLastImage() 的自动调用

空状态设计增强:
- 添加浮动动画🎨图标吸引注意力
- 3个快速示例按钮(换装/风格转换/表情编辑)
- 功能提示卡片(拖拽/快捷键/图像限制)
- 渐变背景+虚线边框增强视觉层级

历史记录底部操作栏:
- 移除悬停依赖,底部固定显示操作按钮
- 移动端始终可见(触摸设备优化)
- 40x40px大尺寸按钮(易点击)
- 毛玻璃效果+渐变背景
- 新增下载功能按钮

细节优化:
- 当前生成和历史记录统一使用新操作栏
- 点击图像可放大查看
- 所有按钮添加 event.stopPropagation() 防止误触

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (3) hide show
  1. static/script.js +63 -26
  2. static/style.css +172 -27
  3. templates/index.html +23 -3
static/script.js CHANGED
@@ -589,8 +589,7 @@ async function handleFileUpload(event) {
589
  height: this.height
590
  });
591
  addImagePreview(dataUrl, uploadedImages.length - 1);
592
- updateCustomSizeFromLastImage();
593
-
594
  if (processedCount + errorCount === files.length) {
595
  if (errorCount === 0) {
596
  showStatus(`成功添加 ${processedCount} 张图像 (已使用 ${uploadedImages.length}/10 个位置)`, 'success');
@@ -599,12 +598,11 @@ async function handleFileUpload(event) {
599
  }
600
  }
601
  };
602
-
603
  img.onerror = () => {
604
  console.error('Error loading image dimensions for:', file.name);
605
  imageDimensions.push({ width: 1280, height: 1280 });
606
  addImagePreview(dataUrl, uploadedImages.length - 1);
607
- updateCustomSizeFromLastImage();
608
  };
609
 
610
  img.src = dataUrl;
@@ -652,7 +650,40 @@ function removeImage(index) {
652
  uploadedImages.splice(index, 1);
653
  imageDimensions.splice(index, 1);
654
  renderImagePreviews();
655
- updateCustomSizeFromLastImage();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  }
657
 
658
  // Update custom size based on last image
@@ -978,7 +1009,6 @@ async function getImageDimensionsFromUrl(url) {
978
  width: this.width,
979
  height: this.height
980
  });
981
- updateCustomSizeFromLastImage();
982
  resolve();
983
  };
984
  img.onerror = function() {
@@ -1320,14 +1350,23 @@ function displayCurrentResults(response) {
1320
  response.images.forEach((image, index) => {
1321
  const imgSrc = image.url || image.file_data || '';
1322
  const imageId = `current-img-${Date.now()}-${index}`;
1323
-
1324
  const item = document.createElement('div');
1325
  item.className = 'generation-item';
1326
  item.innerHTML = `
1327
- <img id="${imageId}" src="${imgSrc}" alt="Result ${index + 1}" loading="lazy" decoding="async">
1328
- <button class="use-as-input-btn" onclick="useAsInput('${imageId}', '${imgSrc}')" title="作为输入">
1329
- 作为输入
1330
- </button>
 
 
 
 
 
 
 
 
 
1331
  `;
1332
  currentResults.appendChild(item);
1333
  });
@@ -1367,17 +1406,19 @@ function displayHistory() {
1367
  item.innerHTML = `
1368
  <img id="${imageId}" src="${imgSrc}" alt="Generation" loading="lazy" decoding="async"
1369
  onclick="openImageModal('${imageId}', '${imgSrc}', '${generation.prompt.replace(/'/g, "\\'")}', '${new Date(generation.timestamp).toLocaleString()}')">
1370
- <div class="generation-actions">
1371
- <button class="use-as-input-btn" onclick="useAsInput('${imageId}', '${imgSrc}')" title="作为输入">
1372
- 作为输入
1373
- </button>
1374
- <button class="copy-prompt-btn" onclick="copyPromptFromHistory('${generation.prompt.replace(/'/g, "\\'")}', event)" title="复制提示词">
1375
- 📋 复制提示词
1376
- </button>
1377
- </div>
1378
- <div class="generation-meta">
1379
- <span class="timestamp">${new Date(generation.timestamp).toLocaleString()}</span>
1380
- <span class="prompt-preview">${generation.prompt}</span>
 
 
1381
  </div>
1382
  `;
1383
  historyGrid.appendChild(item);
@@ -1632,8 +1673,6 @@ async function useAsInput(imageId, imageSrc) {
1632
  width: imgElement.naturalWidth || imgElement.width,
1633
  height: imgElement.naturalHeight || imgElement.height
1634
  });
1635
-
1636
- updateCustomSizeFromLastImage();
1637
  } else {
1638
  const img = new Image();
1639
  img.onload = function() {
@@ -1641,11 +1680,9 @@ async function useAsInput(imageId, imageSrc) {
1641
  width: this.width,
1642
  height: this.height
1643
  });
1644
- updateCustomSizeFromLastImage();
1645
  };
1646
  img.onerror = function() {
1647
  imageDimensions.push({ width: 1280, height: 1280 });
1648
- updateCustomSizeFromLastImage();
1649
  };
1650
  img.src = imageSrc;
1651
  }
 
589
  height: this.height
590
  });
591
  addImagePreview(dataUrl, uploadedImages.length - 1);
592
+
 
593
  if (processedCount + errorCount === files.length) {
594
  if (errorCount === 0) {
595
  showStatus(`成功添加 ${processedCount} 张图像 (已使用 ${uploadedImages.length}/10 个位置)`, 'success');
 
598
  }
599
  }
600
  };
601
+
602
  img.onerror = () => {
603
  console.error('Error loading image dimensions for:', file.name);
604
  imageDimensions.push({ width: 1280, height: 1280 });
605
  addImagePreview(dataUrl, uploadedImages.length - 1);
 
606
  };
607
 
608
  img.src = dataUrl;
 
650
  uploadedImages.splice(index, 1);
651
  imageDimensions.splice(index, 1);
652
  renderImagePreviews();
653
+ }
654
+
655
+ // Fill example prompt
656
+ function fillExample(exampleText) {
657
+ const promptTextarea = document.getElementById('prompt');
658
+ const drawerPromptTextarea = document.getElementById('drawerPrompt');
659
+
660
+ if (promptTextarea) {
661
+ promptTextarea.value = exampleText;
662
+ promptTextarea.focus();
663
+ }
664
+ if (drawerPromptTextarea) {
665
+ drawerPromptTextarea.value = exampleText;
666
+ }
667
+
668
+ // Switch to edit mode if needed
669
+ const currentModel = modelSelect.value;
670
+ if (currentModel === 'fal-ai/bytedance/seedream/v4/text-to-image') {
671
+ modelSelect.value = 'fal-ai/bytedance/seedream/v4/edit';
672
+ handleModelChange();
673
+ }
674
+
675
+ showToast('示例提示词已填入,上传图像后即可生成', 'success', 3000);
676
+ }
677
+
678
+ // Download image
679
+ function downloadImage(imageSrc, imageId) {
680
+ const link = document.createElement('a');
681
+ link.href = imageSrc;
682
+ link.download = `seedream-${imageId}.png`;
683
+ document.body.appendChild(link);
684
+ link.click();
685
+ document.body.removeChild(link);
686
+ showToast('图像下载中...', 'success', 2000);
687
  }
688
 
689
  // Update custom size based on last image
 
1009
  width: this.width,
1010
  height: this.height
1011
  });
 
1012
  resolve();
1013
  };
1014
  img.onerror = function() {
 
1350
  response.images.forEach((image, index) => {
1351
  const imgSrc = image.url || image.file_data || '';
1352
  const imageId = `current-img-${Date.now()}-${index}`;
1353
+
1354
  const item = document.createElement('div');
1355
  item.className = 'generation-item';
1356
  item.innerHTML = `
1357
+ <img id="${imageId}" src="${imgSrc}" alt="Result ${index + 1}" loading="lazy" decoding="async"
1358
+ onclick="openImageModal('${imageId}', '${imgSrc}', '当前生成', '${new Date().toLocaleString()}')">
1359
+ <div class="generation-footer">
1360
+ <div class="generation-timestamp">刚刚生成</div>
1361
+ <div class="generation-actions-bar">
1362
+ <button class="action-icon" onclick="useAsInput('${imageId}', '${imgSrc}'); event.stopPropagation();" title="作为输入">
1363
+
1364
+ </button>
1365
+ <button class="action-icon" onclick="downloadImage('${imgSrc}', 'current-${index}'); event.stopPropagation();" title="下载">
1366
+ ⬇️
1367
+ </button>
1368
+ </div>
1369
+ </div>
1370
  `;
1371
  currentResults.appendChild(item);
1372
  });
 
1406
  item.innerHTML = `
1407
  <img id="${imageId}" src="${imgSrc}" alt="Generation" loading="lazy" decoding="async"
1408
  onclick="openImageModal('${imageId}', '${imgSrc}', '${generation.prompt.replace(/'/g, "\\'")}', '${new Date(generation.timestamp).toLocaleString()}')">
1409
+ <div class="generation-footer">
1410
+ <div class="generation-timestamp">${new Date(generation.timestamp).toLocaleString()}</div>
1411
+ <div class="generation-actions-bar">
1412
+ <button class="action-icon" onclick="useAsInput('${imageId}', '${imgSrc}'); event.stopPropagation();" title="作为输入">
1413
+
1414
+ </button>
1415
+ <button class="action-icon" onclick="copyPromptFromHistory('${generation.prompt.replace(/'/g, "\\'")}', event)" title="复制提示词">
1416
+ 📋
1417
+ </button>
1418
+ <button class="action-icon" onclick="downloadImage('${imgSrc}', '${generation.id}-${imgIndex}'); event.stopPropagation();" title="下载">
1419
+ ⬇️
1420
+ </button>
1421
+ </div>
1422
  </div>
1423
  `;
1424
  historyGrid.appendChild(item);
 
1673
  width: imgElement.naturalWidth || imgElement.width,
1674
  height: imgElement.naturalHeight || imgElement.height
1675
  });
 
 
1676
  } else {
1677
  const img = new Image();
1678
  img.onload = function() {
 
1680
  width: this.width,
1681
  height: this.height
1682
  });
 
1683
  };
1684
  img.onerror = function() {
1685
  imageDimensions.push({ width: 1280, height: 1280 });
 
1686
  };
1687
  img.src = imageSrc;
1688
  }
static/style.css CHANGED
@@ -441,49 +441,74 @@ label, .meta {
441
  line-height: 1.3;
442
  }
443
 
444
- /* Generation action buttons container */
445
- .generation-actions {
446
  position: absolute;
447
- top: 8px;
448
- right: 8px;
 
 
 
 
 
449
  display: flex;
450
  flex-direction: column;
451
- gap: 4px;
452
  opacity: 0;
453
- transition: all 0.3s ease;
454
  }
455
 
456
- .generation-item:hover .generation-actions {
457
  opacity: 1;
458
  }
459
 
460
- /* Shared button styles */
461
- .use-as-input-btn, .copy-prompt-btn {
462
- background: linear-gradient(135deg, var(--brand-secondary) 0%, var(--brand-primary) 100%);
463
- color: white;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  border: none;
465
- padding: 6px 10px;
466
- border-radius: 4px;
467
- font-size: 0.75rem;
468
- font-weight: 600;
469
  cursor: pointer;
 
 
470
  transition: all 0.2s ease;
471
- white-space: nowrap;
472
- box-shadow: 0 2px 8px rgba(0,0,0,0.2);
473
- }
474
-
475
- /* Copy prompt button specific styling */
476
- .copy-prompt-btn {
477
- background: linear-gradient(135deg, #34C759 0%, #30D158 100%);
478
  }
479
 
480
- .use-as-input-btn:hover, .copy-prompt-btn:hover {
481
- transform: scale(1.05);
482
- box-shadow: 0 4px 12px rgba(0,0,0,0.3);
483
  }
484
 
485
- .copy-prompt-btn:hover {
486
- background: linear-gradient(135deg, #30D158 0%, #32D74B 100%);
487
  }
488
 
489
  /* Textarea size controls */
@@ -806,6 +831,126 @@ label, .meta {
806
  line-height: 1.4;
807
  }
808
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809
  /* Generation Info */
810
  .generation-info {
811
  background: var(--brand-bg);
 
441
  line-height: 1.3;
442
  }
443
 
444
+ /* Generation footer with actions bar */
445
+ .generation-footer {
446
  position: absolute;
447
+ bottom: 0;
448
+ left: 0;
449
+ right: 0;
450
+ background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.6) 70%, transparent 100%);
451
+ padding: var(--spacing-3) var(--spacing-2);
452
+ backdrop-filter: blur(8px);
453
+ -webkit-backdrop-filter: blur(8px);
454
  display: flex;
455
  flex-direction: column;
456
+ gap: var(--spacing-2);
457
  opacity: 0;
458
+ transition: opacity 0.2s ease;
459
  }
460
 
461
+ .generation-item:hover .generation-footer {
462
  opacity: 1;
463
  }
464
 
465
+ /* Always show on touch devices */
466
+ @media (hover: none) and (pointer: coarse) {
467
+ .generation-footer {
468
+ opacity: 1;
469
+ background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.5) 70%, transparent 100%);
470
+ }
471
+ }
472
+
473
+ .generation-timestamp {
474
+ font-size: 11px;
475
+ color: rgba(255, 255, 255, 0.9);
476
+ font-weight: 500;
477
+ text-align: center;
478
+ }
479
+
480
+ .generation-actions-bar {
481
+ display: flex;
482
+ justify-content: center;
483
+ gap: var(--spacing-2);
484
+ }
485
+
486
+ .action-icon {
487
+ width: 40px;
488
+ height: 40px;
489
+ min-width: 40px;
490
+ min-height: 40px;
491
  border: none;
492
+ background: rgba(255, 255, 255, 0.2);
493
+ backdrop-filter: blur(8px);
494
+ -webkit-backdrop-filter: blur(8px);
495
+ border-radius: var(--radius-md);
496
  cursor: pointer;
497
+ font-size: 18px;
498
+ color: white;
499
  transition: all 0.2s ease;
500
+ display: flex;
501
+ align-items: center;
502
+ justify-content: center;
 
 
 
 
503
  }
504
 
505
+ .action-icon:hover {
506
+ background: rgba(255, 255, 255, 0.35);
507
+ transform: scale(1.1);
508
  }
509
 
510
+ .action-icon:active {
511
+ transform: scale(0.95);
512
  }
513
 
514
  /* Textarea size controls */
 
831
  line-height: 1.4;
832
  }
833
 
834
+ /* Enhanced Empty State */
835
+ .empty-state-enhanced {
836
+ text-align: center;
837
+ padding: var(--spacing-12) var(--spacing-8);
838
+ background: linear-gradient(135deg, #faf5ff 0%, #ffffff 100%);
839
+ border: 2px dashed var(--border-light);
840
+ border-radius: var(--radius-xl);
841
+ max-width: 700px;
842
+ margin: 0 auto;
843
+ }
844
+
845
+ .empty-icon {
846
+ font-size: 80px;
847
+ margin-bottom: var(--spacing-6);
848
+ animation: float 3s ease-in-out infinite;
849
+ display: inline-block;
850
+ }
851
+
852
+ @keyframes float {
853
+ 0%, 100% { transform: translateY(0); }
854
+ 50% { transform: translateY(-10px); }
855
+ }
856
+
857
+ .empty-state-enhanced h3 {
858
+ font-size: 24px;
859
+ font-weight: 600;
860
+ color: var(--text-primary);
861
+ margin-bottom: var(--spacing-3);
862
+ }
863
+
864
+ .empty-state-enhanced > p {
865
+ font-size: 16px;
866
+ color: var(--text-secondary);
867
+ margin-bottom: var(--spacing-8);
868
+ line-height: 1.6;
869
+ }
870
+
871
+ .quick-examples {
872
+ margin-bottom: var(--spacing-8);
873
+ }
874
+
875
+ .quick-examples h4 {
876
+ font-size: 16px;
877
+ font-weight: 600;
878
+ color: var(--text-primary);
879
+ margin-bottom: var(--spacing-4);
880
+ }
881
+
882
+ .example-prompt {
883
+ display: inline-block;
884
+ margin: var(--spacing-2);
885
+ padding: var(--spacing-3) var(--spacing-5);
886
+ background: white;
887
+ border: 2px solid var(--brand-primary);
888
+ border-radius: var(--radius-lg);
889
+ cursor: pointer;
890
+ font-size: 15px;
891
+ font-weight: 500;
892
+ color: var(--brand-primary);
893
+ transition: all 0.2s ease;
894
+ min-height: 44px;
895
+ min-width: 44px;
896
+ }
897
+
898
+ .example-prompt:hover {
899
+ background: var(--brand-primary);
900
+ color: white;
901
+ transform: translateY(-2px);
902
+ box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
903
+ }
904
+
905
+ .example-prompt:active {
906
+ transform: translateY(0);
907
+ }
908
+
909
+ .feature-hints {
910
+ display: flex;
911
+ gap: var(--spacing-4);
912
+ justify-content: center;
913
+ flex-wrap: wrap;
914
+ }
915
+
916
+ .feature-hints span {
917
+ font-size: 14px;
918
+ color: var(--text-secondary);
919
+ padding: var(--spacing-2) var(--spacing-4);
920
+ background: rgba(124, 58, 237, 0.08);
921
+ border-radius: var(--radius-md);
922
+ border: 1px solid rgba(124, 58, 237, 0.15);
923
+ }
924
+
925
+ @media (max-width: 768px) {
926
+ .empty-state-enhanced {
927
+ padding: var(--spacing-8) var(--spacing-4);
928
+ }
929
+
930
+ .empty-icon {
931
+ font-size: 60px;
932
+ }
933
+
934
+ .empty-state-enhanced h3 {
935
+ font-size: 20px;
936
+ }
937
+
938
+ .example-prompt {
939
+ display: block;
940
+ width: 100%;
941
+ margin: var(--spacing-2) 0;
942
+ }
943
+
944
+ .feature-hints {
945
+ flex-direction: column;
946
+ gap: var(--spacing-2);
947
+ }
948
+
949
+ .feature-hints span {
950
+ width: 100%;
951
+ }
952
+ }
953
+
954
  /* Generation Info */
955
  .generation-info {
956
  background: var(--brand-bg);
templates/index.html CHANGED
@@ -358,9 +358,29 @@
358
 
359
  <div id="currentTab" class="tab-content active">
360
  <div id="currentResults" class="results-grid">
361
- <div class="empty-state" id="currentEmptyState">
362
- <p>暂无当前生成</p>
363
- <small>生成图像后在此查看结果</small>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  </div>
365
  </div>
366
  <div id="currentInfo" class="generation-info"></div>
 
358
 
359
  <div id="currentTab" class="tab-content active">
360
  <div id="currentResults" class="results-grid">
361
+ <div class="empty-state-enhanced" id="currentEmptyState">
362
+ <div class="empty-icon">🎨</div>
363
+ <h3>开始您的创作之旅</h3>
364
+ <p>上传参考图像或输入文字描述,让AI为您生成惊艳的图像</p>
365
+
366
+ <div class="quick-examples">
367
+ <h4>快速尝试:</h4>
368
+ <button class="example-prompt" onclick="fillExample('给模特穿上时尚的连衣裙和高跟鞋,背景是城市街道')">
369
+ 👗 给人物换装
370
+ </button>
371
+ <button class="example-prompt" onclick="fillExample('将这张照片转换成油画风格,保持人物特征')">
372
+ 🎨 风格转换
373
+ </button>
374
+ <button class="example-prompt" onclick="fillExample('让照片中的人物微笑,表情自然')">
375
+ 😊 表情编辑
376
+ </button>
377
+ </div>
378
+
379
+ <div class="feature-hints">
380
+ <span>💡 支持拖拽上传</span>
381
+ <span>⌨️ Cmd+Enter 快速生成</span>
382
+ <span>🖼️ 最多10张参考图</span>
383
+ </div>
384
  </div>
385
  </div>
386
  <div id="currentInfo" class="generation-info"></div>