From 25ff154a7320c1ce01f2cf633d2ba0ec94a83d8c Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 21 Sep 2026 11:41:30 +0800 Subject: [PATCH] Update MicUploadPage.jsx via upload script - 2026-09-21 11:41:19 --- MicUploadPage.jsx | 65 ++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 26 deletions(-) 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 (
-
+
品类发布模板配置
- 每个品类填一个"仿造发布"模板产品的完整URL(形如 - https://membercenter.made-in-china.com/productmanage.do?xcase=addSimilar&prodId=xxxx), - 需要你先在MIC后台为每个品类找一个字段结构合适的已发布产品。留空的品类点"开始自动填写"时会报错提示先配置。 + 直接编辑这段JSON——key是品类的细分类型名,value是"仿造发布"模板产品的完整URL(形如 + https://membercenter.made-in-china.com/productmanage.do?xcase=addSimilar&prodId=xxxx)。 + 不需要的品类可以留在JSON里但值填空字符串,或者干脆删掉那一行。
{loading ? (
加载中...
) : ( <> - {(productCategories || []).map((cat) => ( -
-
{cat.name}
- {(cat.types || []).map((typeName) => ( -
-
{typeName}
- setValues((prev) => ({ ...prev, [typeName]: e.target.value }))} - style={{ flex: 1, padding: '4px 6px', fontSize: 12 }} - /> -
- ))} -
- ))} +