diff --git a/frontend/src/components/ChatSidebar.vue b/frontend/src/components/ChatSidebar.vue index f956afc..3412dbc 100644 --- a/frontend/src/components/ChatSidebar.vue +++ b/frontend/src/components/ChatSidebar.vue @@ -200,7 +200,7 @@ async function onCreateSession() { if (creatingSession.value) return creatingSession.value = true try { - const res = await api.post('/chat/sessions') + const res: any = await api.post('/chat/sessions') const sessionId = res.data?.session_id || res.data?.data?.session_id || res.session_id if (!sessionId) { throw new Error('服务端未返回 session_id') diff --git a/frontend/src/components/poster/PosterStepPreview.vue b/frontend/src/components/poster/PosterStepPreview.vue index cb2c829..de9c5a5 100644 --- a/frontend/src/components/poster/PosterStepPreview.vue +++ b/frontend/src/components/poster/PosterStepPreview.vue @@ -1,68 +1,72 @@ @@ -79,27 +83,43 @@ const props = defineProps<{ templateId: number | null copyContent: any aiRawContent?: any - size?: string + initialSize?: string + templateName?: string + scenarioLabel?: string }>() defineEmits<{ back: [] }>() +const selectedSize = ref(props.initialSize || '1024x1792') const taskStatus = ref<'idle' | 'queued' | 'generating' | 'done' | 'failed'>('idle') const taskProgress = ref(0) const taskError = ref(null) const posterObjectUrl = ref(null) const recordId = ref(null) -const generationMode = ref(null) -const pollCount = ref(0) let pollTimer: ReturnType | null = null -const MAX_POLL_RETRIES = 90 // 最多轮询 90 次 = 3 分钟 - -const sizeLabelMap: Record = { - '1024x1792': '竖版 1080×1920', - '1792x1024': '横版 900×500', - '1024x1024': '方图 1080×1080', -} -const sizeLabel = computed(() => sizeLabelMap[props.size || ''] || props.size || '1024x1792') +const checklist = [ + '标题和正文没有夸大收益', + '产品名称和客户场景匹配', + '尺寸适合本次投放渠道', + '行动号召清晰且合规', +] +const statusLabel = computed(() => { + if (taskStatus.value === 'queued') return '排队中' + if (taskStatus.value === 'generating') return '生成中' + if (taskStatus.value === 'done') return '已完成' + if (taskStatus.value === 'failed') return '失败' + return '待生成' +}) +const sizeText = computed(() => { + if (selectedSize.value === '1792x1024') return '横版 1792x1024' + if (selectedSize.value === '1024x1024') return '方图 1024x1024' + return '竖版 1024x1792' +}) +const sizeClass = computed(() => { + if (selectedSize.value === '1792x1024') return 'landscape' + if (selectedSize.value === '1024x1024') return 'square' + return 'portrait' +}) function clearPoster() { stopPolling() @@ -111,8 +131,6 @@ function clearPoster() { taskStatus.value = 'idle' taskProgress.value = 0 taskError.value = null - generationMode.value = null - pollCount.value = 0 } function stopPolling() { @@ -126,16 +144,16 @@ async function onGenerate() { taskStatus.value = 'queued' taskProgress.value = 0 taskError.value = null - pollCount.value = 0 try { const res: any = await posterApi.generatePoster({ caseUploadId: props.caseUploadId ?? undefined, productId: props.productId, templateId: props.templateId ?? undefined, copyContent: props.copyContent, - size: props.size || '1024x1792', - copyMode: 'ai', - } as any) + aiRawContent: props.aiRawContent, + size: selectedSize.value, + copyMode: props.aiRawContent ? 'ai' : 'template', + }) const record = res?.data recordId.value = record?.id if (record?.id) { @@ -149,23 +167,13 @@ async function onGenerate() { function startPolling(id: number) { stopPolling() - pollCount.value = 0 pollTimer = setInterval(async () => { - pollCount.value++ - // 超时保护 - if (pollCount.value > MAX_POLL_RETRIES) { - stopPolling() - taskStatus.value = 'failed' - taskError.value = '生成超时,请查看历史记录或重新生成' - return - } try { const res: any = await posterApi.getRecord(id) const data = res?.data taskStatus.value = data?.taskStatus || 'generating' taskProgress.value = data?.taskProgress || 0 taskError.value = data?.taskError || null - generationMode.value = data?.generationMode || null if (taskStatus.value === 'done') { stopPolling() @@ -180,7 +188,7 @@ function startPolling(id: number) { stopPolling() } } catch { - // 轮询失败不停止,继续重试 + // 轮询失败时继续等待下一次状态更新 } }, 2000) } @@ -209,98 +217,198 @@ onBeforeUnmount(() => { diff --git a/frontend/src/components/poster/PosterStepProduct.vue b/frontend/src/components/poster/PosterStepProduct.vue index a994b35..b05a2b3 100644 --- a/frontend/src/components/poster/PosterStepProduct.vue +++ b/frontend/src/components/poster/PosterStepProduct.vue @@ -1,6 +1,11 @@