bug修复
This commit is contained in:
1 parent
eae135ec88
commit
12979c9600
5 files changed
+57
-29
No files matched your search
+10
-2
@@ -633,10 +633,17 @@ function SearchResults({ query }: { query: string }) {
|
||||
/** B2B 商品详情主体,集中展示主图、核心信息、参数、详情和询盘入口。 */
|
||||
function ProductDetailView({ data: d, configuration }: { data: Record<string, any>; configuration?: ProductDetailConfiguration }) {
|
||||
const [inquiryOpen, setInquiryOpen] = useState(false);
|
||||
const [imageZoomOpen, setImageZoomOpen] = useState(false);
|
||||
const [touchStartX, setTouchStartX] = useState<number | null>(null);
|
||||
const productImages = d.images?.length ? d.images : d.coverMediaUrl ? [{mediaCode:d.coverMediaCode,url:d.coverMediaUrl}] : [];
|
||||
const [selectedImage, setSelectedImage] = useState(0);
|
||||
const attributes = (d.attributes || []).slice(0, configuration?.productInformationLimit || d.attributes?.length || 0);
|
||||
const showProductInformation = configuration?.showProductInformation !== false && (Boolean(d.model) || attributes.length > 0);
|
||||
const specifications = d.specifications || [];
|
||||
const selectAdjacentImage = (direction: number) => {
|
||||
if (productImages.length < 2) return;
|
||||
setSelectedImage((current) => (current + direction + productImages.length) % productImages.length);
|
||||
};
|
||||
useEffect(() => setSelectedImage(0), [d.productCode]);
|
||||
useEffect(() => {
|
||||
if (!inquiryOpen) return;
|
||||
@@ -654,7 +661,7 @@ function ProductDetailView({ data: d, configuration }: { data: Record<string, an
|
||||
<Crumbs current={String(d.productName || "Product")}/>
|
||||
<section className="product-overview">
|
||||
<div className="product-gallery">
|
||||
<div className="product-media">
|
||||
<div className="product-media" onClick={() => productImages.length > 0 && setImageZoomOpen(true)} onTouchStart={(event) => setTouchStartX(event.touches[0].clientX)} onTouchEnd={(event) => { if (touchStartX === null) return; const delta = event.changedTouches[0].clientX - touchStartX; if (Math.abs(delta) > 40) selectAdjacentImage(delta < 0 ? 1 : -1); setTouchStartX(null); }}>
|
||||
{productImages[selectedImage]?.url
|
||||
? <img src={assetUrl(productImages[selectedImage].url)} alt={`${d.productName || "Product"} ${selectedImage + 1}`}/>
|
||||
: <div className="product-image-placeholder"><ImageIcon size={48}/><span>Product image coming soon</span></div>}
|
||||
@@ -672,12 +679,13 @@ function ProductDetailView({ data: d, configuration }: { data: Record<string, an
|
||||
{attributes.map((attribute:any,index:number)=><div key={`${attribute.name}-${index}`}><dt>{attribute.name}</dt><dd>{attribute.value} {attribute.unit}</dd></div>)}
|
||||
</dl>
|
||||
</section>}
|
||||
{specifications.length > 0 && <section className="product-specifications"><h2>Specifications</h2><dl>{specifications.map((spec:any,index:number)=><div key={`${spec.name}-${index}`}><dt>{spec.groupName&&`${spec.groupName} · `}{spec.name}</dt><dd>{spec.value} {spec.unit}</dd></div>)}</dl></section>}
|
||||
{d.inquiryEnabled && <button className="product-inquiry-cta" type="button" onClick={() => setInquiryOpen(true)}><Mail size={18}/>Request a quote</button>}
|
||||
<SocialShareBar title={String(d.productName || document.title)}/>
|
||||
</div>
|
||||
</section>
|
||||
<div className="content product-content" dangerouslySetInnerHTML={{__html:normalizeRichTextHtml(d.content)}}/>
|
||||
{d.specifications?.length > 0 && <section className="specs"><h2>Technical specifications</h2>{d.specifications.map((s:any,i:number)=><div key={i}><span>{s.groupName&&`${s.groupName} · `}{s.name}</span><strong>{s.value} {s.unit}</strong></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)}>
|
||||
<div className="inquiry-modal" role="dialog" aria-modal="true" aria-label="Request a quote" onMouseDown={(event) => event.stopPropagation()}>
|
||||
|
||||
Reference in new issue
Block a user