diff --git a/furniture-3d-system/src/app/api/diy/ai-renders/[id]/color-review/route.ts b/furniture-3d-system/src/app/api/diy/ai-renders/[id]/color-review/route.ts new file mode 100644 index 00000000..4ae93ce1 --- /dev/null +++ b/furniture-3d-system/src/app/api/diy/ai-renders/[id]/color-review/route.ts @@ -0,0 +1,9 @@ +import { NextRequest } from 'next/server' +import { handleRequest, jsonSuccess } from '@/server/core/response' +import { getDiySolidDoorColorReview } from '@/server/services/diy-solid-door-color-review.service' + +export async function GET(request: NextRequest, context: { params: Promise<{ id: string }> }) { + return handleRequest(request, async ctx => jsonSuccess(await getDiySolidDoorColorReview( + (await context.params).id, request.nextUrl.searchParams.get('storageKey') || '', ctx.user, + ), 200, ctx.requestId), { requireAuth: true }) +} diff --git a/furniture-3d-system/src/app/api/diy/ai-renders/color-standards/route.ts b/furniture-3d-system/src/app/api/diy/ai-renders/color-standards/route.ts new file mode 100644 index 00000000..1a2cb738 --- /dev/null +++ b/furniture-3d-system/src/app/api/diy/ai-renders/color-standards/route.ts @@ -0,0 +1,10 @@ +import { NextRequest } from 'next/server' +import { handleRequest, jsonSuccess } from '@/server/core/response' +import { getDiySolidDoorStandards } from '@/server/services/diy-solid-door-colors.service' + +export async function GET(request: NextRequest) { + return handleRequest(request, async ctx => jsonSuccess(await getDiySolidDoorStandards({ + catalogHash: request.nextUrl.searchParams.get('catalogHash'), + codes: request.nextUrl.searchParams.getAll('code'), + }, ctx.user), 200, ctx.requestId), { requireAuth: true }) +} diff --git a/furniture-3d-system/src/app/diy/components/DiyAiPromptForm.tsx b/furniture-3d-system/src/app/diy/components/DiyAiPromptForm.tsx index 6a1198ce..0024140c 100644 --- a/furniture-3d-system/src/app/diy/components/DiyAiPromptForm.tsx +++ b/furniture-3d-system/src/app/diy/components/DiyAiPromptForm.tsx @@ -5,6 +5,7 @@ import Button from '@/components/ui/Button' import { RenderInspectorPromptTagPicker } from '@/app/ai-render-workbench/RenderInspectorPromptTagPicker' import type { DiyAiRenderInput } from '@/lib/diy/ai-render' import type { DiyAiRenderController } from '../hooks/useDiyAiRender' +import DiySolidDoorColors from './DiySolidDoorColors' const field = 'w-full rounded-[4px] border border-black/[0.04] bg-white px-2.5 py-1.5 text-[11px] leading-[18px] text-[#2d3335] outline-none focus:border-[#47646b]/30 disabled:opacity-50' const box = 'rounded-[6px] border border-black/[0.04] bg-white' @@ -16,6 +17,7 @@ export default function DiyAiPromptForm({ ai, hasItems }: { ai:DiyAiRenderContro onClick={() => ai.setMode(mode)} className={`h-8 rounded-[5px] text-[11px] font-semibold transition ${ai.mode===mode?'bg-white text-[#2d3335] shadow-sm ring-1 ring-black/[0.04]':'text-[#5a6062]/60 hover:bg-white/70'}`}> {mode==='scene'?'效果图':'白底图'})} +
当前视角参考图
diff --git a/furniture-3d-system/src/app/diy/components/DiyAiResultCard.tsx b/furniture-3d-system/src/app/diy/components/DiyAiResultCard.tsx index 901a8644..73ed2dca 100644 --- a/furniture-3d-system/src/app/diy/components/DiyAiResultCard.tsx +++ b/furniture-3d-system/src/app/diy/components/DiyAiResultCard.tsx @@ -5,6 +5,7 @@ import Button from '@/components/ui/Button' import type { DiyAiRenderDTO } from '@/lib/diy/ai-render' import type { DiyImageSelection } from '@/lib/diy/image-tools' import type { DiyAiRenderController } from '../hooks/useDiyAiRender' +import DiySolidDoorColorReview from './DiySolidDoorColorReview' export const diyRenderLabel = (record: DiyAiRenderDTO) => record.operation === 'local-preview' ? '本地截图' : record.operation === 'text-replace' ? '文字替换' : record.operation === 'layout-replace' ? '排版图' : record.mode === 'scene' ? '效果图' : '白底图' @@ -38,6 +39,7 @@ export default function DiyAiResultCard({ record, ai, onPreview, onEdit, onLayou {`${record.name} {image.width} × {image.height} +
{canLayout && } diff --git a/furniture-3d-system/src/app/diy/components/DiySolidDoorColorReview.tsx b/furniture-3d-system/src/app/diy/components/DiySolidDoorColorReview.tsx new file mode 100644 index 00000000..fb150f52 --- /dev/null +++ b/furniture-3d-system/src/app/diy/components/DiySolidDoorColorReview.tsx @@ -0,0 +1,42 @@ +'use client' + +import { useEffect, useRef, useState } from 'react' +import type { DiyAiRenderDTO, DiyAiRenderImage } from '@/lib/diy/ai-render' +import type { SolidDoorColorReview } from '@/lib/diy/solid-door-colors' +import { readDiySolidDoorColorReview } from '../lib/solid-door-colors-api' + +export default function DiySolidDoorColorReview({ record, image }: { record: DiyAiRenderDTO; image: DiyAiRenderImage }) { + const root = useRef(null), [visible, setVisible] = useState(false), [revision, setRevision] = useState(0) + const [state, setState] = useState<{ key: string; review?: SolidDoorColorReview; error?: string } | null>(null) + const requestKey = `${record.id}:${image.storageKey}:${revision}` + const review = state?.key === requestKey ? state.review : undefined, error = state?.key === requestKey ? state.error : undefined + const applicable = Boolean(record.solidDoorColors?.length) && !record.operation + useEffect(() => { + if (!applicable || !root.current) return + const observer = new IntersectionObserver(entries => { if (entries.some(entry => entry.isIntersecting)) { setVisible(true); observer.disconnect() } }) + observer.observe(root.current); return () => observer.disconnect() + }, [applicable]) + useEffect(() => { + if (!applicable || !visible) return + let live = true + void readDiySolidDoorColorReview(record.id, image.storageKey).then(result => { if (live) setState({ key: requestKey, review: result }) }) + .catch(err => { if (live) setState({ key: requestKey, error: err instanceof Error ? err.message : '核色失败' }) }) + return () => { live = false } + }, [record.id, image.storageKey, applicable, visible, requestKey]) + if (!applicable) return null + return
+ {error ? + : !review ? 正在辅助核色… :
+ + {review.status === 'suspect' ? '疑似偏色 · 请核对' : review.status === 'manual' ? '请人工核色' : '未检出明显偏色 · 待确认'} + +
+ {review.colors.map(color =>
+ + {color.name}:{color.reason} +
)} + {record.referenceImageUrl && 查看原始参考图} +
+
} +
+} diff --git a/furniture-3d-system/src/app/diy/components/DiySolidDoorColors.tsx b/furniture-3d-system/src/app/diy/components/DiySolidDoorColors.tsx new file mode 100644 index 00000000..59240f62 --- /dev/null +++ b/furniture-3d-system/src/app/diy/components/DiySolidDoorColors.tsx @@ -0,0 +1,23 @@ +'use client' + +import type { DiySolidDoorColorsController } from '../hooks/useDiySolidDoorColors' + +export default function DiySolidDoorColors({ colors, disabled = false }: { colors: DiySolidDoorColorsController; disabled?: boolean }) { + if (!colors.hasColors) return null + return
+ + {colors.enabled && <> + {colors.loading &&

正在读取素材标准色…

} + {colors.error &&

{colors.error}

} +
+ {colors.standards.map(color => + {color.name} + )} +
+ {!colors.error && !colors.loading &&

同批共用素材标准色,保留自然明暗;成图仍需核色。

} + } +
+} diff --git a/furniture-3d-system/src/app/diy/components/batch/DiyBatchRecord.tsx b/furniture-3d-system/src/app/diy/components/batch/DiyBatchRecord.tsx index ceee48c9..889b9d42 100644 --- a/furniture-3d-system/src/app/diy/components/batch/DiyBatchRecord.tsx +++ b/furniture-3d-system/src/app/diy/components/batch/DiyBatchRecord.tsx @@ -8,6 +8,7 @@ import type { DiyAiRenderImage } from '@/lib/diy/ai-render' import type { DiyAiRenderAccess } from '@/lib/diy/ai-render' import type { DiyBatchImageActions } from '../../hooks/useDiyBatchImageActions' import type { DiyImageSelection } from '@/lib/diy/image-tools' +import DiySolidDoorColorReview from '../DiySolidDoorColorReview' const actionClass = '!h-6 !min-h-0 !min-w-0 !px-1 !py-0 !text-[10px] focus:!px-1 focus:!py-0' export default function DiyBatchRecord({ record, image, index, actions: a, access }: { @@ -38,6 +39,7 @@ export default function DiyBatchRecord({ record, image, index, actions: a, acces {diyBatchRecordState(record)}
+ {image && } {entry && source &&
{canLayout && } diff --git a/furniture-3d-system/src/app/diy/components/batch/DiyBatchSettings.tsx b/furniture-3d-system/src/app/diy/components/batch/DiyBatchSettings.tsx index 17832d57..c2f9e6f7 100644 --- a/furniture-3d-system/src/app/diy/components/batch/DiyBatchSettings.tsx +++ b/furniture-3d-system/src/app/diy/components/batch/DiyBatchSettings.tsx @@ -1,6 +1,7 @@ 'use client' import type { DiyAiBatchController, DiyBatchSettings } from '../../hooks/useDiyAiBatch' +import DiySolidDoorColors from '../DiySolidDoorColors' const field = '!min-h-0 !min-w-0 w-full rounded-md border border-zinc-200 bg-white px-2 py-1.5 text-[11px] leading-5 outline-none focus:border-zinc-500 disabled:opacity-60' const singleLineField = `${field} !h-7 !py-0` @@ -13,6 +14,7 @@ export default function DiyBatchSettings({ batch: b }: { batch: DiyAiBatchContro aria-pressed={b.settings.mode===mode.value} onClick={() => change('mode',mode.value)} className={`!h-7 !min-h-0 !min-w-0 flex-1 rounded px-2 py-0 text-[11px] ${b.settings.mode===mode.value ? 'bg-white font-medium text-zinc-800 shadow-sm' : 'text-zinc-500'}`}>{mode.label})}
+