From c00156d12442437b7847c70b0e99af69742ed32c Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 21 Sep 2026 11:27:01 +0800 Subject: [PATCH] Update MicUploadPage.jsx via upload script - 2026-09-21 11:26:50 --- MicUploadPage.jsx | 77 ++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/MicUploadPage.jsx b/MicUploadPage.jsx index ce48067..4627ab8 100644 --- a/MicUploadPage.jsx +++ b/MicUploadPage.jsx @@ -414,12 +414,15 @@ export function MicUploadPage({ products = [], productCategories = [] }) { } // 按队列顺序处理第idx个产品:导航到模板+AI生成标题关键词+填表,不自动提交 + // 全自动:填完一个立刻自动提交,提交完立刻自动填下一个,队列跑完才停—— + // 不需要每个产品手动点一次"提交"。 async function runFillForIndex(idx) { if (!sessionId) { setError('会话已断开,请重新打开登录页'); return; } const productId = queueIds[idx]; if (!productId) { setError('队列为空'); return; } setError(''); setBusy(true); + setQueueIndex(idx); setPhase('filling'); try { const res = await fetch(`/api/mic-upload/sessions/${sessionId}/publish`, { @@ -429,12 +432,32 @@ export function MicUploadPage({ products = [], productCategories = [] }) { }); const data = await res.json(); if (!res.ok) throw new Error(data.error || '自动填写失败'); - setQueueIndex(idx); - setPhase('filled'); + await submitOneAuto(idx); } catch (e) { setError(e.message); setPhase('ready'); - } finally { + setBusy(false); + } + } + + async function submitOneAuto(idx) { + setPhase('submitting'); + try { + const res = await fetch(`/api/mic-upload/sessions/${sessionId}/submit`, { method: 'POST' }); + const data = await res.json(); + if (!res.ok) throw new Error(data.error || '提交失败'); + const nextIdx = idx + 1; + if (nextIdx < queueIds.length) { + await runFillForIndex(nextIdx); // 递归接着处理队列下一个,全程不用点按钮 + } else { + setPhase('submitted'); + setQueueIds([]); + setQueueIndex(-1); + setBusy(false); + } + } catch (e) { + setError(`第${idx + 1}个产品提交失败: ${e.message}`); + setPhase('ready'); setBusy(false); } } @@ -444,35 +467,10 @@ export function MicUploadPage({ products = [], productCategories = [] }) { await runFillForIndex(0); } - async function handleSubmit() { - if (!sessionId) { setError('会话已断开,请重新打开登录页'); return; } - setError(''); - setBusy(true); - try { - const res = await fetch(`/api/mic-upload/sessions/${sessionId}/submit`, { method: 'POST' }); - const data = await res.json(); - if (!res.ok) throw new Error(data.error || '提交失败'); - const nextIdx = queueIndex + 1; - if (nextIdx < queueIds.length) { - // 队列里还有下一个——自动跳去填下一个,提交仍然要人工再点一次确认 - setBusy(false); - await runFillForIndex(nextIdx); - } else { - setPhase('submitted'); - setQueueIds([]); - setQueueIndex(-1); - setBusy(false); - } - } catch (e) { - setError(e.message); - setBusy(false); - } - } - function toggleQueue(productId) { // 提交完一批之后phase停在'submitted',这时候点选新产品要能重新回到'ready' - // 才会显示"开始自动填写"按钮;处理中(filling/filled)不允许中途改选,忽略点击。 - if (phase === 'filling' || phase === 'filled') return; + // 才会显示"开始自动填写"按钮;处理中(filling/submitting)不允许中途改选,忽略点击。 + if (phase === 'filling' || phase === 'submitting') return; if (phase === 'submitted') setPhase('ready'); setQueueIds((prev) => ( prev.includes(productId) ? prev.filter((id) => id !== productId) : [...prev, productId] @@ -517,7 +515,7 @@ export function MicUploadPage({ products = [], productCategories = [] }) { )} - {(phase === 'ready' || phase === 'filling' || phase === 'filled' || phase === 'submitted') && ( + {(phase === 'ready' || phase === 'filling' || phase === 'submitting' || phase === 'submitted') && ( <> )} - {(phase === 'filling' || phase === 'filled') && queueIds.length > 1 && ( + {(phase === 'filling' || phase === 'submitting') && (
- 批量进度:第 {queueIndex + 1} / {queueIds.length} 个 + {phase === 'filling' ? '正在自动填写...' : '正在提交...'} + {queueIds.length > 1 && ` 第 ${queueIndex + 1} / ${queueIds.length} 个`}
)} - {phase === 'filled' && ( - - )} - {phase === 'submitted' && ( -
✅ 已提交,请在画面里核对发布结果
+
✅ 已全部提交,请在画面里核对发布结果
)} {phase !== 'browsing' && (