bug修复

This commit is contained in:
张锐 committed 2026-11-25 22:45:29 +08:00
1 parent eae135ec88
commit 12979c9600
5 files changed
+57 -29

No files matched your search

+10 -2
View File
@@ -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()}>
+1 -1
View File
@@ -290,7 +290,7 @@ nav a:hover {
padding-bottom: 32px;
}
.product-cover { width: 100%; max-height: 560px; object-fit: contain; background: #f4f6f5; margin: 20px 0 35px; }
.product-detail{max-width:1220px}.product-detail>.crumbs{margin-bottom:30px}.product-overview{display:grid;grid-template-columns:minmax(0,1.05fr) minmax(380px,.95fr);gap:54px;align-items:start}.product-gallery{min-width:0}.product-media{aspect-ratio:1/1;background:#f1f4f2;border:1px solid #e0e6e3;display:grid;place-items:center;overflow:hidden}.product-media>img{width:100%;height:100%;object-fit:contain}.product-thumbnails{display:grid;grid-template-columns:repeat(auto-fill,minmax(72px,1fr));gap:10px;margin-top:12px}.product-thumbnail{aspect-ratio:1;border:1px solid #d6ddda;background:#fff;padding:4px;cursor:pointer}.product-thumbnail img{width:100%;height:100%;object-fit:contain;display:block}.product-thumbnail.active{border:2px solid var(--green);padding:3px}.product-thumbnail:focus-visible{outline:2px solid var(--green);outline-offset:2px}.product-image-placeholder{display:grid;place-items:center;gap:14px;color:#899691;text-align:center}.product-image-placeholder span{font-size:13px}.product-summary{padding:18px 0}.product-summary h1{font-size:46px;line-height:1.1;margin:12px 0 22px}.product-summary .lead{border:0;padding:0;margin:22px 0 20px;font-size:17px;line-height:1.75}.product-information{margin:0 0 26px}.product-information h2{font:500 16px Georgia,serif;margin:0 0 10px}.product-information dl{margin:0}.product-information dl>div{display:grid;grid-template-columns:minmax(90px,.34fr) minmax(0,1fr);gap:16px;align-items:start;padding:8px 0}.product-information dt{color:#76837f;font-size:13px}.product-information dd{margin:0;color:#17211f;font-size:13px;font-weight:500;overflow-wrap:anywhere}.product-inquiry-cta{display:inline-flex;align-items:center;justify-content:center;gap:9px;background:#176b5b;color:#fff;border:0;padding:14px 22px;min-width:190px;font-family:inherit;font-size:14px;font-weight:700;cursor:pointer}.product-content{max-width:900px;margin:55px auto 0;line-height:1.75}.product-content pre,.product-content code{font:inherit;white-space:normal}.product-content pre{margin:0}
.product-detail{max-width:1220px}.product-detail>.crumbs{margin-bottom:30px}.product-overview{display:grid;grid-template-columns:minmax(0,1.05fr) minmax(380px,.95fr);gap:54px;align-items:start}.product-gallery{min-width:0}.product-media{aspect-ratio:1/1;background:#f1f4f2;border:1px solid #e0e6e3;display:grid;place-items:center;overflow:hidden;cursor:zoom-in;touch-action:pan-y}.product-media>img{width:100%;height:100%;object-fit:contain}.product-thumbnails{display:flex;gap:10px;margin-top:12px;overflow-x:auto;padding-bottom:3px}.product-thumbnail{width:76px;min-width:76px;aspect-ratio:1;border:1px solid #d6ddda;background:#fff;padding:4px;cursor:pointer}.product-thumbnail img{width:100%;height:100%;object-fit:contain;display:block}.product-thumbnail.active{border:2px solid var(--green);padding:3px}.product-thumbnail:focus-visible{outline:2px solid var(--green);outline-offset:2px}.product-image-placeholder{display:grid;place-items:center;gap:14px;color:#899691;text-align:center}.product-image-placeholder span{font-size:13px}.product-summary{padding:18px 0}.product-summary h1{font-size:46px;line-height:1.1;margin:12px 0 22px}.product-summary .lead{border:0;padding:0;margin:22px 0 20px;font-size:17px;line-height:1.75}.product-information,.product-specifications{margin:0 0 22px}.product-information h2,.product-specifications h2{font:500 16px Georgia,serif;margin:0 0 10px}.product-information dl,.product-specifications dl{margin:0;max-height:240px;overflow:auto}.product-information dl>div,.product-specifications dl>div{display:grid;grid-template-columns:minmax(90px,.34fr) minmax(0,1fr);gap:16px;align-items:start;padding:7px 0}.product-information dt,.product-specifications dt{color:#76837f;font-size:13px}.product-information dd,.product-specifications dd{margin:0;color:#17211f;font-size:13px;font-weight:500;overflow-wrap:anywhere}.product-inquiry-cta{display:inline-flex;align-items:center;justify-content:center;gap:9px;background:#176b5b;color:#fff;border:0;padding:14px 22px;min-width:190px;font-family:inherit;font-size:14px;font-weight:700;cursor:pointer}.product-lightbox{position:fixed;inset:0;z-index:1100;background:#101a18e6;display:grid;place-items:center;padding:40px;cursor:zoom-out}.product-lightbox img{max-width:min(1100px,92vw);max-height:88vh;object-fit:contain}.product-lightbox button{position:absolute;top:22px;right:24px;width:42px;height:42px;border:1px solid #fff6;background:#fff;color:#17211f;display:grid;place-items:center;cursor:pointer}.product-content{max-width:900px;margin:55px auto 0;line-height:1.75}.product-content pre,.product-content code{font:inherit;white-space:normal}.product-content pre{margin:0}
.social-share-bar{display:flex;align-items:center;gap:10px;margin-top:22px}.social-share-bar a,.social-floating-bar a{width:32px;height:32px;border-radius:50%;display:grid;place-items:center;background:#18221f;color:#fff;font:bold 13px Arial,sans-serif}.social-share-bar a[data-platform="FACEBOOK"],.social-floating-bar a[data-platform="FACEBOOK"]{background:#1877f2}.social-share-bar a[data-platform="LINKEDIN"],.social-floating-bar a[data-platform="LINKEDIN"]{background:#0a66c2}.social-share-bar a[data-platform="YOUTUBE"],.social-floating-bar a[data-platform="YOUTUBE"]{background:#f00}.social-share-bar a[data-platform="WHATSAPP"],.social-floating-bar a[data-platform="WHATSAPP"]{background:#25d366}.social-share-bar a[data-platform="PINTEREST"],.social-floating-bar a[data-platform="PINTEREST"]{background:#bd081c}.social-share-bar a[data-platform="LINE"],.social-floating-bar a[data-platform="LINE"]{background:#06c755}.social-floating-bar{position:fixed;z-index:20;right:22px;top:50%;transform:translateY(-50%);display:grid;gap:10px;padding:12px 9px;background:#171b1a;border-radius:22px;box-shadow:0 10px 28px #10161438}.social-floating-bar a{width:34px;height:34px}.social-floating-bar a:hover,.social-share-bar a:hover{transform:translateY(-2px)}
.modal-open{overflow:hidden}.inquiry-modal-backdrop{position:fixed;inset:0;z-index:1000;background:#101a18a8;display:grid;place-items:center;padding:24px}.inquiry-modal{position:relative;width:min(860px,100%);max-height:calc(100vh - 48px);overflow:auto;background:#fff;box-shadow:0 18px 60px #07100e40}.inquiry-modal-close{position:absolute;z-index:2;top:18px;right:18px;width:42px;height:42px;border:1px solid #d5ddda;background:#fff;color:#17211f;display:grid;place-items:center;cursor:pointer}.inquiry-modal .inquiry-box{margin:0;border-top:0;padding:42px}.inquiry-modal .inquiry-box h2{padding-right:50px}
.content {