diff --git a/MicUploadPage.jsx b/MicUploadPage.jsx index 92d670b..ce48067 100644 --- a/MicUploadPage.jsx +++ b/MicUploadPage.jsx @@ -240,7 +240,7 @@ function TemplateConfigPanel({ productCategories, onClose }) { const [msg, setMsg] = useState(''); useEffect(() => { - fetch('/api/mic-upload/templates') + fetch('/api/mic-upload/templates', { cache: 'no-store' }) .then((r) => r.json()) .then((d) => setValues(d.value || {})) .catch(() => {}) @@ -315,7 +315,8 @@ export function MicUploadPage({ products = [], productCategories = [] }) { // connecting -> browsing -> ready -> filling -> filled -> submitted(还有个 error 态) const [phase, setPhase] = useState('connecting'); - const [selectedProductId, setSelectedProductId] = useState(''); + const [queueIds, setQueueIds] = useState([]); // 选中要批量处理的产品,按点击顺序 + const [queueIndex, setQueueIndex] = useState(-1); // 当前处理到队列里第几个,-1=还没开始 const [search, setSearch] = useState(''); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); @@ -412,9 +413,11 @@ export function MicUploadPage({ products = [], productCategories = [] }) { } } - async function handleFill() { + // 按队列顺序处理第idx个产品:导航到模板+AI生成标题关键词+填表,不自动提交 + async function runFillForIndex(idx) { if (!sessionId) { setError('会话已断开,请重新打开登录页'); return; } - if (!selectedProductId) { setError('请先选择一个产品'); return; } + const productId = queueIds[idx]; + if (!productId) { setError('队列为空'); return; } setError(''); setBusy(true); setPhase('filling'); @@ -422,10 +425,11 @@ export function MicUploadPage({ products = [], productCategories = [] }) { const res = await fetch(`/api/mic-upload/sessions/${sessionId}/publish`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ productId: selectedProductId }), + body: JSON.stringify({ productId }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error || '自动填写失败'); + setQueueIndex(idx); setPhase('filled'); } catch (e) { setError(e.message); @@ -435,6 +439,11 @@ export function MicUploadPage({ products = [], productCategories = [] }) { } } + async function handleFill() { + if (queueIds.length === 0) { setError('请先选择至少一个产品'); return; } + await runFillForIndex(0); + } + async function handleSubmit() { if (!sessionId) { setError('会话已断开,请重新打开登录页'); return; } setError(''); @@ -443,17 +452,37 @@ export function MicUploadPage({ products = [], productCategories = [] }) { 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 || '提交失败'); - setPhase('submitted'); + 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); - } finally { setBusy(false); } } + function toggleQueue(productId) { + // 提交完一批之后phase停在'submitted',这时候点选新产品要能重新回到'ready' + // 才会显示"开始自动填写"按钮;处理中(filling/filled)不允许中途改选,忽略点击。 + if (phase === 'filling' || phase === 'filled') return; + if (phase === 'submitted') setPhase('ready'); + setQueueIds((prev) => ( + prev.includes(productId) ? prev.filter((id) => id !== productId) : [...prev, productId] + )); + } + async function handleClose() { await stop(); - setSelectedProductId(''); + setQueueIds([]); + setQueueIndex(-1); // 关掉之后自动重新连接一次——这会真正启动一个全新的浏览器(旧的已经关了), // 相当于手动"重启"这个模块,不用刷新整个页面。 await handleRetryConnect(); @@ -501,11 +530,12 @@ export function MicUploadPage({ products = [], productCategories = [] }) {
没有匹配的产品
)} {filteredProducts.map((p) => { - const selected = selectedProductId === p.id; + const orderIdx = queueIds.indexOf(p.id); + const selected = orderIdx >= 0; return (
setSelectedProductId(p.id)} + onClick={() => toggleQueue(p.id)} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '6px 8px', fontSize: 13, cursor: 'pointer', @@ -514,32 +544,50 @@ export function MicUploadPage({ products = [], productCategories = [] }) { }} > {p.brand ? `[${p.brand}] ` : ''}{p.name} - - {selected ? '✓' : '+'} + + {selected ? `#${orderIdx + 1}` : '+'}
); })} - - )} - - {phase === 'ready' && ( - <> - - {!selectedProductId && ( + {queueIds.length > 0 && (
- 提示:先在上面的列表里点选一个产品(不是只搜索),选中后这里才会真正开始填写。 + 已选 {queueIds.length} 个,按点选顺序依次处理。再点一下已选的行可以取消。
)} )} + {phase === 'ready' && ( + <> + + {queueIds.length === 0 && ( +
+ 提示:先在上面的列表里点选一个或多个产品(不是只搜索),选中后这里才会真正开始填写。 +
+ )} + + )} + + {(phase === 'filling' || phase === 'filled') && queueIds.length > 1 && ( +
+ 批量进度:第 {queueIndex + 1} / {queueIds.length} 个 +
+ )} + {phase === 'filled' && ( )}