账户登录

This commit is contained in:
张锐 committed 2026-11-23 11:09:03 +08:00
1 parent d8e17fce1d
commit 7dea19f2db
12 files changed
+331 -14

No files matched your search

+28 -6
View File
@@ -111,6 +111,26 @@ const nav = [
["Help", "/help"],
["About", "/about-us"],
];
type NavigationItem = { title: string; url: string; openType: "CURRENT" | "NEW"; children: NavigationItem[] };
/** 读取已发布导航,没有配置时返回既有默认菜单。 */
function useNavigation(position: "HEADER" | "FOOTER"): NavigationItem[] {
const fallback = nav.map(([title, url]) => ({ title, url, openType: "CURRENT" as const, children: [] }));
const [items, setItems] = useState<NavigationItem[]>(fallback);
useEffect(() => {
let active = true;
post("/navigations/detail", { position })
.then((data) => { if (active && data.items?.length) setItems(data.items); })
.catch(() => undefined);
return () => { active = false; };
}, [position]);
return items;
}
/** 渲染支持二级菜单的前台导航链接。 */
function NavigationLinks({ items }: { items: NavigationItem[] }) {
return <>{items.map((item) => <div className="site-nav-item" key={`${item.title}-${item.url}`}><a href={item.url} target={item.openType === "NEW" ? "_blank" : undefined} rel={item.openType === "NEW" ? "noreferrer" : undefined}>{item.title}</a>{item.children?.length > 0 && <div className="site-subnav">{item.children.map((child) => <a href={child.url} key={`${child.title}-${child.url}`} target={child.openType === "NEW" ? "_blank" : undefined} rel={child.openType === "NEW" ? "noreferrer" : undefined}>{child.title}</a>)}</div>}</div>)}</>;
}
function route() {
const p = location.pathname.split("/").filter(Boolean);
const previewPage = new URLSearchParams(location.search).get("previewPage") || undefined;
@@ -181,7 +201,7 @@ function DecoratedPage({ pageType, fallback }: { pageType: string; fallback: Rea
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 <header className="live-header" style={style}><a href="/" className="live-logo">SHOPLIX</a><nav>{nav.map(([name,url])=><a key={url} href={url}>{name}</a>)}</nav><a className="live-quote" href="/contact-us">Get a quote</a></header>;
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==="RICH_TEXT")return <section className="live-rich" style={style}><h2>{section.title}</h2><p>{section.subtitle}</p></section>;
if(section.type==="PRODUCTS"||section.type==="CONTENT")return <LiveCollection section={section}/>;
@@ -189,6 +209,11 @@ 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 LiveHeader({ style }: { style: React.CSSProperties }) {
const items = useNavigation("HEADER");
return <header className="live-header" style={style}><a href="/" className="live-logo">SHOPLIX</a><nav><NavigationLinks items={items}/></nav><a className="live-quote" href="/contact-us">Get a quote</a></header>;
}
function LiveCollection({section}:{section:DecorationSection}) {
const [items,setItems]=useState<Item[]>([]);
useEffect(()=>{const path=section.type==="PRODUCTS"?"/products/list":"/contents/list";const body=section.type==="PRODUCTS"?{}:{contentType:section.sourceType||"CASE"};post(path,body).then(data=>setItems((data.items||[]).slice(0,section.limit||3))).catch(()=>setItems([]))},[section.type,section.sourceType,section.limit]);
@@ -196,6 +221,7 @@ function LiveCollection({section}:{section:DecorationSection}) {
return <section className="live-collection" style={{background:section.background,color:section.textColor}}><p>FEATURED</p><h2>{section.title}</h2><div>{items.map(item=><a href={`/${base}/${item.slug}`} key={item.productCode||item.contentCode}><div>{item.coverMediaUrl&&<img src={`http://localhost:8082${item.coverMediaUrl}`} alt={item.productName||item.title}/>}</div><span>{section.type==="PRODUCTS"?"PRODUCT":section.sourceType}</span><h3>{item.productName||item.title}</h3><p>{item.summary}</p></a>)}</div></section>;
}
function Header() {
const items = useNavigation("HEADER");
return (
<header>
<a className="logo" href="/">
@@ -203,11 +229,7 @@ function Header() {
<span>Industrial Solutions</span>
</a>
<nav>
{nav.map(([n, h]) => (
<a href={h} key={h}>
{n}
</a>
))}
<NavigationLinks items={items}/>
</nav>
<div className="actions">
<Search size={19} />
+1
View File
@@ -53,6 +53,7 @@ nav {
nav a:hover {
color: #16715e;
}
.site-nav-item{position:relative;display:flex;align-items:center}.site-subnav{display:none;position:absolute;top:100%;left:50%;transform:translateX(-50%);min-width:190px;padding:8px;background:#fff;color:#17242a;border:1px solid #e1e6e4;box-shadow:0 10px 28px #1d302a20}.site-nav-item:hover>.site-subnav,.site-nav-item:focus-within>.site-subnav{display:grid}.site-subnav a{white-space:nowrap;padding:9px 11px;font-weight:500}.site-subnav a:hover{background:#eef5f2}.live-header .site-subnav{top:calc(100% + 18px)}
.actions {
display: flex;
align-items: center;