bug修复

This commit is contained in:
张锐 committed 2026-11-25 08:14:27 +08:00
1 parent 18b5c1e9e1
commit 654d08c8c8
4 files changed
+42 -48

No files matched your search

+34 -43
View File
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { createRoot } from "react-dom/client";
import { ArrowRight, ChevronRight, Image as ImageIcon, Mail, Menu, Search } from "lucide-react";
import { ArrowRight, ChevronRight, Image as ImageIcon, Mail, Menu, Search, X } from "lucide-react";
import "./styles.css";
import { initializeAnalytics, routePageCode, trackInquirySubmitted, trackPageLeave, trackPageView } from "./analytics";
@@ -489,6 +489,19 @@ function Collection({
}
/** B2B 商品详情主体,集中展示主图、核心信息、参数、详情和询盘入口。 */
function ProductDetailView({ data: d }: { data: Record<string, any> }) {
const [inquiryOpen, setInquiryOpen] = useState(false);
useEffect(() => {
if (!inquiryOpen) return;
const closeOnEscape = (event: KeyboardEvent) => {
if (event.key === "Escape") setInquiryOpen(false);
};
document.body.classList.add("modal-open");
window.addEventListener("keydown", closeOnEscape);
return () => {
document.body.classList.remove("modal-open");
window.removeEventListener("keydown", closeOnEscape);
};
}, [inquiryOpen]);
return <article className="detail product-detail">
<Crumbs current={String(d.productName || "Product")}/>
<section className="product-overview">
@@ -502,13 +515,20 @@ function ProductDetailView({ data: d }: { data: Record<string, any> }) {
<h1>{d.productName}</h1>
{d.model && <div className="product-model">Model <strong>{d.model}</strong></div>}
<p className="lead">{d.summary}</p>
{d.inquiryEnabled && <a className="product-inquiry-cta" href="#product-inquiry"><Mail size={18}/>Request a quote</a>}
{d.inquiryEnabled && <button className="product-inquiry-cta" type="button" onClick={() => setInquiryOpen(true)}><Mail size={18}/>Request a quote</button>}
</div>
</section>
{d.attributes?.length > 0 && <section className="specs product-attributes"><h2>Product attributes</h2>{d.attributes.map((a:any,i:number)=><div key={i}><span>{a.name}</span><strong>{a.value} {a.unit}</strong></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>}
{d.inquiryEnabled && <div id="product-inquiry"><InquiryForm scene="PRODUCT" sourceCode={d.productCode}/></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()}>
<button className="inquiry-modal-close" type="button" aria-label="Close inquiry form" onClick={() => setInquiryOpen(false)}><X size={22}/></button>
<InquiryForm scene="PRODUCT" sourceCode={d.productCode}/>
</div>
</div>
)}
</article>;
}
function Page({ slug }: { slug: string }) {
@@ -601,12 +621,22 @@ function InquiryForm({
try {
setBusy(true);
setNotice("");
const configuredValue = (...keys: string[]) => {
const field = definition.fields.find((item) => keys.includes(item.fieldKey));
return field ? custom[field.fieldCode] || "" : "";
};
const result = await post("/inquiries/submit", {
formCode: definition.formCode,
sourceType: scene,
sourceCode,
sourceUrl: location.href,
...form,
name: configuredValue("name", "customer_name"),
email: configuredValue("email", "customer_email"),
phone: configuredValue("phone", "customer_phone"),
company: configuredValue("company", "company_name"),
countryCode: configuredValue("country_code", "country"),
message: configuredValue("message", "requirements"),
fieldValues: definition.fields.map((x) => ({
fieldCode: x.fieldCode,
value: custom[x.fieldCode] || "",
@@ -636,37 +666,6 @@ function InquiryForm({
<h2>Discuss your requirements</h2>
{definition.description && <p>{definition.description}</p>}
<form onSubmit={submit}>
<label>
<span>Name *</span>
<input
required
value={form.name}
onChange={(e) => setForm({ ...form, name: e.target.value })}
/>
</label>
<label>
<span>Email *</span>
<input
type="email"
required
value={form.email}
onChange={(e) => setForm({ ...form, email: e.target.value })}
/>
</label>
<label>
<span>Phone</span>
<input
value={form.phone}
onChange={(e) => setForm({ ...form, phone: e.target.value })}
/>
</label>
<label>
<span>Company</span>
<input
value={form.company}
onChange={(e) => setForm({ ...form, company: e.target.value })}
/>
</label>
{definition.fields.map((field) => (
<label
className={field.widthType === "FULL" ? "wide" : ""}
@@ -701,6 +700,7 @@ function InquiryForm({
/>
) : (
<input
type={field.fieldType === "EMAIL" ? "email" : field.fieldType === "PHONE" ? "tel" : field.fieldType === "NUMBER" ? "number" : "text"}
required={field.required}
maxLength={field.maxLength}
placeholder={field.placeholder}
@@ -713,15 +713,6 @@ function InquiryForm({
{field.helpText && <small>{field.helpText}</small>}
</label>
))}
<label className="wide">
<span>Message *</span>
<textarea
required
rows={6}
value={form.message}
onChange={(e) => setForm({ ...form, message: e.target.value })}
/>
</label>
<input
className="honeypot"
tabIndex={-1}