Update MicUploadPage.jsx via upload script - 2026-09-21 11:57:46

This commit is contained in:
mike 2026-09-21 11:57:59 +08:00
parent 517e442a51
commit cb3ec0d378
1 changed files with 24 additions and 34 deletions

View File

@ -237,7 +237,7 @@ function SavedCredentialsPanel({ sessionId, sendAutofill }) {
// 品类 -> MIC仿造发布模板URL 配置面板。列表来自CRM"产品分组"里的品类树,
// 每个细分品类(type)一行,读写走 /api/mic-upload/templates。
function TemplateConfigPanel({ productCategories, onClose }) {
const [rawText, setRawText] = useState('');
const [values, setValues] = useState({});
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
const [msg, setMsg] = useState('');
@ -245,30 +245,19 @@ function TemplateConfigPanel({ productCategories, onClose }) {
useEffect(() => {
fetch('/api/mic-upload/templates', { cache: 'no-store' })
.then((r) => r.json())
.then((d) => setRawText(JSON.stringify(d.value || {}, null, 2)))
.then((d) => setValues(d.value || {}))
.catch((e) => setMsg(`读取失败: ${e.message}`))
.finally(() => setLoading(false));
}, []);
async function handleSave() {
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: parsed }),
body: JSON.stringify({ value: values }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || '保存失败');
@ -280,39 +269,40 @@ 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: 560, maxHeight: '80vh', overflowY: 'auto', display: 'flex', flexDirection: 'column' }}>
<div style={{ background: '#fff', borderRadius: 8, padding: 20, width: 520, maxHeight: '80vh', overflowY: 'auto' }}>
<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 }}>
直接编辑这段JSON——key是品类的细分类型名,value是"仿造发布"模板产品的完整URL(形如
https://membercenter.made-in-china.com/productmanage.do?xcase=addSimilar&prodId=xxxx)。
不需要的品类可以留在JSON里但值填空字符串,或者干脆删掉那一行。
每个品类填一个"仿造发布"模板产品的完整URL(形如
https://membercenter.made-in-china.com/productmanage.do?xcase=addSimilar&prodId=xxxx),
需要你先在MIC后台为每个品类找一个字段结构合适的已发布产品。留空的品类点"开始自动填写"时会报错提示先配置。
</div>
{loading ? (
<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',
}}
{(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 style={{ fontSize: 11, color: 'var(--ink-soft, #888)', margin: '8px 0' }}>
当前系统里的品类细分类型名(key必须跟这些完全一致才会被自动填写用到):
{allTypeNames.join('、')}
</div>
))}
</div>
))}
<button className="btn-primary" disabled={saving} onClick={handleSave}>
{saving ? '保存中...' : '保存'}
{saving ? '保存中...' : '保存全部'}
</button>
{msg && <span style={{ marginLeft: 8, fontSize: 12 }}>{msg}</span>}
</>