调整商详属性和规格标签展示

This commit is contained in:
张锐 committed 2026-11-27 08:46:14 +08:00
1 parent 362c1ede21
commit 104238f3c6
4 files changed
+67 -13

No files matched your search

+16 -4
View File
@@ -642,17 +642,19 @@ function SearchResults({ query }: { query: string }) {
function ProductDetailView({ data: d, configuration }: { data: Record<string, any>; configuration?: ProductDetailConfiguration }) {
const [inquiryOpen, setInquiryOpen] = useState(false);
const [imageZoomOpen, setImageZoomOpen] = useState(false);
const [activeProductTab, setActiveProductTab] = useState<"DETAILS" | "SPECIFICATIONS">("DETAILS");
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 showProductInformation = configuration?.showProductInformation !== false && 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(() => setActiveProductTab("DETAILS"), [d.productCode]);
useEffect(() => {
if (!inquiryOpen) return;
const closeOnEscape = (event: KeyboardEvent) => {
@@ -683,16 +685,26 @@ function ProductDetailView({ data: d, configuration }: { data: Record<string, an
{showProductInformation && <section className="product-information">
<h2>{configuration?.productInformationTitle || "Product information"}</h2>
<dl>
{d.model && <div><dt>Model</dt><dd>{d.model}</dd></div>}
{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)}}/>
<section className="product-detail-tabs">
<div className="product-tab-list" role="tablist" aria-label="Product information tabs">
<button type="button" role="tab" aria-selected={activeProductTab === "DETAILS"} className={activeProductTab === "DETAILS" ? "active" : ""} onClick={() => setActiveProductTab("DETAILS")}>Product Details</button>
<button type="button" role="tab" aria-selected={activeProductTab === "SPECIFICATIONS"} className={activeProductTab === "SPECIFICATIONS" ? "active" : ""} onClick={() => setActiveProductTab("SPECIFICATIONS")}>Specifications</button>
</div>
{activeProductTab === "DETAILS" ? (
<div className="content product-content" role="tabpanel" dangerouslySetInnerHTML={{__html:normalizeRichTextHtml(d.content)}}/>
) : (
<div className="product-specification-panel" role="tabpanel">
{specifications.length > 0 ? specifications.map((spec:any,index:number)=><div className="product-specification-row" key={`${spec.groupName}-${spec.name}-${index}`}><span>{spec.groupName || "General"}</span><strong>{spec.name}</strong><em>{spec.value} {spec.unit}</em></div>) : <p className="product-tab-empty">Specifications are being prepared.</p>}
</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)}>