diff --git a/App.jsx b/App.jsx
index 38b79cf..514b518 100644
--- a/App.jsx
+++ b/App.jsx
@@ -1,7 +1,7 @@
-import React, { useState, useEffect, useMemo } from 'react';
+import React, { useState, useEffect, useMemo, useRef } from 'react';
import {
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,
Package, Layers, Zap, Tag, Inbox, Paperclip,
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 (
-
详情模板(公共图片组,显示在上面"产品详情图"的下方;点一下添加,再点一下移除)
+
详情模板(公共图片组或 HTML 参数表,显示在上面"产品详情图"的下方;点一下添加,再点一下移除)
{templates.length === 0 ? (
还没有模板。可以把公司介绍、工厂、认证、包装物流这类每个产品都要放的图片做成模板。
) : (
@@ -5959,8 +5959,8 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
const imgs = t.images || [];
return (
);
})}
@@ -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)));
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]);
setActiveId(t.id);
if (onCreated) onCreated(t.id);
@@ -6018,7 +6018,7 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
images.push(up.fileName);
} 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 => {
const i = list.findIndex(x => x.id === t.id);
const next = [...list];
@@ -6042,7 +6042,7 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
{templates.map(t => (
))}
@@ -6053,11 +6053,20 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
模板名称(只在后台显示,网站上不显示)
update(active.id, { name: e.target.value })} placeholder="如:公司实力 / 认证证书 / 包装物流" />
+
+ 模板内容:
+
+
+
+ {active.kind === 'html' ? (
+
update(active.id, patch)} products={products} onNotify={onNotify} />
+ ) : (
update(active.id, patch)}
onNotify={onNotify} field="images" max={WEB_MAX_TEMPLATE_IMAGES} tall
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
+ )}
{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}
@@ -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 (
+
+
+
粘贴 HTML 代码,或上传 .html 文件(网站上显示在详情图下方,标题为"Series specifications")
+
+ {preview && html.trim() && (
+
+ )}
+ {html.trim() && (
+
+
发布到网站时自动处理:
+ {info.styled &&
✓ 去掉原文件的颜色、字体等样式,统一用网站样式
}
+ {info.unsafe > 0 &&
✓ 清理 {info.unsafe} 处脚本 / 外部内容
}
+ {info.cites > 0 &&
✓ 去掉 {info.cites} 处"[cite]"引用标记
}
+
✓ 文字自动翻译成西语、俄语(型号、数值保持不变)
+ {info.tables > 0 && info.models.length > 0
+ ?
✓ 识别到型号列:{info.models.join('、')}(产品页上高亮当前型号)
+ :
! 没有识别到参数表(第一行应为型号行)。其他内容(标题、段落、列表)照常显示
}
+ {unmatched.length > 0 && info.models.length > 0 && (
+
! 这些产品在表格里找不到对应型号列,不会高亮:{unmatched.map(p => p.model || p.name).join('、')}
+ )}
+ {info.size > 200 * 1024 &&
! 内容较大({Math.round(info.size / 1024)}KB),建议只保留文字和表格
}
+
+ )}
+
+ );
+}
+
// 离线式 / 在线互动式 UPS:网站上只做询价(不填价格),改为配置默认插座
const isQuoteOnlyType = (t) => t === '离线式UPS' || t === '在线互动式UPS';
const WEB_SOCKET_TYPES = [