From ee8731c4b2a961c4a50a30cd4a30eee8cf2b4454 Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 31 Oct 2026 00:14:02 +0800 Subject: [PATCH] Update public-api.js via upload script - 2026-10-31 00:13:56 --- public-api.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/public-api.js b/public-api.js index 1ab7e6e..746cc4e 100644 --- a/public-api.js +++ b/public-api.js @@ -228,6 +228,9 @@ function htmlSegments(h) { return out; } const tplHtmlOf = (t) => (t && String(t.html || '').trim() ? cleanTplHtml(t.html) : ''); +// HTML 内容可以有多段:htmls = [{ id, name, html }];旧数据只有一段 html,当作 id 为 h_main 的一段 +const tplHtmlsOf = (t) => (!t ? [] : Array.isArray(t.htmls) ? t.htmls : String(t.html || '').trim() ? [{ id: 'h_main', html: t.html }] : []) + .filter((h) => h && String(h.html || '').trim()); // 详情图片里的 HTML 片段(原样显示,网站上放在隔离的 iframe 里):detailHtml = [{ id, html, pos }],pos = 排在第几张图后面(0 = 最上面) const tplDetailBlocks = (t) => arr(t && t.detailHtml).filter((b) => b && String(b.html || '').trim()); // 同一模板下给某个型号去掉部分内容:modelExclude = { 产品id: { images: [文件名], blocks: [片段id], html: true } };没设置 = 全部都用 @@ -245,10 +248,13 @@ const tplBlocksFor = (t, p) => { if (Array.isArray(pk)) return tplDetailBlocks(t).filter((b) => pk.includes(b.id)); const ex = arr(exclOf(t, p).blocks); return tplDetailBlocks(t).filter((b) => !ex.includes(b.id)); }; -const tplHtmlFor = (t, p) => { - const pk = pickOf(t, p).html; - if (typeof pk === 'boolean') return pk ? tplHtmlOf(t) : ''; - return exclOf(t, p).html ? '' : tplHtmlOf(t); +// 某个型号用哪几段 HTML 内容:modelPick.htmls = [id](只用选中的);旧数据 html:true/false = 全部 / 不用;没设置 = 全部 +const tplHtmlListFor = (t, p) => { + const all = tplHtmlsOf(t), pk = pickOf(t, p); + let list = all; + if (Array.isArray(pk.htmls)) list = all.filter((h) => pk.htmls.includes(h.id)); + else if (pk.html === false || (pk.html !== true && exclOf(t, p).html)) list = []; + return list.map((h) => ({ id: h.id, html: cleanTplHtml(h.html) })).filter((h) => h.html); }; // 详情图片 + HTML 片段的顺序:片段位置按模板里的原始图片序号算,去掉的图片 / 片段跳过 function tplDetailSeq(t, p) { @@ -518,7 +524,7 @@ function toPublic(p, templates = [], packSpecs = []) { : { html: { en: x.html } }))); } // HTML 模板(系列参数表等):显示在详情图下方 - const tplHtml = templatesOf(p, templates).map((t) => ({ id: t.id, html: { en: tplHtmlFor(t, p) } })).filter((x) => x.html.en); + const tplHtml = templatesOf(p, templates).flatMap((t) => tplHtmlListFor(t, p).map((h) => ({ id: h.id === 'h_main' ? t.id : `${t.id}~${h.id}`, html: { en: h.html } }))); if (tplHtml.length) out.templateHtml = tplHtml; return out; }