Update App.jsx via upload script - 2026-11-09 16:28:06
This commit is contained in:
parent
74b02fc290
commit
fa817cd7fb
217
App.jsx
217
App.jsx
|
|
@ -13,7 +13,7 @@ import {
|
||||||
storageGet, storageSet, hasUnsavedChanges, saveTemplate, localPendingTemplates, uploadFile, deleteFile,
|
storageGet, storageSet, hasUnsavedChanges, saveTemplate, localPendingTemplates, uploadFile, deleteFile,
|
||||||
authCheck, authLogin, authLogout, authChangePassword,
|
authCheck, authLogin, authLogout, authChangePassword,
|
||||||
getAiConfig, saveAiConfig, deleteAiConfig, testAiConfig,
|
getAiConfig, saveAiConfig, deleteAiConfig, testAiConfig,
|
||||||
parseCatalogFiles, translateTerms, getPreciseDoc, translatePreciseDoc,
|
parseCatalogFiles, translateTerms,
|
||||||
} from './storage';
|
} from './storage';
|
||||||
|
|
||||||
/* ----------------------------- constants ----------------------------- */
|
/* ----------------------------- constants ----------------------------- */
|
||||||
|
|
@ -870,7 +870,7 @@ function upsertProductByName(list, product) {
|
||||||
productImageOriginalName: existing.productImageOriginalName,
|
productImageOriginalName: existing.productImageOriginalName,
|
||||||
brochureFileName: existing.brochureFileName,
|
brochureFileName: existing.brochureFileName,
|
||||||
brochureOriginalName: existing.brochureOriginalName,
|
brochureOriginalName: existing.brochureOriginalName,
|
||||||
preciseDocId: product.preciseDocId || existing.preciseDocId || '', // 这次没勾精准导入时,保留之前生成的原版彩页
|
brochures: existing.brochures, // 多语言原版彩页(手动上传的文件),重新导入参数时保留
|
||||||
sellingPoints: existing.sellingPoints,
|
sellingPoints: existing.sellingPoints,
|
||||||
costPrice: existing.costPrice,
|
costPrice: existing.costPrice,
|
||||||
notes: existing.notes,
|
notes: existing.notes,
|
||||||
|
|
@ -2194,11 +2194,7 @@ const Styles = () => (
|
||||||
display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
|
display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.precise-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin: 4px 0 12px; border: 1px solid var(--line, #ddd); border-radius: 8px; font-size: 12.5px; line-height: 1.55; color: var(--ink-soft); cursor: pointer; }
|
.brochure-frame { width: 100%; height: 75vh; border: 1px solid var(--line, #ddd); border-radius: 8px; background: #8a8a8a; }
|
||||||
.precise-opt.on { border-color: var(--accent, #2f6fed); background: rgba(47,111,237,.06); }
|
|
||||||
.precise-opt input { margin-top: 3px; flex: none; }
|
|
||||||
.precise-opt b { display: block; color: var(--ink, #222); font-size: 13px; margin-bottom: 2px; }
|
|
||||||
.precise-frame { width: 100%; height: 75vh; border: 1px solid var(--line, #ddd); border-radius: 8px; background: #8a8a8a; }
|
|
||||||
/* ---------- quote / invoice document preview (deliberately NOT themed like the app) ---------- */
|
/* ---------- quote / invoice document preview (deliberately NOT themed like the app) ---------- */
|
||||||
.doc-preview {
|
.doc-preview {
|
||||||
background: #fff; color: #2d2d2d; padding: 46px 52px; max-width: 840px; margin: 0 auto;
|
background: #fff; color: #2d2d2d; padding: 46px 52px; max-width: 840px; margin: 0 auto;
|
||||||
|
|
@ -2562,8 +2558,6 @@ function MainApp({ username, onLogout }) {
|
||||||
const [aiImportHintBrand, setAiImportHintBrand] = useState('');
|
const [aiImportHintBrand, setAiImportHintBrand] = useState('');
|
||||||
const [aiImportHintType, setAiImportHintType] = useState('');
|
const [aiImportHintType, setAiImportHintType] = useState('');
|
||||||
const [aiImportHintExtraTypes, setAiImportHintExtraTypes] = useState([]); // 这批产品同时属于的其他细分品类(多选)
|
const [aiImportHintExtraTypes, setAiImportHintExtraTypes] = useState([]); // 这批产品同时属于的其他细分品类(多选)
|
||||||
const [aiImportPrecise, setAiImportPrecise] = useState(false); // 精准导入:同时按原版式生成"原版彩页",之后可翻译
|
|
||||||
const [aiImportPreciseInfo, setAiImportPreciseInfo] = useState(null); // { doc, error }
|
|
||||||
const [aiImportTruncatedWarning, setAiImportTruncatedWarning] = useState(false);
|
const [aiImportTruncatedWarning, setAiImportTruncatedWarning] = useState(false);
|
||||||
|
|
||||||
const [exportOpen, setExportOpen] = useState(false);
|
const [exportOpen, setExportOpen] = useState(false);
|
||||||
|
|
@ -3330,7 +3324,7 @@ function MainApp({ username, onLogout }) {
|
||||||
function openAiImport() {
|
function openAiImport() {
|
||||||
setAiImportOpen(true); setAiImportDrafts(null); setAiImportError('');
|
setAiImportOpen(true); setAiImportDrafts(null); setAiImportError('');
|
||||||
setAiImportHintCategory(''); setAiImportHintBrand(''); setAiImportHintType(''); setAiImportHintExtraTypes([]);
|
setAiImportHintCategory(''); setAiImportHintBrand(''); setAiImportHintType(''); setAiImportHintExtraTypes([]);
|
||||||
setAiImportTruncatedWarning(false); setAiImportPreciseInfo(null);
|
setAiImportTruncatedWarning(false);
|
||||||
}
|
}
|
||||||
function closeAiImport() { setAiImportOpen(false); setAiImportDrafts(null); setAiImportError(''); setAiImportBusy(false); }
|
function closeAiImport() { setAiImportOpen(false); setAiImportDrafts(null); setAiImportError(''); setAiImportBusy(false); }
|
||||||
|
|
||||||
|
|
@ -3343,10 +3337,8 @@ function MainApp({ username, onLogout }) {
|
||||||
category: aiImportHintCategory.trim(),
|
category: aiImportHintCategory.trim(),
|
||||||
brand: aiImportHintBrand.trim(),
|
brand: aiImportHintBrand.trim(),
|
||||||
type: aiImportHintType.trim(),
|
type: aiImportHintType.trim(),
|
||||||
precise: aiImportPrecise,
|
|
||||||
});
|
});
|
||||||
const parsed = (res && res.products) || [];
|
const parsed = (res && res.products) || [];
|
||||||
setAiImportPreciseInfo(aiImportPrecise ? { doc: res && res.preciseDoc, error: (res && res.preciseError) || '' } : null);
|
|
||||||
if (!parsed.length) { setAiImportError('没有从文件里识别出任何产品,换一份更清晰的文件试试'); return; }
|
if (!parsed.length) { setAiImportError('没有从文件里识别出任何产品,换一份更清晰的文件试试'); return; }
|
||||||
setAiImportTruncatedWarning(!!(res && res.truncated));
|
setAiImportTruncatedWarning(!!(res && res.truncated));
|
||||||
const drafts = parsed.map((p, i) => ({
|
const drafts = parsed.map((p, i) => ({
|
||||||
|
|
@ -3406,7 +3398,6 @@ function MainApp({ username, onLogout }) {
|
||||||
applicationScenarios: p.applicationScenarios || '',
|
applicationScenarios: p.applicationScenarios || '',
|
||||||
container20ft: p.container20ft || '', container40ft: p.container40ft || '', container40hq: p.container40hq || '',
|
container20ft: p.container20ft || '', container40ft: p.container40ft || '', container40hq: p.container40hq || '',
|
||||||
extraSpecs: Array.isArray(p.extraSpecs) ? p.extraSpecs.filter(x => x && x.label && x.value) : [],
|
extraSpecs: Array.isArray(p.extraSpecs) ? p.extraSpecs.filter(x => x && x.label && x.value) : [],
|
||||||
preciseDocId: p.preciseDocId || '',
|
|
||||||
}));
|
}));
|
||||||
setAiImportDrafts(drafts);
|
setAiImportDrafts(drafts);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -3497,7 +3488,6 @@ function MainApp({ username, onLogout }) {
|
||||||
applicationScenarios: d.applicationScenarios || '',
|
applicationScenarios: d.applicationScenarios || '',
|
||||||
container20ft: d.container20ft || '', container40ft: d.container40ft || '', container40hq: d.container40hq || '',
|
container20ft: d.container20ft || '', container40ft: d.container40ft || '', container40hq: d.container40hq || '',
|
||||||
extraSpecs: Array.isArray(d.extraSpecs) ? d.extraSpecs.filter(x => x && x.label && x.value) : [],
|
extraSpecs: Array.isArray(d.extraSpecs) ? d.extraSpecs.filter(x => x && x.label && x.value) : [],
|
||||||
preciseDocId: d.preciseDocId || '',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function confirmAiImport() {
|
function confirmAiImport() {
|
||||||
|
|
@ -4185,7 +4175,8 @@ function MainApp({ username, onLogout }) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button className="btn btn-primary" style={{ width: '100%', justifyContent: 'center', marginBottom: 8 }} onClick={startNewProduct}><Plus size={14} />新建产品档案</button>
|
<button className="btn btn-primary" style={{ width: '100%', justifyContent: 'center', marginBottom: 8 }} onClick={startNewProduct}><Plus size={14} />新建产品档案</button>
|
||||||
<button className="btn" style={{ width: '100%', justifyContent: 'center', marginBottom: 12 }} onClick={openAiImport}><Sparkles size={14} />AI导入(上传PDF/图片自动建档)</button>
|
<button className="btn" style={{ width: '100%', justifyContent: 'center', marginBottom: 8 }} onClick={openAiImport}><Sparkles size={14} />AI导入(上传PDF/图片自动建档)</button>
|
||||||
|
<BrochureBulkUpload products={products} setProducts={setProducts} onNotify={notify} />
|
||||||
<div className="panel">
|
<div className="panel">
|
||||||
<div className="panel-body">
|
<div className="panel-body">
|
||||||
{filteredProducts.length === 0 ? (
|
{filteredProducts.length === 0 ? (
|
||||||
|
|
@ -4216,6 +4207,8 @@ function MainApp({ username, onLogout }) {
|
||||||
exportLabels={productExportLabels} exportLoading={productExportLoading}
|
exportLabels={productExportLabels} exportLoading={productExportLoading}
|
||||||
onExportPdf={handleExportProductPdf} exportPdfBusy={productExportPdfBusy}
|
onExportPdf={handleExportProductPdf} exportPdfBusy={productExportPdfBusy}
|
||||||
backPanelTemplates={backPanelTemplates}
|
backPanelTemplates={backPanelTemplates}
|
||||||
|
onPatch={(patch) => setProducts(list => list.map(x => (x.id === selectedProduct.id ? { ...x, ...patch } : x)))}
|
||||||
|
onNotify={notify}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="panel"><div className="empty-state"><Package size={28} />选择左侧产品查看详情,或新建一个产品档案</div></div>
|
<div className="panel"><div className="empty-state"><Package size={28} />选择左侧产品查看详情,或新建一个产品档案</div></div>
|
||||||
|
|
@ -4880,15 +4873,6 @@ function MainApp({ username, onLogout }) {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
<label className={`precise-opt${aiImportPrecise ? ' on' : ''}`}>
|
|
||||||
<input type="checkbox" checked={aiImportPrecise} disabled={aiImportBusy} onChange={e => setAiImportPrecise(e.target.checked)} />
|
|
||||||
<span>
|
|
||||||
<b>精准导入(保留原版式)</b>
|
|
||||||
除了提取参数,还把原文件按原来的版式 1:1 还原成"原版彩页":文字、表格、图片位置和原文件完全一样,
|
|
||||||
导入后可以一键翻译成英语、俄语等其他语言(版式不变),也能下载或打印成 PDF。
|
|
||||||
适合 PDF 规格书、彩页图片(JPG / PNG)或 HTML;多页 PDF 或多张图片会合成一份多页彩页。
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
<label className="tax-add-category" style={{ display: 'block', cursor: aiImportBusy ? 'default' : 'pointer' }}>
|
<label className="tax-add-category" style={{ display: 'block', cursor: aiImportBusy ? 'default' : 'pointer' }}>
|
||||||
<input
|
<input
|
||||||
type="file" accept="application/pdf,image/*,.html,.htm,text/html" multiple style={{ display: 'none' }}
|
type="file" accept="application/pdf,image/*,.html,.htm,text/html" multiple style={{ display: 'none' }}
|
||||||
|
|
@ -4898,7 +4882,7 @@ function MainApp({ username, onLogout }) {
|
||||||
{aiImportBusy ? (
|
{aiImportBusy ? (
|
||||||
<>
|
<>
|
||||||
<div className="catalog-doc-spinner" style={{ margin: '0 auto 10px' }} />
|
<div className="catalog-doc-spinner" style={{ margin: '0 auto 10px' }} />
|
||||||
{aiImportPrecise ? '正在识别并还原原版版式,可能需要一两分钟…' : '正在识别中,视文件大小可能需要几十秒…'}
|
正在识别中,视文件大小可能需要几十秒…
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<><Plus size={14} style={{ verticalAlign: -2, marginRight: 4 }} />点击选择PDF、图片或HTML(可多选)</>
|
<><Plus size={14} style={{ verticalAlign: -2, marginRight: 4 }} />点击选择PDF、图片或HTML(可多选)</>
|
||||||
|
|
@ -4912,15 +4896,6 @@ function MainApp({ username, onLogout }) {
|
||||||
识别出 {aiImportDrafts.length} 个产品,请检查型号/品牌/大类/细分品类,勾掉不需要导入的行,确认后点"确认导入"。
|
识别出 {aiImportDrafts.length} 个产品,请检查型号/品牌/大类/细分品类,勾掉不需要导入的行,确认后点"确认导入"。
|
||||||
其余规格字段(功率/电压/输出口/电池/尺寸等)已经一并识别好,导入后可以在产品详情里继续核对修改。
|
其余规格字段(功率/电压/输出口/电池/尺寸等)已经一并识别好,导入后可以在产品详情里继续核对修改。
|
||||||
</div>
|
</div>
|
||||||
{aiImportPreciseInfo && (aiImportPreciseInfo.doc ? (
|
|
||||||
<div className="disclaimer" style={{ background: '#E8F5EF', marginTop: -6 }}>
|
|
||||||
✓ 原版彩页已生成({aiImportPreciseInfo.doc.pages} 页),正在后台自动翻译成英语、俄语、西班牙语(每种约 1 分钟)。导入后在产品详情的"原版彩页"里切换语言查看、下载。
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="disclaimer" style={{ background: '#FDECEC', color: 'var(--led-red)', marginTop: -6 }}>
|
|
||||||
原版彩页没有生成成功:{aiImportPreciseInfo.error || '未知原因'}。参数提取不受影响,可以照常导入。
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
{aiImportTruncatedWarning && (
|
{aiImportTruncatedWarning && (
|
||||||
<div className="disclaimer" style={{ background: '#FDECEC', color: 'var(--led-red)', marginTop: -6 }}>
|
<div className="disclaimer" style={{ background: '#FDECEC', color: 'var(--led-red)', marginTop: -6 }}>
|
||||||
⚠️ AI这次输出的内容超出了长度限制,可能还有没识别完的产品被截断丢弃了。建议核对一下上面这 {aiImportDrafts.length} 个是不是齐了,
|
⚠️ AI这次输出的内容超出了长度限制,可能还有没识别完的产品被截断丢弃了。建议核对一下上面这 {aiImportDrafts.length} 个是不是齐了,
|
||||||
|
|
@ -9212,80 +9187,123 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 精准导入生成的"原版彩页":按原文件版式显示,可以切换语言(没翻译过的语言点一下 AI 翻译),下载 HTML 或打印成 PDF
|
// 多语言原版彩页:每种语言一份文件(HTML / PDF / 图片),手动上传;以后网站模板按语言取用
|
||||||
function PreciseDocPanel({ docId, productName }) {
|
const BROCHURE_LANGS = [
|
||||||
const [info, setInfo] = useState(null);
|
{ code: 'zh', label: '中文(原版)' }, { code: 'en', label: 'English' }, { code: 'ru', label: 'Русский' },
|
||||||
const [err, setErr] = useState('');
|
{ code: 'es', label: 'Español' }, { code: 'fr', label: 'Français' }, { code: 'ar', label: 'العربية' },
|
||||||
const [lang, setLang] = useState('');
|
];
|
||||||
|
function productBrochures(p) {
|
||||||
|
const b = { ...(p.brochures || {}) };
|
||||||
|
if (!b.zh && p.brochureFileName) b.zh = { fileName: p.brochureFileName, originalName: p.brochureOriginalName || p.brochureFileName, legacy: true };
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
// 文件名 → [型号, 语言]:SK100-12v_en.html、SK100-12v_ru.pdf、SK100-12v zh.html
|
||||||
|
function parseBrochureName(name) {
|
||||||
|
const base = String(name || '').replace(/\.[a-z0-9]+$/i, '').trim();
|
||||||
|
const m = base.match(/^(.+?)[_\s]+(zh|cn|en|ru|es|fr|ar)$/i);
|
||||||
|
if (!m) return null;
|
||||||
|
return { model: m[1].trim(), lang: m[2].toLowerCase() === 'cn' ? 'zh' : m[2].toLowerCase() };
|
||||||
|
}
|
||||||
|
const normModel = (s) => String(s || '').toLowerCase().replace(/[\s_]+/g, '');
|
||||||
|
|
||||||
|
function BrochurePanel({ product: p, onPatch, onNotify }) {
|
||||||
|
const all = productBrochures(p);
|
||||||
|
const first = BROCHURE_LANGS.find(l => all[l.code]);
|
||||||
|
const [lang, setLang] = useState(first ? first.code : 'zh');
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
const [ver, setVer] = useState(0);
|
useEffect(() => { const f = BROCHURE_LANGS.find(l => productBrochures(p)[l.code]); setLang(f ? f.code : 'zh'); }, [p.id]);
|
||||||
useEffect(() => {
|
const cur = all[lang];
|
||||||
let alive = true;
|
const url = cur ? `/uploads/${p.id}/${cur.fileName}` : '';
|
||||||
setInfo(null); setErr(''); setLang('');
|
const isImg = cur && /\.(png|jpe?g|webp|gif)$/i.test(cur.fileName);
|
||||||
getPreciseDoc(docId).then(d => { if (alive) { setInfo(d); setLang(d.srcLang); } }).catch(e => alive && setErr(e.message));
|
async function pick(file) {
|
||||||
return () => { alive = false; };
|
if (!file) return;
|
||||||
}, [docId]);
|
|
||||||
// 导入后正在后台自动翻译(英 / 俄 / 西):每 8 秒刷新一次,翻完一种就能看一种
|
|
||||||
const pendingKey = info && info.pending ? info.pending.join(',') : '';
|
|
||||||
useEffect(() => {
|
|
||||||
if (!pendingKey) return;
|
|
||||||
const t = setInterval(() => {
|
|
||||||
getPreciseDoc(docId).then(d => setInfo(d)).catch(() => {});
|
|
||||||
}, 8000);
|
|
||||||
return () => clearInterval(t);
|
|
||||||
}, [docId, pendingKey]);
|
|
||||||
if (err) return <div className="panel section-gap"><div className="panel-body" style={{ padding: 18, color: 'var(--led-red)', fontSize: 12.5 }}>原版彩页读取失败:{err}</div></div>;
|
|
||||||
if (!info) return null;
|
|
||||||
const isSrc = lang === info.srcLang;
|
|
||||||
const done = isSrc || !!(info.langs && info.langs[lang] > 0);
|
|
||||||
const pending = (info.pending || []).includes(lang);
|
|
||||||
const url = (extra = '') => `/api/precise/${encodeURIComponent(docId)}/html?lang=${lang}${extra}&v=${ver}`;
|
|
||||||
async function doTranslate() {
|
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
try {
|
try {
|
||||||
await translatePreciseDoc(docId, lang, done); // 已经有译文时点"重新翻译":全部重译
|
const res = await uploadFile(p.id, file);
|
||||||
setInfo(await getPreciseDoc(docId));
|
const old = all[lang];
|
||||||
setVer(v => v + 1);
|
const brochures = { ...(p.brochures || {}), [lang]: { fileName: res.fileName, originalName: res.originalName, uploadedAt: new Date().toISOString() } };
|
||||||
} catch (e) { window.alert(e.message); } finally { setBusy(false); }
|
const patch = { brochures };
|
||||||
|
if (old && old.legacy) { patch.brochureFileName = ''; patch.brochureOriginalName = ''; }
|
||||||
|
onPatch(patch);
|
||||||
|
if (old) { try { await deleteFile(p.id, old.fileName); } catch (e) {} }
|
||||||
|
onNotify && onNotify('彩页已上传');
|
||||||
|
} catch (e) { onNotify && onNotify(e.message || '上传失败'); } finally { setBusy(false); }
|
||||||
|
}
|
||||||
|
async function remove() {
|
||||||
|
if (!cur || !window.confirm(`删除${(BROCHURE_LANGS.find(l => l.code === lang) || {}).label}彩页?`)) return;
|
||||||
|
try { await deleteFile(p.id, cur.fileName); } catch (e) {}
|
||||||
|
const brochures = { ...(p.brochures || {}) }; delete brochures[lang];
|
||||||
|
onPatch(cur.legacy ? { brochures, brochureFileName: '', brochureOriginalName: '' } : { brochures });
|
||||||
}
|
}
|
||||||
const langLabel = (EXPORT_LANGUAGES.find(l => l.code === lang) || {}).label || lang;
|
|
||||||
return (
|
return (
|
||||||
<div className="panel section-gap">
|
<div className="panel section-gap">
|
||||||
<div className="panel-header">
|
<div className="panel-header"><div className="panel-title"><FileText size={15} />原版彩页(多语言)</div></div>
|
||||||
<div className="panel-title"><FileText size={15} />原版彩页(精准导入 · {info.pages} 页)</div>
|
|
||||||
</div>
|
|
||||||
<div className="panel-body" style={{ padding: 18 }}>
|
<div className="panel-body" style={{ padding: 18 }}>
|
||||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center', marginBottom: 12 }}>
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginBottom: 12 }}>
|
||||||
<select className="select" style={{ width: 'auto' }} value={lang} onChange={e => setLang(e.target.value)}>
|
{BROCHURE_LANGS.map(l => (
|
||||||
{[{ code: 'zh', label: '中文' }, ...EXPORT_LANGUAGES.filter(l => l.code !== 'zh')].map(l => (
|
<button key={l.code} type="button" className={`btn btn-sm${lang === l.code ? ' btn-primary' : ''}`} onClick={() => setLang(l.code)}>
|
||||||
<option key={l.code} value={l.code}>
|
{all[l.code] ? '✓ ' : ''}{l.label}
|
||||||
{l.label}{l.code === info.srcLang ? '(原文)' : info.langs && info.langs[l.code] ? '(已翻译)' : (info.pending || []).includes(l.code) ? '(自动翻译中…)' : ''}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
{!isSrc && (
|
|
||||||
<button className={`btn btn-sm${done ? '' : ' btn-primary'}`} disabled={busy || pending} onClick={doTranslate}>
|
|
||||||
<Sparkles size={12} />{busy ? 'AI 翻译中…' : done ? '重新翻译' : `AI 翻译成${langLabel}`}
|
|
||||||
</button>
|
</button>
|
||||||
)}
|
))}
|
||||||
{done && <a className="btn btn-sm" href={url()} target="_blank" rel="noreferrer"><Eye size={12} />新窗口打开</a>}
|
|
||||||
{done && <a className="btn btn-sm" href={url('&print=1')} target="_blank" rel="noreferrer"><Printer size={12} />打印 / 另存为PDF</a>}
|
|
||||||
{done && <a className="btn btn-sm" href={url(`&download=1&name=${encodeURIComponent(productName || '')}`)}><Download size={12} />下载HTML</a>}
|
|
||||||
</div>
|
</div>
|
||||||
{done ? (
|
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center', marginBottom: 12 }}>
|
||||||
<iframe title="原版彩页" src={url()} className="precise-frame" />
|
<label className="btn btn-sm" style={{ cursor: busy ? 'default' : 'pointer' }}>
|
||||||
) : (
|
<Upload size={12} />{busy ? '上传中…' : cur ? '替换' : '上传'}
|
||||||
<div className="empty-state" style={{ padding: 30 }}>{busy || pending ? `AI 正在翻译${langLabel}版,版式不变,只替换文字…(导入后会自动翻译英语、俄语、西班牙语)` : info.failed && info.failed[lang] ? `${langLabel}版自动翻译失败(${info.failed[lang]}),点上面的按钮重试。` : `还没有${langLabel}版,点上面的按钮翻译(正文和图表里的文字都会翻译,版式不变)。`}</div>
|
<input type="file" accept=".html,.htm,text/html,application/pdf,image/*" style={{ display: 'none' }} disabled={busy} onChange={e => { pick(e.target.files && e.target.files[0]); e.target.value = ''; }} />
|
||||||
)}
|
</label>
|
||||||
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginTop: 8 }}>
|
{cur && <a className="btn btn-sm" href={url} target="_blank" rel="noreferrer"><Eye size={12} />新窗口打开 / 打印</a>}
|
||||||
打印时在打印窗口里选"另存为 PDF",页面大小和原文件一致;产品照片上印的文字属于照片本身,不会翻译。
|
{cur && <a className="btn btn-sm" href={url} download={cur.originalName}><Download size={12} />下载</a>}
|
||||||
|
{cur && <button className="btn btn-sm btn-ghost btn-danger" onClick={remove}><Trash2 size={12} /></button>}
|
||||||
|
{cur && <span style={{ fontSize: 12, color: 'var(--ink-soft)', wordBreak: 'break-all' }}>{cur.originalName}</span>}
|
||||||
</div>
|
</div>
|
||||||
|
{cur ? (isImg
|
||||||
|
? <img src={url} alt="" style={{ maxWidth: '100%', border: '1px solid var(--line, #ddd)', borderRadius: 8 }} />
|
||||||
|
: <iframe title="原版彩页" src={url} className="brochure-frame" />)
|
||||||
|
: <div className="empty-state" style={{ padding: 30 }}>还没有这种语言的彩页,点"上传"选择文件(HTML、PDF 或图片)。</div>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ProductDetail({ product: p, onEdit, onDelete, categories, exportLang, onExportLangChange, exportLabels, exportLoading, onExportPdf, exportPdfBusy, backPanelTemplates }) {
|
// 批量上传:文件名写成"型号_语言.html"(如 SK100-12v_en.html、SK100-12v_ru.html),自动放进对应型号的对应语言
|
||||||
|
function BrochureBulkUpload({ products, setProducts, onNotify }) {
|
||||||
|
const [busy, setBusy] = useState('');
|
||||||
|
async function run(files) {
|
||||||
|
files = Array.from(files || []);
|
||||||
|
if (!files.length) return;
|
||||||
|
const ok = [], skip = [];
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const f = files[i];
|
||||||
|
const info = parseBrochureName(f.name);
|
||||||
|
const prod = info && products.find(p => normModel(p.name) === normModel(info.model));
|
||||||
|
if (!prod) { skip.push(f.name); continue; }
|
||||||
|
setBusy(`${i + 1}/${files.length}`);
|
||||||
|
try {
|
||||||
|
const res = await uploadFile(prod.id, f);
|
||||||
|
let old = null;
|
||||||
|
setProducts(list => list.map(x => {
|
||||||
|
if (x.id !== prod.id) return x;
|
||||||
|
old = productBrochures(x)[info.lang] || null;
|
||||||
|
const patch = { brochures: { ...(x.brochures || {}), [info.lang]: { fileName: res.fileName, originalName: res.originalName, uploadedAt: new Date().toISOString() } } };
|
||||||
|
if (old && old.legacy) { patch.brochureFileName = ''; patch.brochureOriginalName = ''; }
|
||||||
|
return { ...x, ...patch };
|
||||||
|
}));
|
||||||
|
if (old) { try { await deleteFile(prod.id, old.fileName); } catch (e) {} }
|
||||||
|
ok.push(f.name);
|
||||||
|
} catch (e) { skip.push(`${f.name}(${e.message})`); }
|
||||||
|
}
|
||||||
|
setBusy('');
|
||||||
|
window.alert(`已上传 ${ok.length} 个彩页` + (skip.length ? `\n\n没有上传(文件名对不上型号或上传失败):\n${skip.join('\n')}\n\n文件名格式:型号_语言.html,语言用 zh / en / ru / es / fr / ar,型号要和产品档案里的完全一致。` : ''));
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<label className="btn" style={{ width: '100%', justifyContent: 'center', marginBottom: 12, cursor: busy ? 'default' : 'pointer' }}>
|
||||||
|
<FileText size={14} />{busy ? `正在上传彩页 ${busy}…` : '批量上传多语言彩页(型号_语言.html)'}
|
||||||
|
<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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProductDetail({ product: p, onEdit, onDelete, categories, exportLang, onExportLangChange, exportLabels, exportLoading, onExportPdf, exportPdfBusy, backPanelTemplates, onPatch, onNotify }) {
|
||||||
const cat = (categories || []).find(c => c.id === p.category);
|
const cat = (categories || []).find(c => c.id === p.category);
|
||||||
const showMachineVariant = isUpsCategory(cat) && p.machineVariant;
|
const showMachineVariant = isUpsCategory(cat) && p.machineVariant;
|
||||||
const L = (key) => (exportLabels && exportLabels[key]) || key;
|
const L = (key) => (exportLabels && exportLabels[key]) || key;
|
||||||
|
|
@ -9321,22 +9339,11 @@ function ProductDetail({ product: p, onEdit, onDelete, categories, exportLang, o
|
||||||
<BackPanelReadOnly template={backPanelTemplate} />
|
<BackPanelReadOnly template={backPanelTemplate} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{p.brochureFileName && (
|
|
||||||
<div className="field">
|
|
||||||
<span className="field-label">原版彩页</span>
|
|
||||||
<a
|
|
||||||
href={`/uploads/${p.id}/${p.brochureFileName}`} target="_blank" rel="noreferrer" download={p.brochureOriginalName}
|
|
||||||
className="btn btn-sm" style={{ display: 'inline-flex' }}
|
|
||||||
>
|
|
||||||
<FileText size={12} />{p.brochureOriginalName || '下载原版彩页'}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{p.notes && <div className="field"><span className="field-label">备注</span><div style={{ fontSize: 12.5, whiteSpace: 'pre-wrap' }}>{p.notes}</div></div>}
|
{p.notes && <div className="field"><span className="field-label">备注</span><div style={{ fontSize: 12.5, whiteSpace: 'pre-wrap' }}>{p.notes}</div></div>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{p.preciseDocId && <PreciseDocPanel docId={p.preciseDocId} productName={p.name} />}
|
<BrochurePanel product={p} onPatch={onPatch} onNotify={onNotify} />
|
||||||
|
|
||||||
<div className="panel section-gap">
|
<div className="panel section-gap">
|
||||||
<div className="panel-header"><div className="panel-title"><Globe size={15} />多语言PDF资料导出</div></div>
|
<div className="panel-header"><div className="panel-title"><Globe size={15} />多语言PDF资料导出</div></div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue