fix: show fallback state for missing workflow previews
This commit is contained in:
parent
4f1e0bc60a
commit
a15a26ba99
@ -159,17 +159,18 @@ function buildWorkflowOptionPreviewUrl(url?: string | null, sourceUrl?: string |
|
||||
function handleWorkflowOptionPreviewError(
|
||||
event: SyntheticEvent<HTMLImageElement, Event>,
|
||||
originalUrl?: string | null
|
||||
) {
|
||||
): boolean {
|
||||
const fallbackUrl = String(originalUrl || "").trim();
|
||||
if (!fallbackUrl) return;
|
||||
if (!fallbackUrl) return false;
|
||||
|
||||
const image = event.currentTarget;
|
||||
if (image.dataset.workflowPreviewFallbackApplied === "1") {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
image.dataset.workflowPreviewFallbackApplied = "1";
|
||||
image.src = fallbackUrl;
|
||||
return true;
|
||||
}
|
||||
|
||||
function appendWorkflowOptionPreviewUrls(
|
||||
@ -434,7 +435,13 @@ const StepOptionCard = memo(function StepOptionCard({
|
||||
() => buildWorkflowOptionPreviewUrl(option.previewImageUrl, option.previewImageSourceUrl),
|
||||
[option.previewImageSourceUrl, option.previewImageUrl]
|
||||
);
|
||||
const [previewFailed, setPreviewFailed] = useState(false);
|
||||
useEffect(() => {
|
||||
setPreviewFailed(false);
|
||||
}, [previewUrl]);
|
||||
const shouldLoadFast = selected || index < WORKFLOW_OPTION_PREVIEW_EAGER_COUNT;
|
||||
const hasPreview = Boolean(previewUrl && !previewFailed);
|
||||
const isAutoConfiguredOption = /根据风格已配置/.test(option.buttonName);
|
||||
|
||||
return (
|
||||
<button
|
||||
@ -455,7 +462,7 @@ const StepOptionCard = memo(function StepOptionCard({
|
||||
>
|
||||
{/* 背景 */}
|
||||
<div className="absolute inset-0 bg-zinc-900">
|
||||
{previewUrl ? (
|
||||
{hasPreview ? (
|
||||
<>
|
||||
<img
|
||||
src={previewUrl}
|
||||
@ -468,9 +475,15 @@ const StepOptionCard = memo(function StepOptionCard({
|
||||
referrerPolicy="no-referrer"
|
||||
draggable={false}
|
||||
sizes="(max-width: 640px) 50vw, 230px"
|
||||
onError={(event) =>
|
||||
handleWorkflowOptionPreviewError(event, option.previewImageUrl)
|
||||
}
|
||||
onError={(event) => {
|
||||
const fallbackApplied = handleWorkflowOptionPreviewError(
|
||||
event,
|
||||
option.previewImageUrl
|
||||
);
|
||||
if (!fallbackApplied) {
|
||||
setPreviewFailed(true);
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"h-full w-full object-cover transition-transform duration-500",
|
||||
!disabled && "group-hover:scale-[1.04]"
|
||||
@ -479,8 +492,15 @@ const StepOptionCard = memo(function StepOptionCard({
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/80 via-black/40 to-transparent" />
|
||||
</>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center bg-gradient-to-br from-zinc-800 to-zinc-900">
|
||||
<Sparkles className="h-10 w-10 text-white/20" />
|
||||
<div className="flex h-full w-full items-center justify-center bg-[radial-gradient(circle_at_30%_20%,rgba(255,255,255,0.10),transparent_38%),linear-gradient(135deg,#151515,#090909)] px-6">
|
||||
<div className="text-center">
|
||||
<div className="mx-auto flex h-11 w-11 items-center justify-center rounded-full border border-white/10 bg-white/[0.04]">
|
||||
<Sparkles className="h-5 w-5 text-white/35" />
|
||||
</div>
|
||||
<div className="mt-3 text-[11px] font-medium text-white/42">
|
||||
{isAutoConfiguredOption ? "自动配置" : "暂无预览图"}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user