Update MicUploadPage.jsx via upload script - 2026-09-21 11:26:50

This commit is contained in:
mike 2026-09-21 11:27:01 +08:00
parent 5a121d0cbb
commit c00156d124
1 changed files with 33 additions and 44 deletions

View File

@ -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') && (
<>
<input
placeholder="搜索产品(型号/品牌)"
@ -575,24 +573,15 @@ export function MicUploadPage({ products = [], productCategories = [] }) {
</>
)}
{(phase === 'filling' || phase === 'filled') && queueIds.length > 1 && (
{(phase === 'filling' || phase === 'submitting') && (
<div style={{ fontSize: 12, color: 'var(--ink-soft, #888)' }}>
批量进度:第 {queueIndex + 1} / {queueIds.length} 个
{phase === 'filling' ? '正在自动填写...' : '正在提交...'}
{queueIds.length > 1 && ` 第 ${queueIndex + 1} / ${queueIds.length} 个`}
</div>
)}
{phase === 'filled' && (
<button className="btn-primary" disabled={busy} onClick={handleSubmit}>
{busy
? '提交中...'
: queueIndex + 1 < queueIds.length
? '确认无误,提交并填写下一个'
: '确认无误,提交发布'}
</button>
)}
{phase === 'submitted' && (
<div style={{ color: 'var(--success, #2a8f4d)', fontSize: 13 }}>✅ 已提交,请在画面里核对发布结果</div>
<div style={{ color: 'var(--success, #2a8f4d)', fontSize: 13 }}>✅ 已全部提交,请在画面里核对发布结果</div>
)}
{phase !== 'browsing' && (