Update App.jsx via upload script - 2026-11-09 15:04:23
This commit is contained in:
parent
aa2881c5d1
commit
21f3682864
101
App.jsx
101
App.jsx
|
|
@ -13,7 +13,7 @@ import {
|
|||
storageGet, storageSet, hasUnsavedChanges, saveTemplate, localPendingTemplates, uploadFile, deleteFile,
|
||||
authCheck, authLogin, authLogout, authChangePassword,
|
||||
getAiConfig, saveAiConfig, deleteAiConfig, testAiConfig,
|
||||
parseCatalogFiles, translateTerms,
|
||||
parseCatalogFiles, translateTerms, getPreciseDoc, translatePreciseDoc,
|
||||
} from './storage';
|
||||
|
||||
/* ----------------------------- constants ----------------------------- */
|
||||
|
|
@ -870,6 +870,7 @@ function upsertProductByName(list, product) {
|
|||
productImageOriginalName: existing.productImageOriginalName,
|
||||
brochureFileName: existing.brochureFileName,
|
||||
brochureOriginalName: existing.brochureOriginalName,
|
||||
preciseDocId: product.preciseDocId || existing.preciseDocId || '', // 这次没勾精准导入时,保留之前生成的原版彩页
|
||||
sellingPoints: existing.sellingPoints,
|
||||
costPrice: existing.costPrice,
|
||||
notes: existing.notes,
|
||||
|
|
@ -2193,6 +2194,11 @@ const Styles = () => (
|
|||
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; }
|
||||
.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) ---------- */
|
||||
.doc-preview {
|
||||
background: #fff; color: #2d2d2d; padding: 46px 52px; max-width: 840px; margin: 0 auto;
|
||||
|
|
@ -2556,6 +2562,8 @@ function MainApp({ username, onLogout }) {
|
|||
const [aiImportHintBrand, setAiImportHintBrand] = useState('');
|
||||
const [aiImportHintType, setAiImportHintType] = useState('');
|
||||
const [aiImportHintExtraTypes, setAiImportHintExtraTypes] = useState([]); // 这批产品同时属于的其他细分品类(多选)
|
||||
const [aiImportPrecise, setAiImportPrecise] = useState(false); // 精准导入:同时按原版式生成"原版彩页",之后可翻译
|
||||
const [aiImportPreciseInfo, setAiImportPreciseInfo] = useState(null); // { doc, error }
|
||||
const [aiImportTruncatedWarning, setAiImportTruncatedWarning] = useState(false);
|
||||
|
||||
const [exportOpen, setExportOpen] = useState(false);
|
||||
|
|
@ -3322,7 +3330,7 @@ function MainApp({ username, onLogout }) {
|
|||
function openAiImport() {
|
||||
setAiImportOpen(true); setAiImportDrafts(null); setAiImportError('');
|
||||
setAiImportHintCategory(''); setAiImportHintBrand(''); setAiImportHintType(''); setAiImportHintExtraTypes([]);
|
||||
setAiImportTruncatedWarning(false);
|
||||
setAiImportTruncatedWarning(false); setAiImportPreciseInfo(null);
|
||||
}
|
||||
function closeAiImport() { setAiImportOpen(false); setAiImportDrafts(null); setAiImportError(''); setAiImportBusy(false); }
|
||||
|
||||
|
|
@ -3335,8 +3343,10 @@ function MainApp({ username, onLogout }) {
|
|||
category: aiImportHintCategory.trim(),
|
||||
brand: aiImportHintBrand.trim(),
|
||||
type: aiImportHintType.trim(),
|
||||
precise: aiImportPrecise,
|
||||
});
|
||||
const parsed = (res && res.products) || [];
|
||||
setAiImportPreciseInfo(aiImportPrecise ? { doc: res && res.preciseDoc, error: (res && res.preciseError) || '' } : null);
|
||||
if (!parsed.length) { setAiImportError('没有从文件里识别出任何产品,换一份更清晰的文件试试'); return; }
|
||||
setAiImportTruncatedWarning(!!(res && res.truncated));
|
||||
const drafts = parsed.map((p, i) => ({
|
||||
|
|
@ -3396,6 +3406,7 @@ function MainApp({ username, onLogout }) {
|
|||
applicationScenarios: p.applicationScenarios || '',
|
||||
container20ft: p.container20ft || '', container40ft: p.container40ft || '', container40hq: p.container40hq || '',
|
||||
extraSpecs: Array.isArray(p.extraSpecs) ? p.extraSpecs.filter(x => x && x.label && x.value) : [],
|
||||
preciseDocId: p.preciseDocId || '',
|
||||
}));
|
||||
setAiImportDrafts(drafts);
|
||||
} catch (e) {
|
||||
|
|
@ -3486,6 +3497,7 @@ function MainApp({ username, onLogout }) {
|
|||
applicationScenarios: d.applicationScenarios || '',
|
||||
container20ft: d.container20ft || '', container40ft: d.container40ft || '', container40hq: d.container40hq || '',
|
||||
extraSpecs: Array.isArray(d.extraSpecs) ? d.extraSpecs.filter(x => x && x.label && x.value) : [],
|
||||
preciseDocId: d.preciseDocId || '',
|
||||
};
|
||||
}
|
||||
function confirmAiImport() {
|
||||
|
|
@ -4868,6 +4880,15 @@ function MainApp({ username, onLogout }) {
|
|||
</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' }}>
|
||||
<input
|
||||
type="file" accept="application/pdf,image/*,.html,.htm,text/html" multiple style={{ display: 'none' }}
|
||||
|
|
@ -4877,7 +4898,7 @@ function MainApp({ username, onLogout }) {
|
|||
{aiImportBusy ? (
|
||||
<>
|
||||
<div className="catalog-doc-spinner" style={{ margin: '0 auto 10px' }} />
|
||||
正在识别中,视文件大小可能需要几十秒…
|
||||
{aiImportPrecise ? '正在识别并还原原版版式,可能需要一两分钟…' : '正在识别中,视文件大小可能需要几十秒…'}
|
||||
</>
|
||||
) : (
|
||||
<><Plus size={14} style={{ verticalAlign: -2, marginRight: 4 }} />点击选择PDF、图片或HTML(可多选)</>
|
||||
|
|
@ -4891,6 +4912,15 @@ function MainApp({ username, onLogout }) {
|
|||
识别出 {aiImportDrafts.length} 个产品,请检查型号/品牌/大类/细分品类,勾掉不需要导入的行,确认后点"确认导入"。
|
||||
其余规格字段(功率/电压/输出口/电池/尺寸等)已经一并识别好,导入后可以在产品详情里继续核对修改。
|
||||
</div>
|
||||
{aiImportPreciseInfo && (aiImportPreciseInfo.doc ? (
|
||||
<div className="disclaimer" style={{ background: '#E8F5EF', marginTop: -6 }}>
|
||||
✓ 原版彩页已生成({aiImportPreciseInfo.doc.pages} 页),导入后在产品详情的"原版彩页"里查看、翻译和下载。
|
||||
</div>
|
||||
) : (
|
||||
<div className="disclaimer" style={{ background: '#FDECEC', color: 'var(--led-red)', marginTop: -6 }}>
|
||||
原版彩页没有生成成功:{aiImportPreciseInfo.error || '未知原因'}。参数提取不受影响,可以照常导入。
|
||||
</div>
|
||||
))}
|
||||
{aiImportTruncatedWarning && (
|
||||
<div className="disclaimer" style={{ background: '#FDECEC', color: 'var(--led-red)', marginTop: -6 }}>
|
||||
⚠️ AI这次输出的内容超出了长度限制,可能还有没识别完的产品被截断丢弃了。建议核对一下上面这 {aiImportDrafts.length} 个是不是齐了,
|
||||
|
|
@ -9182,6 +9212,69 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage,
|
|||
);
|
||||
}
|
||||
|
||||
// 精准导入生成的"原版彩页":按原文件版式显示,可以切换语言(没翻译过的语言点一下 AI 翻译),下载 HTML 或打印成 PDF
|
||||
function PreciseDocPanel({ docId, productName }) {
|
||||
const [info, setInfo] = useState(null);
|
||||
const [err, setErr] = useState('');
|
||||
const [lang, setLang] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [ver, setVer] = useState(0);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setInfo(null); setErr(''); setLang('');
|
||||
getPreciseDoc(docId).then(d => { if (alive) { setInfo(d); setLang(d.srcLang); } }).catch(e => alive && setErr(e.message));
|
||||
return () => { alive = false; };
|
||||
}, [docId]);
|
||||
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 url = (extra = '') => `/api/precise/${encodeURIComponent(docId)}/html?lang=${lang}${extra}&v=${ver}`;
|
||||
async function doTranslate() {
|
||||
setBusy(true);
|
||||
try {
|
||||
await translatePreciseDoc(docId, lang);
|
||||
setInfo(await getPreciseDoc(docId));
|
||||
setVer(v => v + 1);
|
||||
} catch (e) { window.alert(e.message); } finally { setBusy(false); }
|
||||
}
|
||||
const langLabel = (EXPORT_LANGUAGES.find(l => l.code === lang) || {}).label || lang;
|
||||
return (
|
||||
<div className="panel section-gap">
|
||||
<div className="panel-header">
|
||||
<div className="panel-title"><FileText size={15} />原版彩页(精准导入 · {info.pages} 页)</div>
|
||||
</div>
|
||||
<div className="panel-body" style={{ padding: 18 }}>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center', marginBottom: 12 }}>
|
||||
<select className="select" style={{ width: 'auto' }} value={lang} onChange={e => setLang(e.target.value)}>
|
||||
{[{ code: 'zh', label: '中文' }, ...EXPORT_LANGUAGES.filter(l => l.code !== 'zh')].map(l => (
|
||||
<option key={l.code} value={l.code}>
|
||||
{l.label}{l.code === info.srcLang ? '(原文)' : info.langs && info.langs[l.code] ? '(已翻译)' : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{!isSrc && (
|
||||
<button className={`btn btn-sm${done ? '' : ' btn-primary'}`} disabled={busy} onClick={doTranslate}>
|
||||
<Sparkles size={12} />{busy ? 'AI 翻译中…' : done ? '重新翻译' : `AI 翻译成${langLabel}`}
|
||||
</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>
|
||||
{done ? (
|
||||
<iframe title="原版彩页" src={url()} className="precise-frame" />
|
||||
) : (
|
||||
<div className="empty-state" style={{ padding: 30 }}>{busy ? 'AI 正在翻译,版式不变,只替换文字…' : `还没有${langLabel}版,点上面的按钮翻译(正文和图表里的文字都会翻译,版式不变)。`}</div>
|
||||
)}
|
||||
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginTop: 8 }}>
|
||||
打印时在打印窗口里选"另存为 PDF",页面大小和原文件一致;产品照片上印的文字属于照片本身,不会翻译。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProductDetail({ product: p, onEdit, onDelete, categories, exportLang, onExportLangChange, exportLabels, exportLoading, onExportPdf, exportPdfBusy, backPanelTemplates }) {
|
||||
const cat = (categories || []).find(c => c.id === p.category);
|
||||
const showMachineVariant = isUpsCategory(cat) && p.machineVariant;
|
||||
|
|
@ -9233,6 +9326,8 @@ function ProductDetail({ product: p, onEdit, onDelete, categories, exportLang, o
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{p.preciseDocId && <PreciseDocPanel docId={p.preciseDocId} productName={p.name} />}
|
||||
|
||||
<div className="panel section-gap">
|
||||
<div className="panel-header"><div className="panel-title"><Globe size={15} />多语言PDF资料导出</div></div>
|
||||
<div className="panel-body" style={{ padding: 18 }}>
|
||||
|
|
|
|||
Loading…
Reference in New Issue