支持内容素材选择和轮播高度配置

This commit is contained in:
张锐 committed 2026-11-26 08:15:38 +08:00
1 parent 7f4f62702a
commit 26406481e2
3 files changed
+187 -13

No files matched your search

+2 -2
View File
@@ -302,7 +302,7 @@ function CustomCodeRuntime() {
useEffect(() => { let nodes: HTMLElement[] = []; post("/custom-codes/list", { siteCode: "SIT0000000000001" }).then(data => { (data.items || []).forEach((item: { content: string; position: string }) => { const container = item.position === "HEAD" ? document.head : document.body; const wrapper = document.createElement("div"); wrapper.innerHTML = item.content; Array.from(wrapper.children).forEach(child => { let node: HTMLElement = child as HTMLElement; if (child.tagName === "SCRIPT") { const script = document.createElement("script"); Array.from(child.attributes).forEach(attribute => script.setAttribute(attribute.name, attribute.value)); script.text = child.textContent || ""; node = script; } container.insertBefore(node, item.position === "BODY_START" ? container.firstChild : null); nodes.push(node); }); }); }).catch(() => undefined); return () => nodes.forEach(node => node.remove()); }, []);
return null;
}
type DecorationSection = { id:string; type:string; title:string; subtitle:string; imageUrl:string; imageUrls?:string[]; buttonText:string; buttonUrl:string; sourceType:string; limit:number; visible:boolean; background:string; textColor:string; showProductInformation?:boolean; productInformationTitle?:string; productInformationLimit?:number };
type DecorationSection = { id:string; type:string; title:string; subtitle:string; imageUrl:string; imageUrls?:string[]; heroHeight?:"30"|"50"|"80"|"100"; buttonText:string; buttonUrl:string; sourceType:string; limit:number; visible:boolean; background:string; textColor:string; showProductInformation?:boolean; productInformationTitle?:string; productInformationLimit?:number };
type ProductDetailConfiguration = {
/** 是否在商品摘要区域展示产品信息。 */
showProductInformation?: boolean;
@@ -337,7 +337,7 @@ function LiveHero({ section, style }: { section: DecorationSection; style: React
const [index, setIndex] = useState(0);
useEffect(() => { if (images.length < 2) return; const timer = window.setInterval(() => setIndex((current) => (current + 1) % images.length), 5000); return () => window.clearInterval(timer); }, [images.length]);
const image = images[index] || "";
return <section className="live-hero" style={{...style,backgroundImage:image?`linear-gradient(90deg,rgba(0,0,0,.72),rgba(0,0,0,.12)),url(${image})`:undefined}}><button className="hero-arrow hero-arrow-prev" type="button" onClick={() => setIndex((index - 1 + images.length) % images.length)} aria-label="Previous slide" disabled={images.length < 2}>‹</button><div><p>ENGINEERED FOR INDUSTRY</p><h1>{section.title}</h1><span>{section.subtitle}</span>{section.buttonText&&<a href={section.buttonUrl||"#"}>{section.buttonText}<ArrowRight size={17}/></a>}</div><button className="hero-arrow hero-arrow-next" type="button" onClick={() => setIndex((index + 1) % images.length)} aria-label="Next slide" disabled={images.length < 2}>›</button>{images.length > 1 && <div className="hero-dots">{images.map((_, dot) => <button type="button" key={dot} className={dot === index ? "active" : ""} onClick={() => setIndex(dot)} aria-label={`Go to slide ${dot + 1}`} />)}</div>}</section>;
return <section className="live-hero" style={{...style,minHeight:`${section.heroHeight||"80"}vh`,backgroundImage:image?`linear-gradient(90deg,rgba(0,0,0,.72),rgba(0,0,0,.12)),url(${image})`:undefined}}><button className="hero-arrow hero-arrow-prev" type="button" onClick={() => setIndex((index - 1 + images.length) % images.length)} aria-label="Previous slide" disabled={images.length < 2}>‹</button><div><p>ENGINEERED FOR INDUSTRY</p><h1>{section.title}</h1><span>{section.subtitle}</span>{section.buttonText&&<a href={section.buttonUrl||"#"}>{section.buttonText}<ArrowRight size={17}/></a>}</div><button className="hero-arrow hero-arrow-next" type="button" onClick={() => setIndex((index + 1) % images.length)} aria-label="Next slide" disabled={images.length < 2}>›</button>{images.length > 1 && <div className="hero-dots">{images.map((_, dot) => <button type="button" key={dot} className={dot === index ? "active" : ""} onClick={() => setIndex(dot)} aria-label={`Go to slide ${dot + 1}`} />)}</div>}</section>;
}
/** 装修模板中的产品详情组件,按当前访问路径加载真实商品。 */
function RuntimeProductDetail({ configuration }: { configuration: ProductDetailConfiguration }) {