Update MicUploadPage.jsx via upload script - 2026-09-21 11:41:19
This commit is contained in:
parent
c00156d124
commit
25ff154a73
|
|
@ -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 (
|
||||
<div style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.4)', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 50 }}>
|
||||
<div style={{ background: '#fff', borderRadius: 8, padding: 20, width: 520, maxHeight: '80vh', overflowY: 'auto' }}>
|
||||
<div style={{ background: '#fff', borderRadius: 8, padding: 20, width: 560, maxHeight: '80vh', overflowY: 'auto', display: 'flex', flexDirection: 'column' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
|
||||
<div className="panel-title">品类发布模板配置</div>
|
||||
<button className="btn-ghost" onClick={onClose}>关闭</button>
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--ink-soft, #888)', marginBottom: 10 }}>
|
||||
每个品类填一个"仿造发布"模板产品的完整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里但值填空字符串,或者干脆删掉那一行。
|
||||
</div>
|
||||
{loading ? (
|
||||
<div>加载中...</div>
|
||||
) : (
|
||||
<>
|
||||
{(productCategories || []).map((cat) => (
|
||||
<div key={cat.id} style={{ marginBottom: 10 }}>
|
||||
<div style={{ fontSize: 13, fontWeight: 600, marginBottom: 4 }}>{cat.name}</div>
|
||||
{(cat.types || []).map((typeName) => (
|
||||
<div key={typeName} style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 4 }}>
|
||||
<div style={{ width: 120, fontSize: 12, flexShrink: 0 }}>{typeName}</div>
|
||||
<input
|
||||
placeholder="addSimilar模板URL"
|
||||
value={values[typeName] || ''}
|
||||
onChange={(e) => setValues((prev) => ({ ...prev, [typeName]: e.target.value }))}
|
||||
style={{ flex: 1, padding: '4px 6px', fontSize: 12 }}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
<textarea
|
||||
value={rawText}
|
||||
onChange={(e) => setRawText(e.target.value)}
|
||||
spellCheck={false}
|
||||
style={{
|
||||
width: '100%', minHeight: 320, fontFamily: 'monospace', fontSize: 12,
|
||||
padding: 8, boxSizing: 'border-box', whiteSpace: 'pre',
|
||||
}}
|
||||
/>
|
||||
<div style={{ fontSize: 11, color: 'var(--ink-soft, #888)', margin: '8px 0' }}>
|
||||
当前系统里的品类细分类型名(key必须跟这些完全一致才会被自动填写用到):
|
||||
{allTypeNames.join('、')}
|
||||
</div>
|
||||
<button className="btn-primary" disabled={saving} onClick={handleSave}>
|
||||
{saving ? '保存中...' : '保存全部'}
|
||||
{saving ? '保存中...' : '保存'}
|
||||
</button>
|
||||
{msg && <span style={{ marginLeft: 8, fontSize: 12 }}>{msg}</span>}
|
||||
</>
|
||||
|
|
|
|||
Loading…
Reference in New Issue