新增首页封面轮播装修组件

This commit is contained in:
张锐 committed 2026-11-26 00:01:04 +08:00
1 parent 12979c9600
commit 8a93a95d42
3 files changed
+18 -4

No files matched your search

+7 -2
View File
@@ -39,6 +39,7 @@ type Section = {
title: string;
subtitle: string;
imageUrl: string;
imageUrls: string[];
buttonText: string;
buttonUrl: string;
sourceType: string;
@@ -121,6 +122,7 @@ function createSection(type: SectionType): Section {
? "Industrial products and project-proven solutions for global B2B customers."
: "",
imageUrl: "",
imageUrls: [],
buttonText: type === "HERO" ? "Explore Products" : "",
buttonUrl: type === "HERO" ? "/products" : "",
sourceType: type === "CONTENT" ? "CASE" : "",
@@ -507,8 +509,8 @@ function PreviewSection({
className="pv-hero"
style={{
...style,
backgroundImage: item.imageUrl
? `linear-gradient(90deg,rgba(0,0,0,.65),rgba(0,0,0,.1)),url(${item.imageUrl})`
backgroundImage: (item.imageUrls?.[0] || item.imageUrl)
? `linear-gradient(90deg,rgba(0,0,0,.65),rgba(0,0,0,.1)),url(${item.imageUrls?.[0] || item.imageUrl})`
: undefined,
}}
onClick={onSelect}
@@ -723,6 +725,9 @@ function SectionSettings({
onChange={(e) => onChange({ imageUrl: e.target.value })}
/>
</Field>
<Field label="轮播图片 URL(每行一张)">
<textarea rows={4} value={(item.imageUrls || []).join("\n")} onChange={(e) => onChange({ imageUrls: e.target.value.split(/\r?\n/).map((value) => value.trim()).filter(Boolean) })} placeholder="https://..." />
</Field>
<Field label="按钮文案">
<input
value={item.buttonText}
+10 -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; 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[]; buttonText:string; buttonUrl:string; sourceType:string; limit:number; visible:boolean; background:string; textColor:string; showProductInformation?:boolean; productInformationTitle?:string; productInformationLimit?:number };
type ProductDetailConfiguration = {
/** 是否在商品摘要区域展示产品信息。 */
showProductInformation?: boolean;
@@ -323,7 +323,7 @@ function LiveSection({section}:{section:DecorationSection}) {
const style={background:section.background,color:section.textColor};
if(section.type==="ANNOUNCEMENT")return <div className="live-announcement" style={style}>{section.title}</div>;
if(section.type==="HEADER")return <LiveHeader style={style}/>;
if(section.type==="HERO")return <section className="live-hero" style={{...style,backgroundImage:section.imageUrl?`linear-gradient(90deg,rgba(0,0,0,.72),rgba(0,0,0,.12)),url(${section.imageUrl})`:undefined}}><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></section>;
if(section.type==="HERO")return <LiveHero section={section} style={style}/>;
if(section.type==="RICH_TEXT")return <section className="live-rich" style={style}><h2>{section.title}</h2><p>{section.subtitle}</p></section>;
if(section.type==="PRODUCT_DETAIL")return <RuntimeProductDetail configuration={section}/>;
if(section.type==="PRODUCTS"||section.type==="CONTENT")return <LiveCollection section={section}/>;
@@ -331,6 +331,14 @@ function LiveSection({section}:{section:DecorationSection}) {
if(section.type==="FOOTER")return <footer className="live-footer" style={style}><div><b>SHOPLIX</b><p>Industrial Solutions</p></div><div><b>Explore</b><a href="/products">Products</a><a href="/cases">Cases</a><a href="/news">News</a></div><div><b>Company</b><a href="/about-us">About Us</a><a href="/contact-us">Contact Us</a><a href="/privacy-policy">Privacy Policy</a></div><small>{section.subtitle||"Copyright © 2026. All rights reserved."}</small></footer>;
return null;
}
/** 首页首屏轮播组件,支持自动播放、左右切换和指示点。 */
function LiveHero({ section, style }: { section: DecorationSection; style: React.CSSProperties }) {
const images = section.imageUrls?.length ? section.imageUrls : section.imageUrl ? [section.imageUrl] : [];
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>;
}
/** 装修模板中的产品详情组件,按当前访问路径加载真实商品。 */
function RuntimeProductDetail({ configuration }: { configuration: ProductDetailConfiguration }) {
const slug = route().slug;
+1
View File
@@ -297,6 +297,7 @@ nav a:hover {
font-size: 17px;
margin-top: 35px;
}
.live-hero{position:relative;overflow:hidden}.live-hero .hero-arrow{position:absolute;z-index:2;top:50%;transform:translateY(-50%);width:44px;height:72px;border:0;background:#101a2555;color:#fff;font-size:42px;line-height:1;cursor:pointer}.live-hero .hero-arrow:disabled{opacity:0}.hero-arrow-prev{left:18px}.hero-arrow-next{right:18px}.hero-dots{position:absolute;z-index:2;left:50%;bottom:28px;transform:translateX(-50%);display:flex;gap:8px}.hero-dots button{width:9px;height:9px;padding:0;border:1px solid #fff;background:#ffffff66;border-radius:50%;cursor:pointer}.hero-dots button.active{background:#fff}
.content h2 {
font:
500 30px Georgia,