Update public-api.js via upload script - 2026-10-31 00:13:56

This commit is contained in:
mike 2026-10-31 00:14:02 +08:00
parent 8e122d3374
commit ee8731c4b2
1 changed files with 11 additions and 5 deletions

View File

@ -228,6 +228,9 @@ function htmlSegments(h) {
return out; return out;
} }
const tplHtmlOf = (t) => (t && String(t.html || '').trim() ? cleanTplHtml(t.html) : ''); 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 = 最上面) // 详情图片里的 HTML 片段(原样显示,网站上放在隔离的 iframe 里):detailHtml = [{ id, html, pos }],pos = 排在第几张图后面(0 = 最上面)
const tplDetailBlocks = (t) => arr(t && t.detailHtml).filter((b) => b && String(b.html || '').trim()); const tplDetailBlocks = (t) => arr(t && t.detailHtml).filter((b) => b && String(b.html || '').trim());
// 同一模板下给某个型号去掉部分内容:modelExclude = { 产品id: { images: [文件名], blocks: [片段id], html: true } };没设置 = 全部都用 // 同一模板下给某个型号去掉部分内容: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)); 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 ex = arr(exclOf(t, p).blocks); return tplDetailBlocks(t).filter((b) => !ex.includes(b.id));
}; };
const tplHtmlFor = (t, p) => { // 某个型号用哪几段 HTML 内容:modelPick.htmls = [id](只用选中的);旧数据 html:true/false = 全部 / 不用;没设置 = 全部
const pk = pickOf(t, p).html; const tplHtmlListFor = (t, p) => {
if (typeof pk === 'boolean') return pk ? tplHtmlOf(t) : ''; const all = tplHtmlsOf(t), pk = pickOf(t, p);
return exclOf(t, p).html ? '' : tplHtmlOf(t); 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 片段的顺序:片段位置按模板里的原始图片序号算,去掉的图片 / 片段跳过 // 详情图片 + HTML 片段的顺序:片段位置按模板里的原始图片序号算,去掉的图片 / 片段跳过
function tplDetailSeq(t, p) { function tplDetailSeq(t, p) {
@ -518,7 +524,7 @@ function toPublic(p, templates = [], packSpecs = []) {
: { html: { en: x.html } }))); : { html: { en: x.html } })));
} }
// 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; if (tplHtml.length) out.templateHtml = tplHtml;
return out; return out;
} }