bug修复
This commit is contained in:
1 parent
4d55b6177e
commit
d6f05ae975
5 files changed
+98
-13
No files matched your search
@@ -6,6 +6,7 @@ import {
|
|||||||
Eye,
|
Eye,
|
||||||
EyeOff,
|
EyeOff,
|
||||||
GripVertical,
|
GripVertical,
|
||||||
|
Image as ImageIcon,
|
||||||
Monitor,
|
Monitor,
|
||||||
Plus,
|
Plus,
|
||||||
Redo2,
|
Redo2,
|
||||||
@@ -28,6 +29,7 @@ type SectionType =
|
|||||||
| "HERO"
|
| "HERO"
|
||||||
| "RICH_TEXT"
|
| "RICH_TEXT"
|
||||||
| "PRODUCTS"
|
| "PRODUCTS"
|
||||||
|
| "PRODUCT_DETAIL"
|
||||||
| "CONTENT"
|
| "CONTENT"
|
||||||
| "INQUIRY"
|
| "INQUIRY"
|
||||||
| "FOOTER";
|
| "FOOTER";
|
||||||
@@ -55,12 +57,14 @@ type Schema = {
|
|||||||
};
|
};
|
||||||
sections: Section[];
|
sections: Section[];
|
||||||
};
|
};
|
||||||
|
type PreviewProduct = {productCode:string;productName:string;model?:string;summary?:string;coverMediaUrl?:string;attributes?:Array<{name:string;value:string;unit?:string}>};
|
||||||
const labels: Record<SectionType, string> = {
|
const labels: Record<SectionType, string> = {
|
||||||
ANNOUNCEMENT: "公告栏",
|
ANNOUNCEMENT: "公告栏",
|
||||||
HEADER: "导航栏",
|
HEADER: "导航栏",
|
||||||
HERO: "轮播横幅",
|
HERO: "轮播横幅",
|
||||||
RICH_TEXT: "富文本",
|
RICH_TEXT: "富文本",
|
||||||
PRODUCTS: "产品展示",
|
PRODUCTS: "产品展示",
|
||||||
|
PRODUCT_DETAIL: "产品详情",
|
||||||
CONTENT: "内容展示",
|
CONTENT: "内容展示",
|
||||||
INQUIRY: "询盘表单",
|
INQUIRY: "询盘表单",
|
||||||
FOOTER: "页脚",
|
FOOTER: "页脚",
|
||||||
@@ -120,6 +124,10 @@ function createSection(type: SectionType): Section {
|
|||||||
textColor: type === "HEADER" || type === "FOOTER" ? "#ffffff" : "#17211f",
|
textColor: type === "HEADER" || type === "FOOTER" ? "#ffffff" : "#17211f",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
/** 为产品详情页提供可直接发布的基础组件结构。 */
|
||||||
|
function productDetailSchema(schema:Schema):Schema{
|
||||||
|
return {...schema,sections:[createSection("HEADER"),createSection("PRODUCT_DETAIL"),createSection("FOOTER")]};
|
||||||
|
}
|
||||||
export default function DecorationEditor({ onBack }: { onBack: () => void }) {
|
export default function DecorationEditor({ onBack }: { onBack: () => void }) {
|
||||||
const [pageType, setPageType] = useState("HOME");
|
const [pageType, setPageType] = useState("HOME");
|
||||||
const [schema, setSchema] = useState<Schema>(initialSchema);
|
const [schema, setSchema] = useState<Schema>(initialSchema);
|
||||||
@@ -131,6 +139,7 @@ export default function DecorationEditor({ onBack }: { onBack: () => void }) {
|
|||||||
const [notice, setNotice] = useState("");
|
const [notice, setNotice] = useState("");
|
||||||
const [status, setStatus] = useState("DRAFT");
|
const [status, setStatus] = useState("DRAFT");
|
||||||
const [version, setVersion] = useState(0);
|
const [version, setVersion] = useState(0);
|
||||||
|
const [previewProduct,setPreviewProduct]=useState<PreviewProduct>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelected(null);
|
setSelected(null);
|
||||||
setGlobalMode(false);
|
setGlobalMode(false);
|
||||||
@@ -138,12 +147,14 @@ export default function DecorationEditor({ onBack }: { onBack: () => void }) {
|
|||||||
setFuture([]);
|
setFuture([]);
|
||||||
post("/decorations/detail", { siteCode: SITE, pageType })
|
post("/decorations/detail", { siteCode: SITE, pageType })
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setSchema(JSON.parse(data.schema));
|
const loaded=JSON.parse(data.schema) as Schema;
|
||||||
|
setSchema(pageType==="PRODUCT_DETAIL"&&!loaded.sections.length?productDetailSchema(loaded):loaded);
|
||||||
setStatus(data.status);
|
setStatus(data.status);
|
||||||
setVersion(data.publishedVersion);
|
setVersion(data.publishedVersion);
|
||||||
})
|
})
|
||||||
.catch((error) => setNotice(error.message));
|
.catch((error) => setNotice(error.message));
|
||||||
}, [pageType]);
|
}, [pageType]);
|
||||||
|
useEffect(()=>{if(pageType!=="PRODUCT_DETAIL")return;post("/products/list",{siteCode:SITE}).then(data=>data.items?.[0]?.productCode?post("/products/detail",{siteCode:SITE,productCode:data.items[0].productCode}):undefined).then(data=>{if(data)setPreviewProduct(data)}).catch(()=>setPreviewProduct(undefined))},[pageType]);
|
||||||
const commit = (next: Schema) => {
|
const commit = (next: Schema) => {
|
||||||
setHistory((items) => [...items.slice(-19), schema]);
|
setHistory((items) => [...items.slice(-19), schema]);
|
||||||
setFuture([]);
|
setFuture([]);
|
||||||
@@ -389,6 +400,7 @@ export default function DecorationEditor({ onBack }: { onBack: () => void }) {
|
|||||||
setSelected(item.id);
|
setSelected(item.id);
|
||||||
setGlobalMode(false);
|
setGlobalMode(false);
|
||||||
}}
|
}}
|
||||||
|
product={previewProduct}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
@@ -453,11 +465,13 @@ function PreviewSection({
|
|||||||
primary,
|
primary,
|
||||||
selected,
|
selected,
|
||||||
onSelect,
|
onSelect,
|
||||||
|
product,
|
||||||
}: {
|
}: {
|
||||||
item: Section;
|
item: Section;
|
||||||
primary: string;
|
primary: string;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
onSelect: () => void;
|
onSelect: () => void;
|
||||||
|
product?:PreviewProduct;
|
||||||
}) {
|
}) {
|
||||||
const style = {
|
const style = {
|
||||||
background: item.background,
|
background: item.background,
|
||||||
@@ -533,6 +547,7 @@ function PreviewSection({
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
if(item.type==="PRODUCT_DETAIL")return <section className="pv-product-detail" style={style} onClick={onSelect}><div className="pv-product-image">{product?.coverMediaUrl?<img src={product.coverMediaUrl} alt={product.productName}/>:<ImageIcon size={44}/>}</div><div><span>PRODUCT</span><h1>{product?.productName||"Product title"}</h1>{product?.model&&<small>Model <strong>{product.model}</strong></small>}<p>{product?.summary||"Product summary and key selling points will be loaded from the selected product."}</p><button style={{background:primary}}>Request a quote</button></div>{product?.attributes?.length?<dl>{product.attributes.slice(0,4).map(attribute=><div key={attribute.name}><dt>{attribute.name}</dt><dd>{attribute.value} {attribute.unit}</dd></div>)}</dl>:null}</section>;
|
||||||
if (item.type === "INQUIRY")
|
if (item.type === "INQUIRY")
|
||||||
return (
|
return (
|
||||||
<section className="pv-inquiry" style={style} onClick={onSelect}>
|
<section className="pv-inquiry" style={style} onClick={onSelect}>
|
||||||
@@ -658,7 +673,7 @@ function SectionSettings({
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h3>{labels[item.type]}设置</h3>
|
<h3>{labels[item.type]}设置</h3>
|
||||||
<Field label="英文标题">
|
{item.type!=="PRODUCT_DETAIL"&&<><Field label="英文标题">
|
||||||
<input
|
<input
|
||||||
value={item.title}
|
value={item.title}
|
||||||
onChange={(e) => onChange({ title: e.target.value })}
|
onChange={(e) => onChange({ title: e.target.value })}
|
||||||
@@ -671,6 +686,7 @@ function SectionSettings({
|
|||||||
onChange={(e) => onChange({ subtitle: e.target.value })}
|
onChange={(e) => onChange({ subtitle: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
</>}
|
||||||
{item.type === "HERO" && (
|
{item.type === "HERO" && (
|
||||||
<>
|
<>
|
||||||
<Field label="背景图片 URL">
|
<Field label="背景图片 URL">
|
||||||
|
|||||||
@@ -38,6 +38,17 @@ function mergeSpecifications(items:Specification[]):Specification[]{
|
|||||||
return [...merged.values()];
|
return [...merged.values()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 将误存为普通文本的富文本标签恢复为可编辑 HTML,正常富文本保持不变。 */
|
||||||
|
function normalizeRichTextHtml(content:string):string{
|
||||||
|
if(!content||!/&(?:amp;)?lt;\/?(?:h[1-6]|p|ul|ol|li|blockquote|table|img|a)\b/i.test(content))return content;
|
||||||
|
const decoder=document.createElement('textarea');
|
||||||
|
let decoded=content;
|
||||||
|
for(let index=0;index<2;index+=1){decoder.innerHTML=decoded;const next=decoder.value;if(next===decoded)break;decoded=next}
|
||||||
|
decoded=decoded.replace(/^\s*<pre><code>/i,'').replace(/<\/code><\/pre>(?:<p><\/p>)?\s*$/i,'');
|
||||||
|
if(!/<\/?(?:h[1-6]|p|ul|ol|li|blockquote|table|img|a)\b/i.test(decoded))return content;
|
||||||
|
const container=document.createElement('div');container.innerHTML=decoded;return container.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
export default function ProductEditor({productCode,onBack}:Props){
|
export default function ProductEditor({productCode,onBack}:Props){
|
||||||
const [form,setForm]=useState({productName:'',slug:'',model:'',summary:'',primaryCategoryCode:'',coverMediaCode:'',coverMediaUrl:'',featured:false,inquiryEnabled:true,sortNo:30,status:'DRAFT'});
|
const [form,setForm]=useState({productName:'',slug:'',model:'',summary:'',primaryCategoryCode:'',coverMediaCode:'',coverMediaUrl:'',featured:false,inquiryEnabled:true,sortNo:30,status:'DRAFT'});
|
||||||
const [attributes,setAttributes]=useState<Attribute[]>([]);const [specifications,setSpecifications]=useState<Specification[]>([]);const [categories,setCategories]=useState<ProductCategoryOption[]>([]);
|
const [attributes,setAttributes]=useState<Attribute[]>([]);const [specifications,setSpecifications]=useState<Specification[]>([]);const [categories,setCategories]=useState<ProductCategoryOption[]>([]);
|
||||||
@@ -47,10 +58,10 @@ export default function ProductEditor({productCode,onBack}:Props){
|
|||||||
const [uploading,setUploading]=useState(false);const coverInputRef=useRef<HTMLInputElement>(null);
|
const [uploading,setUploading]=useState(false);const coverInputRef=useRef<HTMLInputElement>(null);
|
||||||
const editor=useEditor({extensions:[StarterKit,Link.configure({openOnClick:false}),Image],content:'<p></p>'});
|
const editor=useEditor({extensions:[StarterKit,Link.configure({openOnClick:false}),Image],content:'<p></p>'});
|
||||||
useEffect(()=>{let active=true;setCategoriesLoading(true);setCategoriesError('');post('/products/categories/list',{siteCode:SITE}).then(data=>{if(active)setCategories(buildCategoryOptions(data.items||[]))}).catch(error=>{if(active)setCategoriesError(error instanceof Error?error.message:'产品分类加载失败')}).finally(()=>{if(active)setCategoriesLoading(false)});return()=>{active=false}},[]);
|
useEffect(()=>{let active=true;setCategoriesLoading(true);setCategoriesError('');post('/products/categories/list',{siteCode:SITE}).then(data=>{if(active)setCategories(buildCategoryOptions(data.items||[]))}).catch(error=>{if(active)setCategoriesError(error instanceof Error?error.message:'产品分类加载失败')}).finally(()=>{if(active)setCategoriesLoading(false)});return()=>{active=false}},[]);
|
||||||
useEffect(()=>{if(!productCode)return;post('/products/detail',{siteCode:SITE,productCode}).then(d=>{setForm({...d,coverMediaUrl:d.coverMediaUrl||''});setAttributes(d.attributes||[]);setSpecifications(mergeSpecifications(d.specifications||[]));editor?.commands.setContent(d.productContent||'<p></p>')});post('/seo/detail',{siteCode:SITE,pageType:'PRODUCT_DETAIL',targetCode:productCode}).then(d=>{setSeo({title:d.title,description:d.description,keywords:d.keywords||'',h1:d.h1,canonicalUrl:d.canonicalUrl||'',robots:d.robots,ogTitle:d.ogTitle||'',ogDescription:d.ogDescription||'',ogImageUrl:d.ogImageUrl||'',status:d.status});setHeadings(d.headings||[])}).catch(()=>{})},[productCode,editor]);
|
useEffect(()=>{if(!productCode)return;post('/products/detail',{siteCode:SITE,productCode}).then(d=>{setForm({...d,coverMediaUrl:d.coverMediaUrl||''});setAttributes(d.attributes||[]);setSpecifications(mergeSpecifications(d.specifications||[]));editor?.commands.setContent(normalizeRichTextHtml(d.productContent||'<p></p>'))});post('/seo/detail',{siteCode:SITE,pageType:'PRODUCT_DETAIL',targetCode:productCode}).then(d=>{setSeo({title:d.title,description:d.description,keywords:d.keywords||'',h1:d.h1,canonicalUrl:d.canonicalUrl||'',robots:d.robots,ogTitle:d.ogTitle||'',ogDescription:d.ogDescription||'',ogImageUrl:d.ogImageUrl||'',status:d.status});setHeadings(d.headings||[])}).catch(()=>{})},[productCode,editor]);
|
||||||
/** 校验并上传产品主图,选择相同文件时也允许重新触发上传。 */
|
/** 校验并上传产品主图,选择相同文件时也允许重新触发上传。 */
|
||||||
const upload=async(file?:File)=>{if(!file)return;if(file.size>10*1024*1024){setNotice('图片不能超过 10MB');return}try{setUploading(true);setNotice('');const body=new FormData();body.append('siteCode',SITE);body.append('altText',form.productName);body.append('file',file);const r=await fetch(API+'/media/upload-image',{method:'POST',body});if(r.status===413)throw new Error('图片超过服务器上传限制,请联系管理员调整 Nginx 上传上限');if(!r.ok)throw new Error((await r.json().catch(()=>({}))).message||'上传失败');const d=await r.json();setForm(current=>({...current,coverMediaCode:d.mediaCode,coverMediaUrl:d.url}));setNotice('产品主图上传成功')}catch(e){setNotice(e instanceof Error?e.message:'上传失败')}finally{setUploading(false);if(coverInputRef.current)coverInputRef.current.value=''}};
|
const upload=async(file?:File)=>{if(!file)return;if(file.size>10*1024*1024){setNotice('图片不能超过 10MB');return}try{setUploading(true);setNotice('');const body=new FormData();body.append('siteCode',SITE);body.append('altText',form.productName);body.append('file',file);const r=await fetch(API+'/media/upload-image',{method:'POST',body});if(r.status===413)throw new Error('图片超过服务器上传限制,请联系管理员调整 Nginx 上传上限');if(!r.ok)throw new Error((await r.json().catch(()=>({}))).message||'上传失败');const d=await r.json();setForm(current=>({...current,coverMediaCode:d.mediaCode,coverMediaUrl:d.url}));setNotice('产品主图上传成功')}catch(e){setNotice(e instanceof Error?e.message:'上传失败')}finally{setUploading(false);if(coverInputRef.current)coverInputRef.current.value=''}};
|
||||||
const save=async()=>{if(!editor)return;try{setSaving(true);setNotice('');const result=await post('/products/save',{productCode,siteCode:SITE,primaryCategoryCode:form.primaryCategoryCode,productName:form.productName,slug:form.slug,model:form.model,summary:form.summary,productContent:editor.getHTML(),coverMediaCode:form.coverMediaCode,featured:form.featured,inquiryEnabled:form.inquiryEnabled,sortNo:form.sortNo,status:form.status,specifications,attributes});await post('/seo/save',{siteCode:SITE,pageType:'PRODUCT_DETAIL',targetCode:result.productCode,title:seo.title||form.productName,description:seo.description||form.summary,keywords:seo.keywords,h1:seo.h1||form.productName,canonicalUrl:seo.canonicalUrl||`/products/${form.slug}`,robots:seo.robots,ogTitle:seo.ogTitle,ogDescription:seo.ogDescription,ogImageUrl:seo.ogImageUrl,structuredData:null,status:form.status,headings});setNotice('产品与 SEO 已保存');if(!productCode)setTimeout(onBack,500)}catch(e){setNotice(e instanceof Error?e.message:'保存失败')}finally{setSaving(false)}};
|
const save=async()=>{if(!editor)return;try{setSaving(true);setNotice('');const result=await post('/products/save',{productCode,siteCode:SITE,primaryCategoryCode:form.primaryCategoryCode,productName:form.productName,slug:form.slug,model:form.model,summary:form.summary,productContent:normalizeRichTextHtml(editor.getHTML()),coverMediaCode:form.coverMediaCode,featured:form.featured,inquiryEnabled:form.inquiryEnabled,sortNo:form.sortNo,status:form.status,specifications,attributes});await post('/seo/save',{siteCode:SITE,pageType:'PRODUCT_DETAIL',targetCode:result.productCode,title:seo.title||form.productName,description:seo.description||form.summary,keywords:seo.keywords,h1:seo.h1||form.productName,canonicalUrl:seo.canonicalUrl||`/products/${form.slug}`,robots:seo.robots,ogTitle:seo.ogTitle,ogDescription:seo.ogDescription,ogImageUrl:seo.ogImageUrl,structuredData:null,status:form.status,headings});setNotice('产品与 SEO 已保存');if(!productCode)setTimeout(onBack,500)}catch(e){setNotice(e instanceof Error?e.message:'保存失败')}finally{setSaving(false)}};
|
||||||
const addLink=()=>{const href=window.prompt('请输入链接地址');if(href)editor?.chain().focus().setLink({href}).run()};const addImage=()=>{const src=window.prompt('请输入图片地址');if(src)editor?.chain().focus().setImage({src}).run()};
|
const addLink=()=>{const href=window.prompt('请输入链接地址');if(href)editor?.chain().focus().setLink({href}).run()};const addImage=()=>{const src=window.prompt('请输入图片地址');if(src)editor?.chain().focus().setImage({src}).run()};
|
||||||
return <div className="product-editor"><div className="editor-top"><div className="breadcrumb-title"><button className="back" onClick={onBack}><ArrowLeft size={17}/>产品管理</button><span>/</span><h1>{productCode?'编辑产品':'新增产品'}</h1>{notice&&<em>{notice}</em>}</div><div className="editor-actions"><button onClick={onBack}>取消</button><button className="primary" disabled={saving||!form.productName||!form.slug} onClick={save}><Save size={16}/>{saving?'保存中':'保存'}</button></div></div><div className="editor-layout"><div className="editor-main">
|
return <div className="product-editor"><div className="editor-top"><div className="breadcrumb-title"><button className="back" onClick={onBack}><ArrowLeft size={17}/>产品管理</button><span>/</span><h1>{productCode?'编辑产品':'新增产品'}</h1>{notice&&<em>{notice}</em>}</div><div className="editor-actions"><button onClick={onBack}>取消</button><button className="primary" disabled={saving||!form.productName||!form.slug} onClick={save}><Save size={16}/>{saving?'保存中':'保存'}</button></div></div><div className="editor-layout"><div className="editor-main">
|
||||||
<section className="edit-section"><h2>基础信息</h2><div className="edit-grid"><Field label="产品标题 *"><input value={form.productName} onChange={e=>setForm({...form,productName:e.target.value})}/></Field><Field label="英文路径 *"><input value={form.slug} onChange={e=>setForm({...form,slug:e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,'-')})}/></Field><Field label="产品分类"><select disabled={categoriesLoading||Boolean(categoriesError)} value={form.primaryCategoryCode} onChange={e=>setForm({...form,primaryCategoryCode:e.target.value})}><option value="">{categoriesLoading?'分类加载中...':categoriesError||'请选择'}</option>{categories.map(category=><option key={category.categoryCode} value={category.categoryCode}>{`${' '.repeat(category.depth)}${category.categoryName}`}</option>)}</select></Field><Field label="产品型号"><input value={form.model||''} onChange={e=>setForm({...form,model:e.target.value})}/></Field><Field label="排序"><input type="number" value={form.sortNo} onChange={e=>setForm({...form,sortNo:Number(e.target.value)})}/></Field><Field wide label="产品简介 *"><textarea rows={4} value={form.summary||''} onChange={e=>setForm({...form,summary:e.target.value})}/></Field></div></section>
|
<section className="edit-section"><h2>基础信息</h2><div className="edit-grid"><Field label="产品标题 *"><input value={form.productName} onChange={e=>setForm({...form,productName:e.target.value})}/></Field><Field label="英文路径 *"><input value={form.slug} onChange={e=>setForm({...form,slug:e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,'-')})}/></Field><Field label="产品分类"><select disabled={categoriesLoading||Boolean(categoriesError)} value={form.primaryCategoryCode} onChange={e=>setForm({...form,primaryCategoryCode:e.target.value})}><option value="">{categoriesLoading?'分类加载中...':categoriesError||'请选择'}</option>{categories.map(category=><option key={category.categoryCode} value={category.categoryCode}>{`${' '.repeat(category.depth)}${category.categoryName}`}</option>)}</select></Field><Field label="产品型号"><input value={form.model||''} onChange={e=>setForm({...form,model:e.target.value})}/></Field><Field label="排序"><input type="number" value={form.sortNo} onChange={e=>setForm({...form,sortNo:Number(e.target.value)})}/></Field><Field wide label="产品简介 *"><textarea rows={4} value={form.summary||''} onChange={e=>setForm({...form,summary:e.target.value})}/></Field></div></section>
|
||||||
|
|||||||
@@ -436,4 +436,5 @@ header p {
|
|||||||
.shell > main > header > div > p,.content-page > header > div > p,.category-heading p,.navigation-editor-title p,.navigation-manager > header p,.account-settings > header p,.seo-settings-heading p,.agreement-top p{display:none}
|
.shell > main > header > div > p,.content-page > header > div > p,.category-heading p,.navigation-editor-title p,.navigation-manager > header p,.account-settings > header p,.seo-settings-heading p,.agreement-top p{display:none}
|
||||||
.product-cover-section .cover-upload{min-height:140px;grid-template-columns:120px minmax(0,1fr);grid-template-rows:auto auto auto;align-content:center;justify-content:center;column-gap:18px;row-gap:8px;padding:16px 24px}.product-cover-section .cover-upload>svg,.product-cover-section .cover-upload>img{grid-column:1;grid-row:1/-1;justify-self:center}.product-cover-section .cover-upload>img{width:120px;height:120px;object-fit:contain}.product-cover-section .cover-upload label{grid-column:2;grid-row:1;align-self:end}.product-cover-section .cover-upload p{grid-column:2;grid-row:2}.product-cover-section .cover-upload .upload-notice{grid-column:2;grid-row:3}.product-cover-section .cover-upload label,.product-cover-section .cover-upload p,.product-cover-section .cover-upload .upload-notice{justify-self:start;text-align:left}
|
.product-cover-section .cover-upload{min-height:140px;grid-template-columns:120px minmax(0,1fr);grid-template-rows:auto auto auto;align-content:center;justify-content:center;column-gap:18px;row-gap:8px;padding:16px 24px}.product-cover-section .cover-upload>svg,.product-cover-section .cover-upload>img{grid-column:1;grid-row:1/-1;justify-self:center}.product-cover-section .cover-upload>img{width:120px;height:120px;object-fit:contain}.product-cover-section .cover-upload label{grid-column:2;grid-row:1;align-self:end}.product-cover-section .cover-upload p{grid-column:2;grid-row:2}.product-cover-section .cover-upload .upload-notice{grid-column:2;grid-row:3}.product-cover-section .cover-upload label,.product-cover-section .cover-upload p,.product-cover-section .cover-upload .upload-notice{justify-self:start;text-align:left}
|
||||||
.specification-row{display:grid;grid-template-columns:minmax(150px,.85fr) minmax(280px,1.65fr) minmax(130px,.7fr) minmax(110px,.55fr) 42px;gap:12px;align-items:end;padding:14px 0;border-top:1px solid #edf0f2}.specification-row label{display:grid;gap:7px;min-width:0}.specification-row label>span{font-size:12px;font-weight:600;color:#53616b}.specification-row input{box-sizing:border-box;border:1px solid #d8dee3;border-radius:5px;padding:10px 12px;font:inherit;width:100%}.specification-row button{height:43px;border:1px solid #ead6d6;background:#fff;color:#a93636;border-radius:5px;display:inline-grid;place-items:center;cursor:pointer}.specification-empty{border:1px dashed #d8dee3;border-radius:5px;padding:26px;text-align:center;color:#81908b;font-size:13px}
|
.specification-row{display:grid;grid-template-columns:minmax(150px,.85fr) minmax(280px,1.65fr) minmax(130px,.7fr) minmax(110px,.55fr) 42px;gap:12px;align-items:end;padding:14px 0;border-top:1px solid #edf0f2}.specification-row label{display:grid;gap:7px;min-width:0}.specification-row label>span{font-size:12px;font-weight:600;color:#53616b}.specification-row input{box-sizing:border-box;border:1px solid #d8dee3;border-radius:5px;padding:10px 12px;font:inherit;width:100%}.specification-row button{height:43px;border:1px solid #ead6d6;background:#fff;color:#a93636;border-radius:5px;display:inline-grid;place-items:center;cursor:pointer}.specification-empty{border:1px dashed #d8dee3;border-radius:5px;padding:26px;text-align:center;color:#81908b;font-size:13px}
|
||||||
|
.pv-product-detail{padding:44px 5%;display:grid;grid-template-columns:minmax(0,1.05fr) minmax(300px,.95fr);gap:34px;align-items:start}.pv-product-image{aspect-ratio:1/1;background:#eef2f0;display:grid;place-items:center;color:#899691;overflow:hidden}.pv-product-image img{width:100%;height:100%;object-fit:contain}.pv-product-detail>div:nth-child(2)>span{font-size:11px;font-weight:800;color:#176b5d}.pv-product-detail h1{font-size:34px;line-height:1.12;margin:12px 0 18px}.pv-product-detail small{display:block;border-block:1px solid #dce2df;padding:10px 0}.pv-product-detail p{line-height:1.65;color:#61706b}.pv-product-detail button{border:0;color:#fff;padding:12px 20px;font-weight:700;margin-top:10px}.pv-product-detail dl{grid-column:1/-1;margin:8px 0 0;border-top:2px solid #203630}.pv-product-detail dl>div{display:flex;justify-content:space-between;padding:10px 0;border-bottom:1px solid #dce2df}.pv-product-detail dt,.pv-product-detail dd{margin:0;font-size:12px}.preview-frame[style*="390px"] .pv-product-detail{grid-template-columns:1fr;padding:28px 20px}.preview-frame[style*="390px"] .pv-product-detail h1{font-size:27px}
|
||||||
@media(max-width:900px){.specification-row{grid-template-columns:1fr 1fr}.specification-values{grid-column:1/-1}.specification-row button{grid-column:2;justify-self:end;width:42px}}
|
@media(max-width:900px){.specification-row{grid-template-columns:1fr 1fr}.specification-values{grid-column:1/-1}.specification-row button{grid-column:2;justify-self:end;width:42px}}
|
||||||
+64
-9
@@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import { ArrowRight, ChevronRight, Mail, Menu, Search } from "lucide-react";
|
import { ArrowRight, ChevronRight, Image as ImageIcon, Mail, Menu, Search } from "lucide-react";
|
||||||
import "./styles.css";
|
import "./styles.css";
|
||||||
import { initializeAnalytics, routePageCode, trackInquirySubmitted, trackPageLeave, trackPageView } from "./analytics";
|
import { initializeAnalytics, routePageCode, trackInquirySubmitted, trackPageLeave, trackPageView } from "./analytics";
|
||||||
|
|
||||||
@@ -47,6 +47,7 @@ type SeoData = {
|
|||||||
ogImageUrl?: string;
|
ogImageUrl?: string;
|
||||||
structuredData?: string;
|
structuredData?: string;
|
||||||
};
|
};
|
||||||
|
function assetUrl(url?: string): string { return url || ""; }
|
||||||
async function post(path: string, body: unknown) {
|
async function post(path: string, body: unknown) {
|
||||||
const r = await fetch(API + path, {
|
const r = await fetch(API + path, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -57,6 +58,23 @@ async function post(path: string, body: unknown) {
|
|||||||
throw new Error((await r.json()).message || "Unable to load content");
|
throw new Error((await r.json()).message || "Unable to load content");
|
||||||
return r.json();
|
return r.json();
|
||||||
}
|
}
|
||||||
|
/** 兼容历史数据中被转义后保存的富文本标签。 */
|
||||||
|
function normalizeRichTextHtml(content?: string): string {
|
||||||
|
if (!content || !/&(?:amp;)?lt;\/?(?:h[1-6]|p|ul|ol|li|blockquote|table|img|a)\b/i.test(content)) return content || "";
|
||||||
|
const decoder = document.createElement("textarea");
|
||||||
|
let decoded = content;
|
||||||
|
for (let index = 0; index < 2; index += 1) {
|
||||||
|
decoder.innerHTML = decoded;
|
||||||
|
const next = decoder.value;
|
||||||
|
if (next === decoded) break;
|
||||||
|
decoded = next;
|
||||||
|
}
|
||||||
|
decoded = decoded.replace(/^\s*<pre><code>/i, "").replace(/<\/code><\/pre>(?:<p><\/p>)?\s*$/i, "");
|
||||||
|
if (!/<\/?(?:h[1-6]|p|ul|ol|li|blockquote|table|img|a)\b/i.test(decoded)) return content;
|
||||||
|
const container = document.createElement("div");
|
||||||
|
container.innerHTML = decoded;
|
||||||
|
return container.innerHTML;
|
||||||
|
}
|
||||||
function setMeta(name: string, content?: string) {
|
function setMeta(name: string, content?: string) {
|
||||||
const selector = `meta[name="${name}"]`;
|
const selector = `meta[name="${name}"]`;
|
||||||
let element = document.head.querySelector<HTMLMetaElement>(selector);
|
let element = document.head.querySelector<HTMLMetaElement>(selector);
|
||||||
@@ -204,11 +222,22 @@ function LiveSection({section}:{section:DecorationSection}) {
|
|||||||
if(section.type==="HEADER")return <LiveHeader style={style}/>;
|
if(section.type==="HEADER")return <LiveHeader style={style}/>;
|
||||||
if(section.type==="HERO")return <section className="live-hero" style={{...style,backgroundImage:section.imageUrl?`linear-gradient(90deg,rgba(0,0,0,.72),rgba(0,0,0,.12)),url(${section.imageUrl})`:undefined}}><div><p>ENGINEERED FOR INDUSTRY</p><h1>{section.title}</h1><span>{section.subtitle}</span>{section.buttonText&&<a href={section.buttonUrl||"#"}>{section.buttonText}<ArrowRight size={17}/></a>}</div></section>;
|
if(section.type==="HERO")return <section className="live-hero" style={{...style,backgroundImage:section.imageUrl?`linear-gradient(90deg,rgba(0,0,0,.72),rgba(0,0,0,.12)),url(${section.imageUrl})`:undefined}}><div><p>ENGINEERED FOR INDUSTRY</p><h1>{section.title}</h1><span>{section.subtitle}</span>{section.buttonText&&<a href={section.buttonUrl||"#"}>{section.buttonText}<ArrowRight size={17}/></a>}</div></section>;
|
||||||
if(section.type==="RICH_TEXT")return <section className="live-rich" style={style}><h2>{section.title}</h2><p>{section.subtitle}</p></section>;
|
if(section.type==="RICH_TEXT")return <section className="live-rich" style={style}><h2>{section.title}</h2><p>{section.subtitle}</p></section>;
|
||||||
|
if(section.type==="PRODUCT_DETAIL")return <RuntimeProductDetail/>;
|
||||||
if(section.type==="PRODUCTS"||section.type==="CONTENT")return <LiveCollection section={section}/>;
|
if(section.type==="PRODUCTS"||section.type==="CONTENT")return <LiveCollection section={section}/>;
|
||||||
if(section.type==="INQUIRY")return <section className="live-inquiry" style={style}><div><p>START A PROJECT</p><h2>{section.title}</h2><span>{section.subtitle}</span></div><InquiryForm scene="GENERAL"/></section>;
|
if(section.type==="INQUIRY")return <section className="live-inquiry" style={style}><div><p>START A PROJECT</p><h2>{section.title}</h2><span>{section.subtitle}</span></div><InquiryForm scene="GENERAL"/></section>;
|
||||||
if(section.type==="FOOTER")return <footer className="live-footer" style={style}><div><b>SHOPLIX</b><p>Industrial Solutions</p></div><div><b>Explore</b><a href="/products">Products</a><a href="/cases">Cases</a><a href="/news">News</a></div><div><b>Company</b><a href="/about-us">About Us</a><a href="/contact-us">Contact Us</a><a href="/privacy-policy">Privacy Policy</a></div><small>{section.subtitle||"Copyright © 2026. All rights reserved."}</small></footer>;
|
if(section.type==="FOOTER")return <footer className="live-footer" style={style}><div><b>SHOPLIX</b><p>Industrial Solutions</p></div><div><b>Explore</b><a href="/products">Products</a><a href="/cases">Cases</a><a href="/news">News</a></div><div><b>Company</b><a href="/about-us">About Us</a><a href="/contact-us">Contact Us</a><a href="/privacy-policy">Privacy Policy</a></div><small>{section.subtitle||"Copyright © 2026. All rights reserved."}</small></footer>;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
/** 装修模板中的产品详情组件,按当前访问路径加载真实商品。 */
|
||||||
|
function RuntimeProductDetail() {
|
||||||
|
const slug = route().slug;
|
||||||
|
const [product, setProduct] = useState<Record<string, any>>();
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
useEffect(() => { if (!slug) return; post("/products/detail", { slug }).then(setProduct).catch((reason) => setError(reason instanceof Error ? reason.message : "Unable to load product")); }, [slug]);
|
||||||
|
if (error) return <ErrorState message={error}/>;
|
||||||
|
if (!product) return <div className="loading">Loading product…</div>;
|
||||||
|
return <ProductDetailView data={product}/>;
|
||||||
|
}
|
||||||
/** 装修页面使用的动态页头。 */
|
/** 装修页面使用的动态页头。 */
|
||||||
function LiveHeader({ style }: { style: React.CSSProperties }) {
|
function LiveHeader({ style }: { style: React.CSSProperties }) {
|
||||||
const items = useNavigation("HEADER");
|
const items = useNavigation("HEADER");
|
||||||
@@ -218,7 +247,7 @@ function LiveCollection({section}:{section:DecorationSection}) {
|
|||||||
const [items,setItems]=useState<Item[]>([]);
|
const [items,setItems]=useState<Item[]>([]);
|
||||||
useEffect(()=>{const path=section.type==="PRODUCTS"?"/products/list":"/contents/list";const body=section.type==="PRODUCTS"?{}:{contentType:section.sourceType||"CASE"};post(path,body).then(data=>setItems((data.items||[]).slice(0,section.limit||3))).catch(()=>setItems([]))},[section.type,section.sourceType,section.limit]);
|
useEffect(()=>{const path=section.type==="PRODUCTS"?"/products/list":"/contents/list";const body=section.type==="PRODUCTS"?{}:{contentType:section.sourceType||"CASE"};post(path,body).then(data=>setItems((data.items||[]).slice(0,section.limit||3))).catch(()=>setItems([]))},[section.type,section.sourceType,section.limit]);
|
||||||
const base=section.type==="PRODUCTS"?"products":(section.sourceType||"CASE").toLowerCase();
|
const base=section.type==="PRODUCTS"?"products":(section.sourceType||"CASE").toLowerCase();
|
||||||
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={`http://localhost:8082${item.coverMediaUrl}`} alt={item.productName||item.title}/>}</div><span>{section.type==="PRODUCTS"?"PRODUCT":section.sourceType}</span><h3>{item.productName||item.title}</h3><p>{item.summary}</p></a>)}</div></section>;
|
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}/>}</div><span>{section.type==="PRODUCTS"?"PRODUCT":section.sourceType}</span><h3>{item.productName||item.title}</h3><p>{item.summary}</p></a>)}</div></section>;
|
||||||
}
|
}
|
||||||
function Header() {
|
function Header() {
|
||||||
const items = useNavigation("HEADER");
|
const items = useNavigation("HEADER");
|
||||||
@@ -338,17 +367,17 @@ function Collection({
|
|||||||
if (error) return <ErrorState message={error} />;
|
if (error) return <ErrorState message={error} />;
|
||||||
if (slug && !Array.isArray(data)) {
|
if (slug && !Array.isArray(data)) {
|
||||||
const d = data as Record<string, any>;
|
const d = data as Record<string, any>;
|
||||||
|
if (type === "products") return <ProductDetailView data={d}/>;
|
||||||
return (
|
return (
|
||||||
<article className="detail">
|
<article className="detail">
|
||||||
<Crumbs current={String(d.productName || d.title || title)} />
|
<Crumbs current={String(d.productName || d.title || title)} />
|
||||||
<p className="eyebrow">{title.toUpperCase()}</p>
|
<p className="eyebrow">{title.toUpperCase()}</p>
|
||||||
<h1>{d.productName || d.title}</h1>
|
<h1>{d.productName || d.title}</h1>
|
||||||
<p className="lead">{d.summary}</p>
|
<p className="lead">{d.summary}</p>
|
||||||
{d.coverMediaUrl && <img className="product-cover" src={`http://localhost:8082${d.coverMediaUrl}`} alt={d.productName || d.title}/>}
|
|
||||||
{d.attributes?.length > 0 && <section className="specs"><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>}
|
{d.attributes?.length > 0 && <section className="specs"><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
|
<div
|
||||||
className="content"
|
className="content"
|
||||||
dangerouslySetInnerHTML={{ __html: d.content || "" }}
|
dangerouslySetInnerHTML={{ __html: normalizeRichTextHtml(d.content) }}
|
||||||
/>
|
/>
|
||||||
{d.specifications?.length > 0 && (
|
{d.specifications?.length > 0 && (
|
||||||
<section className="specs">
|
<section className="specs">
|
||||||
@@ -366,9 +395,6 @@ function Collection({
|
|||||||
))}
|
))}
|
||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
{type === "products" && d.inquiryEnabled && (
|
|
||||||
<InquiryForm scene="PRODUCT" sourceCode={d.productCode} />
|
|
||||||
)}
|
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -393,7 +419,12 @@ function Collection({
|
|||||||
key={item.productCode || item.contentCode}
|
key={item.productCode || item.contentCode}
|
||||||
>
|
>
|
||||||
<div className="thumb">
|
<div className="thumb">
|
||||||
{item.coverMediaUrl && <img src={`http://localhost:8082${item.coverMediaUrl}`} alt={item.productName || item.title}/>}
|
{item.coverMediaUrl && (
|
||||||
|
<img
|
||||||
|
src={assetUrl(item.coverMediaUrl)}
|
||||||
|
alt={item.productName || item.title}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<span>{type === "products" ? "PRODUCT" : type}</span>
|
<span>{type === "products" ? "PRODUCT" : type}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -414,6 +445,30 @@ function Collection({
|
|||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/** B2B 商品详情主体,集中展示主图、核心信息、参数、详情和询盘入口。 */
|
||||||
|
function ProductDetailView({ data: d }: { data: Record<string, any> }) {
|
||||||
|
return <article className="detail product-detail">
|
||||||
|
<Crumbs current={String(d.productName || "Product")}/>
|
||||||
|
<section className="product-overview">
|
||||||
|
<div className="product-media">
|
||||||
|
{d.coverMediaUrl
|
||||||
|
? <img src={assetUrl(d.coverMediaUrl)} alt={d.productName || "Product image"}/>
|
||||||
|
: <div className="product-image-placeholder"><ImageIcon size={48}/><span>Product image coming soon</span></div>}
|
||||||
|
</div>
|
||||||
|
<div className="product-summary">
|
||||||
|
<p className="eyebrow">PRODUCT</p>
|
||||||
|
<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>}
|
||||||
|
</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>}
|
||||||
|
</article>;
|
||||||
|
}
|
||||||
function Page({ slug }: { slug: string }) {
|
function Page({ slug }: { slug: string }) {
|
||||||
if (slug === "contact-us")
|
if (slug === "contact-us")
|
||||||
return (
|
return (
|
||||||
@@ -588,7 +643,7 @@ function InquiryForm({
|
|||||||
/>
|
/>
|
||||||
{uploadingField === field.fieldCode && <small>Uploading…</small>}
|
{uploadingField === field.fieldCode && <small>Uploading…</small>}
|
||||||
{custom[field.fieldCode] && (
|
{custom[field.fieldCode] && (
|
||||||
<img src={`http://localhost:8082${custom[field.fieldCode]}`} alt={field.label}/>
|
<img src={assetUrl(custom[field.fieldCode])} alt={field.label}/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : field.fieldType === "TEXTAREA" ? (
|
) : field.fieldType === "TEXTAREA" ? (
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ nav a:hover {
|
|||||||
padding-bottom: 32px;
|
padding-bottom: 32px;
|
||||||
}
|
}
|
||||||
.product-cover { width: 100%; max-height: 560px; object-fit: contain; background: #f4f6f5; margin: 20px 0 35px; }
|
.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-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-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 28px;font-size:17px;line-height:1.75}.product-model{display:inline-flex;gap:10px;align-items:center;border-top:1px solid #d7dfdc;border-bottom:1px solid #d7dfdc;padding:12px 0;width:100%;font-size:13px;color:#687579}.product-model strong{color:#17211f}.product-inquiry-cta{display:inline-flex;align-items:center;justify-content:center;gap:9px;background:#176b5b;color:#fff;text-decoration:none;padding:14px 22px;min-width:190px;font-size:14px;font-weight:700}.product-attributes{margin-top:65px}.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 #product-inquiry{scroll-margin-top:24px}
|
||||||
.content {
|
.content {
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
margin-top: 35px;
|
margin-top: 35px;
|
||||||
@@ -425,6 +426,7 @@ footer small {
|
|||||||
.detail h1 {
|
.detail h1 {
|
||||||
font-size: 42px;
|
font-size: 42px;
|
||||||
}
|
}
|
||||||
|
.product-overview{grid-template-columns:1fr;gap:24px}.product-summary{padding:0}.product-summary h1{font-size:36px}.product-inquiry-cta{width:100%;box-sizing:border-box}.product-attributes{margin-top:45px}.product-content{margin-top:40px}
|
||||||
footer {
|
footer {
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user