diff --git a/MicUploadPage.jsx b/MicUploadPage.jsx index 4627ab8..ad186ac 100644 --- a/MicUploadPage.jsx +++ b/MicUploadPage.jsx @@ -42,6 +42,9 @@ function useMicSession() { let msg; try { msg = JSON.parse(ev.data); } catch (e) { return; } if (msg.type === 'frame') { + // 收到画面帧本身就是"确实连着"的铁证——直接在这里也置一次true, + // 不完全依赖onopen这一个事件(万一它在某些代理环境下没如期触发) + setConnected(true); frameCallbackRef.current && frameCallbackRef.current(msg.data); } else if (msg.type === 'log') { appendLog(msg); @@ -234,7 +237,7 @@ function SavedCredentialsPanel({ sessionId, sendAutofill }) { // 品类 -> MIC仿造发布模板URL 配置面板。列表来自CRM"产品分组"里的品类树, // 每个细分品类(type)一行,读写走 /api/mic-upload/templates。 function TemplateConfigPanel({ productCategories, onClose }) { - const [values, setValues] = useState({}); + const [rawText, setRawText] = useState(''); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [msg, setMsg] = useState(''); @@ -242,19 +245,30 @@ function TemplateConfigPanel({ productCategories, onClose }) { useEffect(() => { fetch('/api/mic-upload/templates', { cache: 'no-store' }) .then((r) => r.json()) - .then((d) => setValues(d.value || {})) - .catch(() => {}) + .then((d) => setRawText(JSON.stringify(d.value || {}, null, 2))) + .catch((e) => setMsg(`读取失败: ${e.message}`)) .finally(() => setLoading(false)); }, []); async function handleSave() { - setSaving(true); setMsg(''); + let parsed; + try { + parsed = JSON.parse(rawText); + } catch (e) { + setMsg(`不是合法的JSON,改一下格式再保存: ${e.message}`); + return; + } + if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) { + setMsg('格式不对,最外层必须是 { "品类名": "URL", ... } 这样的对象'); + return; + } + setSaving(true); try { const res = await fetch('/api/mic-upload/templates', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ value: values }), + body: JSON.stringify({ value: parsed }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error || '保存失败'); @@ -266,40 +280,39 @@ function TemplateConfigPanel({ productCategories, onClose }) { } } + const allTypeNames = (productCategories || []).flatMap((cat) => cat.types || []); + return (