Update App.jsx via upload script - 2026-10-20 09:37:49
This commit is contained in:
parent
9b399603df
commit
3d1a4db16a
101
App.jsx
101
App.jsx
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { useState, useEffect, useMemo } from 'react';
|
import React, { useState, useEffect, useMemo, useRef } from 'react';
|
||||||
import {
|
import {
|
||||||
Search, Plus, X, Mail, Edit2, Trash2, Check, Clock,
|
Search, Plus, X, Mail, Edit2, Trash2, Check, Clock,
|
||||||
Settings as SettingsIcon, Copy, ChevronRight,
|
Settings as SettingsIcon, Copy, ChevronRight, Upload, Eye,
|
||||||
Building2, Globe, Phone, Save, RefreshCw, LayoutDashboard, Users,
|
Building2, Globe, Phone, Save, RefreshCw, LayoutDashboard, Users,
|
||||||
Package, Layers, Zap, Tag, Inbox, Paperclip,
|
Package, Layers, Zap, Tag, Inbox, Paperclip,
|
||||||
Menu, LogOut, GripVertical, BookOpen, FileText, FolderTree, Lock, Sparkles, Printer, Image as ImageIcon,
|
Menu, LogOut, GripVertical, BookOpen, FileText, FolderTree, Lock, Sparkles, Printer, Image as ImageIcon,
|
||||||
|
|
@ -5949,7 +5949,7 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<span className="field-label">详情模板(公共图片组,显示在上面"产品详情图"的下方;点一下添加,再点一下移除)</span>
|
<span className="field-label">详情模板(公共图片组或 HTML 参数表,显示在上面"产品详情图"的下方;点一下添加,再点一下移除)</span>
|
||||||
{templates.length === 0 ? (
|
{templates.length === 0 ? (
|
||||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>还没有模板。可以把公司介绍、工厂、认证、包装物流这类每个产品都要放的图片做成模板。</div>
|
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>还没有模板。可以把公司介绍、工厂、认证、包装物流这类每个产品都要放的图片做成模板。</div>
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -5959,8 +5959,8 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
|
||||||
const imgs = t.images || [];
|
const imgs = t.images || [];
|
||||||
return (
|
return (
|
||||||
<button type="button" key={t.id} onClick={() => toggle(t.id)} className={`tpl-chip${on ? ' on' : ''}`}>
|
<button type="button" key={t.id} onClick={() => toggle(t.id)} className={`tpl-chip${on ? ' on' : ''}`}>
|
||||||
{imgs[0] ? <img src={`/uploads/${t.id}/${imgs[0]}`} alt="" /> : <span className="tpl-chip-noimg"><ImageIcon size={14} /></span>}
|
{t.kind !== 'html' && imgs[0] ? <img src={`/uploads/${t.id}/${imgs[0]}`} alt="" /> : <span className="tpl-chip-noimg">{t.kind === 'html' ? <FileText size={14} /> : <ImageIcon size={14} />}</span>}
|
||||||
<span>{on ? '✓ ' : '+ '}{t.name || '未命名模板'}<em>{imgs.length}张</em></span>
|
<span>{on ? '✓ ' : '+ '}{t.name || '未命名模板'}<em>{t.kind === 'html' ? 'HTML' : `${imgs.length}张`}</em></span>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
@ -5995,7 +5995,7 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
|
||||||
const update = (id, patch) => setTemplates(list => list.map(t => (t.id === id ? { ...t, ...patch } : t)));
|
const update = (id, patch) => setTemplates(list => list.map(t => (t.id === id ? { ...t, ...patch } : t)));
|
||||||
|
|
||||||
function addTemplate() {
|
function addTemplate() {
|
||||||
const t = { id: newTemplateId(), name: `新模板 ${templates.length + 1}`, images: [] };
|
const t = { id: newTemplateId(), name: `新模板 ${templates.length + 1}`, kind: 'images', images: [] };
|
||||||
setTemplates(list => [...list, t]);
|
setTemplates(list => [...list, t]);
|
||||||
setActiveId(t.id);
|
setActiveId(t.id);
|
||||||
if (onCreated) onCreated(t.id);
|
if (onCreated) onCreated(t.id);
|
||||||
|
|
@ -6018,7 +6018,7 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
|
||||||
images.push(up.fileName);
|
images.push(up.fileName);
|
||||||
} catch (e) { failed++; }
|
} catch (e) { failed++; }
|
||||||
}
|
}
|
||||||
const copy = { id, name: `${t.name || '模板'} 副本`, images };
|
const copy = { id, name: `${t.name || '模板'} 副本`, kind: t.kind || 'images', images, html: t.html || '' };
|
||||||
setTemplates(list => {
|
setTemplates(list => {
|
||||||
const i = list.findIndex(x => x.id === t.id);
|
const i = list.findIndex(x => x.id === t.id);
|
||||||
const next = [...list];
|
const next = [...list];
|
||||||
|
|
@ -6042,7 +6042,7 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
|
||||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
|
||||||
{templates.map(t => (
|
{templates.map(t => (
|
||||||
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}`} onClick={() => setActiveId(t.id)}>
|
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}`} onClick={() => setActiveId(t.id)}>
|
||||||
{t.name || '未命名模板'}({(t.images || []).length})
|
{t.name || '未命名模板'}({t.kind === 'html' ? 'HTML' : (t.images || []).length})
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
<button type="button" className="btn btn-sm" onClick={addTemplate}><Plus size={12} />新建模板</button>
|
<button type="button" className="btn btn-sm" onClick={addTemplate}><Plus size={12} />新建模板</button>
|
||||||
|
|
@ -6053,11 +6053,20 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
|
||||||
<span className="field-label">模板名称(只在后台显示,网站上不显示)</span>
|
<span className="field-label">模板名称(只在后台显示,网站上不显示)</span>
|
||||||
<input className="input" value={active.name} onChange={e => update(active.id, { name: e.target.value })} placeholder="如:公司实力 / 认证证书 / 包装物流" />
|
<input className="input" value={active.name} onChange={e => update(active.id, { name: e.target.value })} placeholder="如:公司实力 / 认证证书 / 包装物流" />
|
||||||
</div>
|
</div>
|
||||||
|
<div style={{ display: 'flex', gap: 6, alignItems: 'center', margin: '4px 0 12px' }}>
|
||||||
|
<span className="field-label" style={{ margin: 0 }}>模板内容:</span>
|
||||||
|
<button type="button" className={`btn btn-sm${active.kind !== 'html' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'images' })}>图片</button>
|
||||||
|
<button type="button" className={`btn btn-sm${active.kind === 'html' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'html' })}>HTML 内容</button>
|
||||||
|
</div>
|
||||||
|
{active.kind === 'html' ? (
|
||||||
|
<HtmlTemplateEditor key={active.id} tpl={active} update={(patch) => update(active.id, patch)} products={products} onNotify={onNotify} />
|
||||||
|
) : (
|
||||||
<WebImageList
|
<WebImageList
|
||||||
draft={{ id: active.id, images: active.images || [] }}
|
draft={{ id: active.id, images: active.images || [] }}
|
||||||
set={(patch) => update(active.id, patch)}
|
set={(patch) => update(active.id, patch)}
|
||||||
onNotify={onNotify} field="images" max={WEB_MAX_TEMPLATE_IMAGES} tall
|
onNotify={onNotify} field="images" max={WEB_MAX_TEMPLATE_IMAGES} tall
|
||||||
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
|
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
|
||||||
|
)}
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 12.5, color: 'var(--ink-soft)' }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 12.5, color: 'var(--ink-soft)' }}>
|
||||||
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}</span>
|
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}</span>
|
||||||
<span style={{ display: 'flex', gap: 6 }}>
|
<span style={{ display: 'flex', gap: 6 }}>
|
||||||
|
|
@ -6087,6 +6096,82 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTML 详情模板:粘贴代码或上传 .html。网站发布时会去掉原样式、脚本等,只保留表格 / 标题 / 列表 / 文字,统一用网站样式;
|
||||||
|
// 表格第一行当作型号行,产品页上会高亮当前型号那一列;文字自动翻译成西语、俄语。
|
||||||
|
const tplSeriesKey = (m) => { const x = String(m || '').toUpperCase().replace(/\s+/g, '').match(/^([A-Z]+)-?(\d+(?:\.\d+)?)/); return x ? x[1] + x[2] : ''; };
|
||||||
|
function analyzeTplHtml(html) {
|
||||||
|
const r = { cites: (html.match(/\[cite:[^\]]*\]/gi) || []).length, unsafe: 0, styled: false, tables: 0, models: [], size: html.length };
|
||||||
|
if (!html.trim()) return r;
|
||||||
|
try {
|
||||||
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||||
|
r.unsafe = doc.querySelectorAll('script,iframe,object,embed,link[rel="stylesheet"]').length + doc.querySelectorAll('[onclick],[onload],[onerror]').length;
|
||||||
|
r.styled = !!doc.querySelector('style,[style],[class]');
|
||||||
|
const tables = doc.querySelectorAll('table');
|
||||||
|
r.tables = tables.length;
|
||||||
|
if (tables[0]) {
|
||||||
|
const row = tables[0].querySelector('tr');
|
||||||
|
if (row) {
|
||||||
|
const cells = [...row.children];
|
||||||
|
const lead = cells[0] ? Math.max(1, Number(cells[0].getAttribute('colspan')) || 1) : 1;
|
||||||
|
r.models = cells.slice(1).map(c => c.textContent.trim()).filter(Boolean);
|
||||||
|
r.lead = lead;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
function HtmlTemplateEditor({ tpl, update, products, onNotify }) {
|
||||||
|
const html = tpl.html || '';
|
||||||
|
const [preview, setPreview] = useState(false);
|
||||||
|
const fileRef = useRef(null);
|
||||||
|
const info = useMemo(() => analyzeTplHtml(html), [html]);
|
||||||
|
const users = products.filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id));
|
||||||
|
const modelKeys = info.models.map(tplSeriesKey);
|
||||||
|
const unmatched = users.filter(p => !modelKeys.includes(tplSeriesKey(p.model || p.name)));
|
||||||
|
async function onFile(e) {
|
||||||
|
const f = e.target.files && e.target.files[0];
|
||||||
|
e.target.value = '';
|
||||||
|
if (!f) return;
|
||||||
|
if (f.size > 500 * 1024) { onNotify && onNotify('文件太大(超过500KB),HTML 模板一般只放文字和表格'); return; }
|
||||||
|
update({ html: await f.text() });
|
||||||
|
onNotify && onNotify(`已读取 ${f.name}`);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="field">
|
||||||
|
<span className="field-label">粘贴 HTML 代码,或上传 .html 文件(网站上显示在详情图下方,标题为"Series specifications")</span>
|
||||||
|
<textarea className="input" value={html} onChange={e => update({ html: e.target.value })} spellCheck={false}
|
||||||
|
placeholder="<table> … </table>" style={{ height: 220, fontFamily: 'ui-monospace, Menlo, Consolas, monospace', fontSize: 12, lineHeight: 1.45 }} />
|
||||||
|
<div style={{ display: 'flex', gap: 8, marginTop: 8, flexWrap: 'wrap' }}>
|
||||||
|
<button type="button" className="btn btn-sm" onClick={() => fileRef.current && fileRef.current.click()}><Upload size={12} />上传 .html</button>
|
||||||
|
<input ref={fileRef} type="file" accept=".html,.htm,text/html" style={{ display: 'none' }} onChange={onFile} />
|
||||||
|
<button type="button" className="btn btn-sm" disabled={!html.trim()} onClick={() => setPreview(v => !v)}><Eye size={12} />{preview ? '关闭预览' : '原文件预览'}</button>
|
||||||
|
{html && <button type="button" className="btn btn-sm btn-ghost" onClick={() => { if (window.confirm('清空这个模板的 HTML?')) update({ html: '' }); }}><X size={12} />清空</button>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{preview && html.trim() && (
|
||||||
|
<iframe title="预览" sandbox="" srcDoc={html} style={{ width: '100%', height: 420, border: '1px solid var(--line)', borderRadius: 8, background: '#fff', marginBottom: 10 }} />
|
||||||
|
)}
|
||||||
|
{html.trim() && (
|
||||||
|
<div style={{ fontSize: 12.5, lineHeight: 1.8, background: 'var(--bg-soft, #f6f8fa)', borderRadius: 8, padding: '10px 12px', marginBottom: 10 }}>
|
||||||
|
<div style={{ fontWeight: 600, marginBottom: 2 }}>发布到网站时自动处理:</div>
|
||||||
|
{info.styled && <div>✓ 去掉原文件的颜色、字体等样式,统一用网站样式</div>}
|
||||||
|
{info.unsafe > 0 && <div>✓ 清理 {info.unsafe} 处脚本 / 外部内容</div>}
|
||||||
|
{info.cites > 0 && <div>✓ 去掉 {info.cites} 处"[cite]"引用标记</div>}
|
||||||
|
<div>✓ 文字自动翻译成西语、俄语(型号、数值保持不变)</div>
|
||||||
|
{info.tables > 0 && info.models.length > 0
|
||||||
|
? <div>✓ 识别到型号列:{info.models.join('、')}(产品页上高亮当前型号)</div>
|
||||||
|
: <div style={{ color: '#9a6700' }}>! 没有识别到参数表(第一行应为型号行)。其他内容(标题、段落、列表)照常显示</div>}
|
||||||
|
{unmatched.length > 0 && info.models.length > 0 && (
|
||||||
|
<div style={{ color: '#9a6700' }}>! 这些产品在表格里找不到对应型号列,不会高亮:{unmatched.map(p => p.model || p.name).join('、')}</div>
|
||||||
|
)}
|
||||||
|
{info.size > 200 * 1024 && <div style={{ color: '#9a6700' }}>! 内容较大({Math.round(info.size / 1024)}KB),建议只保留文字和表格</div>}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 离线式 / 在线互动式 UPS:网站上只做询价(不填价格),改为配置默认插座
|
// 离线式 / 在线互动式 UPS:网站上只做询价(不填价格),改为配置默认插座
|
||||||
const isQuoteOnlyType = (t) => t === '离线式UPS' || t === '在线互动式UPS';
|
const isQuoteOnlyType = (t) => t === '离线式UPS' || t === '在线互动式UPS';
|
||||||
const WEB_SOCKET_TYPES = [
|
const WEB_SOCKET_TYPES = [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue