优化图片标注和加载组件
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2025-12-19 01:20:58 +08:00
parent 4c25d433f8
commit 5b19e6deba
2 changed files with 39 additions and 12 deletions

View File

@ -119,7 +119,7 @@ export const GeminiImageLoading = memo(() => {
{/* 提示文字 */} {/* 提示文字 */}
<span className="text-xs text-muted-foreground"> <span className="text-xs text-muted-foreground">
Gemini 正在创作 2 张图片,请稍候... NanoBananaPro 正在创作 2 张图片,请稍候...
</span> </span>
</div> </div>
</div> </div>

View File

@ -55,13 +55,19 @@ export function ImageAnnotator({ imageUrl, onConfirm, onCancel }: ImageAnnotator
const [textPosition, setTextPosition] = useState<{ x: number; y: number } | null>(null); const [textPosition, setTextPosition] = useState<{ x: number; y: number } | null>(null);
const [scale, setScale] = useState(1); const [scale, setScale] = useState(1);
const [offset, setOffset] = useState({ x: 0, y: 0 }); const [offset, setOffset] = useState({ x: 0, y: 0 });
const [isLoading, setIsLoading] = useState(true);
// 加载图片 // 加载图片
useEffect(() => { useEffect(() => {
setIsLoading(true);
const img = new window.Image(); const img = new window.Image();
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.onload = () => { img.onload = () => {
setImage(img); setImage(img);
setIsLoading(false);
};
img.onerror = () => {
setIsLoading(false);
}; };
img.src = imageUrl; img.src = imageUrl;
}, [imageUrl]); }, [imageUrl]);
@ -428,6 +434,26 @@ export function ImageAnnotator({ imageUrl, onConfirm, onCancel }: ImageAnnotator
{/* 画布区域 */} {/* 画布区域 */}
<div ref={containerRef} className="flex flex-1 items-center justify-center overflow-hidden bg-muted/30 p-4"> <div ref={containerRef} className="flex flex-1 items-center justify-center overflow-hidden bg-muted/30 p-4">
{isLoading ? (
/* 加载动画 */
<div className="flex flex-col items-center justify-center gap-3">
<div className="flex items-center gap-1">
<span
className="h-2 w-2 rounded-full bg-primary animate-bounce"
style={{ animationDelay: "0ms" }}
/>
<span
className="h-2 w-2 rounded-full bg-primary animate-bounce"
style={{ animationDelay: "150ms" }}
/>
<span
className="h-2 w-2 rounded-full bg-primary animate-bounce"
style={{ animationDelay: "300ms" }}
/>
</div>
<span className="text-sm text-muted-foreground">正在加载图片...</span>
</div>
) : (
<canvas <canvas
ref={canvasRef} ref={canvasRef}
className="cursor-crosshair rounded-lg shadow-lg" className="cursor-crosshair rounded-lg shadow-lg"
@ -439,6 +465,7 @@ export function ImageAnnotator({ imageUrl, onConfirm, onCancel }: ImageAnnotator
onTouchMove={handleMove} onTouchMove={handleMove}
onTouchEnd={handleEnd} onTouchEnd={handleEnd}
/> />
)}
</div> </div>
</div> </div>