功能迭代

This commit is contained in:
张锐 committed 2026-12-01 17:45:37 +08:00
1 parent 9df10ca806
commit 5fc7d4564c
11 files changed
+227 -11

No files matched your search

+18 -4
View File
@@ -6,6 +6,10 @@ import { initializeAnalytics, routePageCode, trackInquirySubmitted, trackPageLea
const API = import.meta.env.VITE_SITE_API_BASE || "/api/site/v1";
type ContentType = "NEWS" | "CASE" | "HELP";
/** 将内容类型映射为前台标准复数路径。 */
function contentPath(type: ContentType): string {
return type === "CASE" ? "cases" : type.toLowerCase();
}
type Item = {
productCode?: string;
contentCode?: string;
@@ -403,7 +407,7 @@ function LiveHeader({ section, style }: { section: DecorationSection; style: Rea
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"?{featured:true,pageNo:1,pageSize:section.limit||3}:{contentType:section.sourceType||"CASE",featured:true,pageNo:1,pageSize:section.limit||3};post(path,body).then(data=>setItems(data.items||[])).catch(()=>setItems([]))},[section.type,section.sourceType,section.limit]);
const base=section.type==="PRODUCTS"?"products":(section.sourceType||"CASE").toLowerCase();
const base=section.type==="PRODUCTS"?"products":contentPath((section.sourceType||"CASE") as ContentType);
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={assetUrl(item.coverMediaUrl)} alt={item.productName||item.title} loading="lazy"/>}</div><span>{section.type==="PRODUCTS"?"PRODUCT":section.sourceType}</span><h3>{item.productName||item.title}</h3><p>{item.summary}</p></a>)}</div></section>;
}
function Header() {
@@ -581,7 +585,7 @@ function Collection({
</article>
);
}
const basePath = type === "products" ? "/products" : `/${type.toLowerCase()}`;
const basePath = type === "products" ? "/products" : `/${contentPath(type as ContentType)}`;
return (
<section className="listing">
<Crumbs current={title} />
@@ -607,7 +611,7 @@ function Collection({
{(data as Item[]).map((item) => (
<a
className="card"
href={`/${type === "products" ? "products" : type.toLowerCase()}/${item.slug}`}
href={`/${type === "products" ? "products" : contentPath(type as ContentType)}/${item.slug}`}
key={item.productCode || item.contentCode}
>
<div className="thumb">
@@ -666,7 +670,7 @@ function SearchResults({ query }: { query: string }) {
setLoading(true);
Promise.all([
post("/products/list", { keyword: query.trim(), pageNo: 1, pageSize: 100 }).then((data) => ({ items: data.items || [], base: "products", label: "Product" })),
...(["NEWS", "CASE", "HELP"] as ContentType[]).map((contentType) => post("/contents/list", { contentType, keyword: query.trim(), pageNo: 1, pageSize: 100 }).then((data) => ({ items: data.items || [], base: contentType.toLowerCase(), label: contentType === "CASE" ? "Case" : contentType.charAt(0) + contentType.slice(1).toLowerCase() }))),
...(["NEWS", "CASE", "HELP"] as ContentType[]).map((contentType) => post("/contents/list", { contentType, keyword: query.trim(), pageNo: 1, pageSize: 100 }).then((data) => ({ items: data.items || [], base: contentPath(contentType), label: contentType === "CASE" ? "Case" : contentType.charAt(0) + contentType.slice(1).toLowerCase() }))),
]).then((groups) => {
const matched = groups.flatMap((group) => group.items.map((item: Item) => ({ item, base: group.base, label: group.label })))
.filter(({ item }) => [item.productName, item.title, item.summary, item.model].some((value) => value?.toLowerCase().includes(keyword)));
@@ -810,6 +814,16 @@ function ProductDetailView({ data: d, configuration }: { data: Record<string, an
</div>
)}
</section>
{(d.relatedProducts || []).length > 0 && <section className="related-products">
<p className="eyebrow">YOU MAY ALSO LIKE</p>
<h2>Related products</h2>
<div>{d.relatedProducts.map((product: Item) => <a href={`/products/${product.slug}`} key={product.productCode}>
<figure>{product.coverMediaUrl ? <img src={assetUrl(product.coverMediaUrl)} alt={product.productName} loading="lazy"/> : <ImageIcon size={36}/>}</figure>
<small>{product.model || "PRODUCT"}</small>
<h3>{product.productName}</h3>
<span>View product <ChevronRight size={14}/></span>
</a>)}</div>
</section>}
{imageZoomOpen && productImages[selectedImage]?.url && <div className="product-lightbox" role="presentation" onClick={() => setImageZoomOpen(false)}><button type="button" aria-label="Close enlarged image" onClick={() => setImageZoomOpen(false)}><X size={22}/></button><img src={assetUrl(productImages[selectedImage].url)} alt={`${d.productName || "Product"} enlarged`} onClick={(event) => event.stopPropagation()}/></div>}
{d.inquiryEnabled && inquiryOpen && (
<div className="inquiry-modal-backdrop" role="presentation" onMouseDown={() => setInquiryOpen(false)}>
+53
View File
@@ -1507,3 +1507,56 @@ footer small {
.content img {
cursor: zoom-in;
}
.related-products {
border-top: 1px solid #dfe6e3;
margin-top: 54px;
padding-top: 50px;
}
.related-products > h2 {
font-family: Georgia, serif;
font-size: clamp(30px, 4vw, 46px);
margin: 6px 0 28px;
}
.related-products > div {
display: grid;
gap: 22px;
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.related-products a {
color: inherit;
text-decoration: none;
}
.related-products figure {
align-items: center;
background: #f3f6f5;
display: flex;
height: 260px;
justify-content: center;
margin: 0 0 17px;
overflow: hidden;
}
.related-products img {
height: 100%;
object-fit: contain;
transition: transform .25s ease;
width: 100%;
}
.related-products a:hover img { transform: scale(1.04); }
.related-products small { color: #6c7974; }
.related-products h3 { font-family: Georgia, serif; font-size: 20px; margin: 8px 0 13px; }
.related-products a > span { align-items: center; color: #08715e; display: flex; font-size: 13px; font-weight: 700; gap: 4px; }
@media (max-width: 900px) {
.related-products > div { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.related-products figure { height: 210px; }
}
@media (max-width: 560px) {
.related-products > div { grid-template-columns: 1fr; }
}