中文版 AI 姿势参考图库 · 1439 组 / 2878 张图片 / 完整汉化 · 零依赖静态画廊
fix(images): show load failures and allow explicit retries
H-Bolef73bb0e543d3
diff --git a/src/components/common/ZoomViewport.tsx b/src/components/common/ZoomViewport.tsxindex 9dabc7d..48eb9d6 100644--- a/src/components/common/ZoomViewport.tsx+++ b/src/components/common/ZoomViewport.tsx@@ -23,6 +23,7 @@ function ZoomSurface({ imageUrl, alt = '图片预览', children, contentWidth =const [size, setSize] = useState({ width: 1, height: 1 })const [natural, setNatural] = useState({ width: contentWidth, height: contentHeight })const [view, setView] = useState({ zoom: 1, x: 0, y: 0 })+ const [imageFailed, setImageFailed] = useState(false)const current = useRef(view)const pointers = useRef(new Map<number, { x: number; y: number }>())const previous = useRef<{ x: number; y: number; distance: number } | null>(null)@@ -80,6 +81,7 @@ function ZoomSurface({ imageUrl, alt = '图片预览', children, contentWidth =className="relative min-h-0 flex-1 overflow-hidden rounded-lg bg-muted/60 outline-offset-2 focus-visible:outline-2 focus-visible:outline-ring"style={{ touchAction: 'none', cursor: view.zoom > 1 ? 'grab' : 'default' }}onKeyDown={(e) => {+ if (e.target !== e.currentTarget) returnif (e.key === '+' || e.key === '=') { e.preventDefault(); zoomAt(current.current.zoom * 1.25) }if (e.key === '-') { e.preventDefault(); zoomAt(current.current.zoom / 1.25) }if (e.key === '0' || e.key === 'Home') { e.preventDefault(); reset() }@@ -106,8 +108,12 @@ function ZoomSurface({ imageUrl, alt = '图片预览', children, contentWidth =onPointerCancel={(e) => { pointers.current.delete(e.pointerId); previous.current = gesture() }}onLostPointerCapture={(e) => { pointers.current.delete(e.pointerId); previous.current = gesture() }}><div className="pointer-events-none absolute top-1/2 left-1/2 origin-center select-none" style={{ width: natural.width, height: natural.height, transform: `translate(-50%, -50%) translate(${view.x}px, ${view.y}px) scale(${fit * view.zoom})` }}>- {children ?? (imageUrl && <img src={imageUrl} alt={alt} draggable={false} className="h-full w-full object-contain" onLoad={(e) => { setNatural({ width: e.currentTarget.naturalWidth, height: e.currentTarget.naturalHeight }); reset() }} />)}+ {children ?? (imageUrl && !imageFailed && <img src={imageUrl} alt={alt} draggable={false} className="h-full w-full object-contain" onError={() => setImageFailed(true)} onLoad={(e) => { setNatural({ width: e.currentTarget.naturalWidth, height: e.currentTarget.naturalHeight }); reset() }} />)}</div>+ {!children && imageFailed && <div className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-background/90 p-4 text-center" onPointerDown={(e) => e.stopPropagation()}>+ <p role="status" className="text-sm text-muted-foreground">图片加载失败,请检查网络后重试。</p>+ <Button type="button" variant="outline" className="min-h-11" onClick={() => { setImageFailed(false); viewport.current?.focus() }}>重新加载图片</Button>+ </div>}</div><p className="shrink-0 text-center text-xs text-muted-foreground">滚轮或双指缩放 · 放大后拖动 · 100% 为适应窗口</p></div>diff --git a/src/routes/costumes.tsx b/src/routes/costumes.tsxindex 83b5d3e..1685163 100644--- a/src/routes/costumes.tsx+++ b/src/routes/costumes.tsx@@ -12,7 +12,7 @@ import {RotateCcwIcon,SearchIcon,} from 'lucide-react'-import { useEffect, useMemo, useState } from 'react'+import { useEffect, useMemo, useRef, useState } from 'react'import { toast } from 'sonner'import { costumesQuery, isNsfwCostume, isNsfwCostumeCategory } from '@/api/gallery'import { EmptyState } from '@/components/common/EmptyState'@@ -28,6 +28,7 @@ import { referenceImageUrl } from '@/lib/recipeImages'import { COSTUME_SOURCES, costumeSourceId } from '@/lib/costumeSources'import { CHARADB_NOTICE_URL } from '@/lib/charadb'import { useStudio } from '@/store/studioStore'+import type { CostumeItem } from '@/types/gallery'export const Route = createFileRoute('/costumes')({staticData: { title: '服装穿搭库' },@@ -36,6 +37,31 @@ export const Route = createFileRoute('/costumes')({component: CostumesPage,})+function CostumeThumbnail({ item, onOpen, picked, onToggle }: { item: CostumeItem; onOpen: () => void; picked: boolean; onToggle: () => void }) {+ const [failed, setFailed] = useState(false)+ const openButton = useRef<HTMLButtonElement>(null)+ return <div className="relative aspect-2/3 w-full shrink-0 overflow-hidden rounded-2xl bg-background">+ <button ref={openButton} type="button" aria-label={`查看 ${item.id} 大图`} onClick={onOpen} className="relative block h-full w-full cursor-zoom-in focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring">+ {!failed && <img src={referenceImageUrl(item.缩略图)} alt={item.服装名称} loading="lazy" onError={() => setFailed(true)} className="h-full w-full object-contain transition duration-300 group-hover:scale-105" />}+ <span className="absolute inset-x-2 top-2 flex items-center justify-between gap-1">+ <span className="rounded-md bg-black/70 px-1.5 py-0.5 font-mono text-[10px] font-bold text-white">{item.id}</span>+ <span className="rounded-md bg-white/90 px-1.5 py-0.5 text-[10px] font-semibold text-zinc-900">{item.分类}</span>+ </span>+ </button>+ <button type="button" onClick={onToggle} className={cn(+ 'absolute bottom-2 left-2 flex items-center gap-1 rounded-lg px-2.5 py-1 text-[11px] font-semibold text-white shadow transition',+ picked ? 'bg-emerald-600' : 'bg-black/75 hover:bg-primary'+ )}>+ {picked ? <CheckIcon className="size-3" /> : <PlusIcon className="size-3" />}+ {picked ? '已选' : '加入配方'}+ </button>+ {failed && <div className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background/90 p-2 text-center">+ <p role="status" className="text-xs text-muted-foreground">图片加载失败</p>+ <Button type="button" variant="outline" className="pointer-events-auto min-h-11" aria-label={`重新加载 ${item.id} 缩略图`} onClick={() => { setFailed(false); openButton.current?.focus() }}>重新加载</Button>+ </div>}+ </div>+}+function CostumesPage() {const { data: costumes } = useSuspenseQuery(costumesQuery)const { recipe, toggleCostume, safeMode, requestUnlockNsfw } = useStudio()@@ -232,39 +258,7 @@ function CostumesPage() {key={item.id}className="group flex flex-col overflow-hidden rounded-[20px] bg-muted p-2 transition hover:-translate-y-0.5 hover:shadow-md">- <div- onClick={() => setViewerIndex(idx)}- className="relative aspect-2/3 cursor-zoom-in overflow-hidden rounded-2xl bg-background"- >- <img- src={referenceImageUrl(item.缩略图)}- alt={item.服装名称}- loading="lazy"- className="h-full w-full object-contain transition duration-300 group-hover:scale-105"- />- <div className="absolute inset-x-2 top-2 flex items-center justify-between gap-1">- <span className="rounded-md bg-black/70 px-1.5 py-0.5 font-mono text-[10px] font-bold text-white">- {item.id}- </span>- <span className="rounded-md bg-white/90 px-1.5 py-0.5 text-[10px] font-semibold text-zinc-900">- {item.分类}- </span>- </div>- <button- type="button"- onClick={(e) => {- e.stopPropagation()- toggleCostume(item)- }}- className={cn(- 'absolute bottom-2 left-2 flex items-center gap-1 rounded-lg px-2.5 py-1 text-[11px] font-semibold text-white shadow transition',- picked ? 'bg-emerald-600' : 'bg-black/75 hover:bg-primary'- )}- >- {picked ? <CheckIcon className="size-3" /> : <PlusIcon className="size-3" />}- {picked ? '已选' : '加入配方'}- </button>- </div>+ <CostumeThumbnail key={item.缩略图} item={item} onOpen={() => setViewerIndex(idx)} picked={picked} onToggle={() => toggleCostume(item)} /><div className="flex flex-1 flex-col justify-between px-1.5 pt-2.5 pb-1"><div>