fix: add edit actions to detail replacement results
This commit is contained in:
parent
2f6d0498e2
commit
553e5b5373
@ -223,6 +223,7 @@ type DetailResultLocalEditTarget = {
|
||||
cardId: string;
|
||||
imageUrl: string;
|
||||
title: string;
|
||||
resultModeType: "detail_generation" | "detail_replacement";
|
||||
};
|
||||
|
||||
type DetailResultLocalEditRect = {
|
||||
@ -4590,9 +4591,14 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
[activeResultModeType, mergedResultCollections, onResultPreviewUrlsChange]
|
||||
);
|
||||
const handleEnhanceDetailGenerationResult = useCallback(
|
||||
async (params: { cardId: string; imageUrl: string }) => {
|
||||
async (params: {
|
||||
cardId: string;
|
||||
imageUrl: string;
|
||||
resultModeType?: "detail_generation" | "detail_replacement";
|
||||
}) => {
|
||||
const cardId = String(params.cardId || "").trim();
|
||||
const imageUrl = String(params.imageUrl || "").trim();
|
||||
const resultModeType = params.resultModeType || "detail_generation";
|
||||
if (!cardId || !/^https?:\/\//i.test(imageUrl)) {
|
||||
toast.error("详情图地址无效,无法高清处理");
|
||||
return;
|
||||
@ -4612,12 +4618,29 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
throw new Error(result.error || "高清处理失败");
|
||||
}
|
||||
const nextUrl = result.data.url;
|
||||
if (!appendResultUrlToCollection("detail_generation", nextUrl)) {
|
||||
throw new Error("当前项目未接入结果保存能力");
|
||||
if (resultModeType === "detail_replacement") {
|
||||
handleUpdateReplacementResultRecord({
|
||||
modeType: "detail_replacement",
|
||||
cardId,
|
||||
url: nextUrl,
|
||||
text: "已完成高清处理。",
|
||||
status: "completed",
|
||||
});
|
||||
setActiveResultModeType("detail_replacement");
|
||||
setActiveDetailReferenceCardId(cardId);
|
||||
setSelectedResultUrl(nextUrl);
|
||||
} else {
|
||||
if (!appendResultUrlToCollection("detail_generation", nextUrl)) {
|
||||
throw new Error("当前项目未接入结果保存能力");
|
||||
}
|
||||
setActiveResultModeType("detail_generation");
|
||||
setSelectedResultUrl(nextUrl);
|
||||
}
|
||||
setActiveResultModeType("detail_generation");
|
||||
setSelectedResultUrl(nextUrl);
|
||||
toast.success("高清处理完成,已加入 AI详情结果区");
|
||||
toast.success(
|
||||
resultModeType === "detail_replacement"
|
||||
? "高清处理完成,已更新当前套详情结果图"
|
||||
: "高清处理完成,已加入 AI详情结果区"
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("[AgentGenerationWorkspaceDarkV2] 详情图高清失败:", error);
|
||||
toast.error(error instanceof Error ? error.message : "高清处理失败,请稍后重试");
|
||||
@ -4629,7 +4652,11 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
});
|
||||
}
|
||||
},
|
||||
[appendResultUrlToCollection, detailEnhancingCardIds]
|
||||
[
|
||||
appendResultUrlToCollection,
|
||||
detailEnhancingCardIds,
|
||||
handleUpdateReplacementResultRecord,
|
||||
]
|
||||
);
|
||||
const handleSubmitDetailLocalEdit = useCallback(
|
||||
async (params: {
|
||||
@ -4641,6 +4668,7 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
const target = detailLocalEditTarget;
|
||||
const cardId = String(target?.cardId || "").trim();
|
||||
const imageUrl = String(params.imageUrl || "").trim();
|
||||
const resultModeType = target?.resultModeType || "detail_generation";
|
||||
if (!target || !cardId || !/^https?:\/\//i.test(imageUrl)) {
|
||||
toast.error("详情图地址无效,无法局部编辑");
|
||||
return;
|
||||
@ -4694,13 +4722,30 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
if (!/^https?:\/\//i.test(nextUrl)) {
|
||||
throw new Error("局部编辑完成但结果地址无效");
|
||||
}
|
||||
if (!appendResultUrlToCollection("detail_generation", nextUrl)) {
|
||||
throw new Error("当前项目未接入结果保存能力");
|
||||
if (resultModeType === "detail_replacement") {
|
||||
handleUpdateReplacementResultRecord({
|
||||
modeType: "detail_replacement",
|
||||
cardId,
|
||||
url: nextUrl,
|
||||
text: "已完成局部编辑处理。",
|
||||
status: "completed",
|
||||
});
|
||||
setActiveResultModeType("detail_replacement");
|
||||
setActiveDetailReferenceCardId(cardId);
|
||||
setSelectedResultUrl(nextUrl);
|
||||
} else {
|
||||
if (!appendResultUrlToCollection("detail_generation", nextUrl)) {
|
||||
throw new Error("当前项目未接入结果保存能力");
|
||||
}
|
||||
setActiveResultModeType("detail_generation");
|
||||
setSelectedResultUrl(nextUrl);
|
||||
}
|
||||
setActiveResultModeType("detail_generation");
|
||||
setSelectedResultUrl(nextUrl);
|
||||
setDetailLocalEditTarget(null);
|
||||
toast.success("局部编辑完成,已加入 AI详情结果区");
|
||||
toast.success(
|
||||
resultModeType === "detail_replacement"
|
||||
? "局部编辑完成,已更新当前套详情结果图"
|
||||
: "局部编辑完成,已加入 AI详情结果区"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -4717,7 +4762,12 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
setDetailLocalEditSubmittingId(null);
|
||||
}
|
||||
},
|
||||
[appendResultUrlToCollection, detailLocalEditSubmittingId, detailLocalEditTarget]
|
||||
[
|
||||
appendResultUrlToCollection,
|
||||
detailLocalEditSubmittingId,
|
||||
detailLocalEditTarget,
|
||||
handleUpdateReplacementResultRecord,
|
||||
]
|
||||
);
|
||||
const handlePsdDerivedImageCreated = useCallback(
|
||||
(imageUrl: string) => {
|
||||
@ -7452,6 +7502,8 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
const isPending = card.status === "generating" || card.status === "queued";
|
||||
const hasResult = Boolean(card.resultUrl) && !isPending;
|
||||
const isWatermarkRemoving = detailWatermarkRemoveCardIds.has(card.id);
|
||||
const isDetailLocalEditing = detailLocalEditSubmittingId === card.id;
|
||||
const isDetailEnhancing = detailEnhancingCardIds.has(card.id);
|
||||
return (
|
||||
<div
|
||||
key={`${card.id}-result`}
|
||||
@ -7508,7 +7560,52 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
>
|
||||
下载
|
||||
</button>
|
||||
<div className="absolute bottom-3 left-3 flex flex-wrap gap-2">
|
||||
<div className="absolute bottom-3 left-3 flex max-w-[calc(100%-6.5rem)] flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
disabled={isDetailLocalEditing}
|
||||
onClick={() => {
|
||||
setDetailLocalEditTarget({
|
||||
cardId: card.id,
|
||||
imageUrl: card.resultUrl!,
|
||||
title: `${detailReferenceSourceLabel}结果图 ${card.index + 1}`,
|
||||
resultModeType: "detail_replacement",
|
||||
});
|
||||
}}
|
||||
className={cn(
|
||||
IMAGE_OVERLAY_ACTION_CLASS,
|
||||
"inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-45"
|
||||
)}
|
||||
>
|
||||
{isDetailLocalEditing ? (
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
<Wand2 className="h-3.5 w-3.5" />
|
||||
)}
|
||||
<span>{isDetailLocalEditing ? "编辑中" : "局部编辑"}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={isDetailEnhancing}
|
||||
onClick={() =>
|
||||
void handleEnhanceDetailGenerationResult({
|
||||
cardId: card.id,
|
||||
imageUrl: card.resultUrl!,
|
||||
resultModeType: "detail_replacement",
|
||||
})
|
||||
}
|
||||
className={cn(
|
||||
IMAGE_OVERLAY_ACTION_CLASS,
|
||||
"inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-45"
|
||||
)}
|
||||
>
|
||||
{isDetailEnhancing ? (
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
<Sparkles className="h-3.5 w-3.5" />
|
||||
)}
|
||||
<span>{isDetailEnhancing ? "高清中" : "高清"}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
@ -8279,6 +8376,7 @@ export function AgentGenerationWorkspaceDarkV2({
|
||||
cardId: card.id,
|
||||
imageUrl: card.url!,
|
||||
title: `AI详情 ${card.index + 1}`,
|
||||
resultModeType: "detail_generation",
|
||||
});
|
||||
}}
|
||||
className={cn(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user