Update App.jsx via upload script - 2026-11-09 17:53:17

This commit is contained in:
mike 2026-11-09 17:53:30 +08:00
parent 4e0fee9854
commit 2fb83e52a9
1 changed files with 18 additions and 2 deletions

20
App.jsx
View File

@ -9327,6 +9327,22 @@ function BrochureBulkUpload({ products, setProducts, onNotify }) {
const ok = [], skip = []; const ok = [], skip = [];
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
const f = files[i]; const f = files[i];
// 图片文件名就是型号(如 SK100-12.jpg):作为这个型号的主图(产品主图 + 网站主图第 1 张)
if (/^image\//.test(f.type) && !parseBrochureName(f.name)) {
const base = f.name.replace(/\.[a-z0-9]+$/i, '').trim();
const prod = products.find(p => normModel(p.name) === normModel(base));
if (!prod) { skip.push(f.name); continue; }
setBusy(`${i + 1}/${files.length}`);
try {
const res = await uploadFile(prod.id, f);
setProducts(list => list.map(x => x.id !== prod.id ? x : {
...x, productImageFileName: res.fileName, productImageOriginalName: res.originalName,
webImages: [res.fileName, ...(Array.isArray(x.webImages) ? x.webImages.filter(n => n !== x.productImageFileName) : [])].slice(0, 6),
}));
ok.push(f.name);
} catch (e) { skip.push(`${f.name}(${e.message})`); }
continue;
}
const info = parseBrochureName(f.name); const info = parseBrochureName(f.name);
const prod = info && products.find(p => normModel(p.name) === normModel(info.model)); const prod = info && products.find(p => normModel(p.name) === normModel(info.model));
if (!prod) { skip.push(f.name); continue; } if (!prod) { skip.push(f.name); continue; }
@ -9346,11 +9362,11 @@ function BrochureBulkUpload({ products, setProducts, onNotify }) {
} catch (e) { skip.push(`${f.name}(${e.message})`); } } catch (e) { skip.push(`${f.name}(${e.message})`); }
} }
setBusy(''); setBusy('');
window.alert(`已上传 ${ok.length} 个彩页` + (skip.length ? `\n\n没有上传(文件名对不上型号或上传失败):\n${skip.join('\n')}\n\n文件名格式:型号_语言.html,语言用 zh / en / ru / es / fr / ar,型号要和产品档案里的完全一致。` : '')); window.alert(`已上传 ${ok.length} 个文件` + (skip.length ? `\n\n没有上传(文件名对不上型号或上传失败):\n${skip.join('\n')}\n\n文件名格式:彩页 型号_语言.html(语言 zh / en / ru / es / fr / ar),主图 型号.jpg;型号要和产品档案里的完全一致。` : ''));
} }
return ( return (
<label className="btn" style={{ width: '100%', justifyContent: 'center', marginBottom: 12, cursor: busy ? 'default' : 'pointer' }}> <label className="btn" style={{ width: '100%', justifyContent: 'center', marginBottom: 12, cursor: busy ? 'default' : 'pointer' }}>
<FileText size={14} />{busy ? `正在上传彩页 ${busy}…` : '批量上传多语言彩页(型号_语言.html)'} <FileText size={14} />{busy ? `正在上传 ${busy}…` : '批量上传彩页 / 主图(型号_语言.html、型号.jpg)'}
<input type="file" multiple accept=".html,.htm,text/html,application/pdf,image/*" style={{ display: 'none' }} disabled={!!busy} onChange={e => { run(e.target.files); e.target.value = ''; }} /> <input type="file" multiple accept=".html,.htm,text/html,application/pdf,image/*" style={{ display: 'none' }} disabled={!!busy} onChange={e => { run(e.target.files); e.target.value = ''; }} />
</label> </label>
); );