Product expertise
Clear technical parameters and application-focused recommendations.
import React, { useEffect, useState } from "react"; import { createRoot } from "react-dom/client"; import { ArrowRight, ChevronRight, Image as ImageIcon, Mail, Menu, Search, X } from "lucide-react"; import "./styles.css"; import { initializeAnalytics, routePageCode, trackInquirySubmitted, trackPageLeave, trackPageView } from "./analytics"; const API = import.meta.env.VITE_SITE_API_BASE || "/api/site/v1"; type ContentType = "NEWS" | "CASE" | "HELP"; type Item = { productCode?: string; contentCode?: string; productName?: string; title?: string; slug: string; summary?: string; model?: string; publishTime?: number; coverMediaUrl?: string; }; type InquiryField = { fieldCode: string; fieldKey: string; label: string; fieldType: string; placeholder?: string; helpText?: string; maxLength?: number; required: boolean; optionsJson?: string; widthType: string; }; type InquiryFormData = { formCode: string; description?: string; submitButtonText: string; successMessage: string; fields: InquiryField[]; }; type SeoData = { title: string; description?: string; keywords?: string; canonicalUrl?: string; robots?: string; ogTitle?: string; ogDescription?: string; ogImageUrl?: string; structuredData?: string; }; function assetUrl(url?: string): string { return url || ""; } async function post(path: string, body: unknown) { const r = await fetch(API + path, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); if (!r.ok) throw new Error((await r.json()).message || "Unable to load content"); return r.json(); } const RICH_TEXT_ALLOWED_TAGS = new Set([ "A", "B", "BLOCKQUOTE", "BR", "CODE", "EM", "H2", "H3", "H4", "HR", "I", "IMG", "LI", "OL", "P", "PRE", "S", "STRONG", "TABLE", "TBODY", "TD", "TH", "THEAD", "TR", "U", "UL", ]); const RICH_TEXT_REMOVED_TAGS = new Set(["BUTTON", "EMBED", "FORM", "IFRAME", "INPUT", "OBJECT", "SCRIPT", "STYLE"]); /** 判断富文本链接或图片地址是否为可安全输出的站内、HTTP 或 HTTPS 地址。 */ function isSafeRichTextUrl(value: string): boolean { const normalized = value.trim().replace(/[\u0000-\u0020]+/g, "").toLowerCase(); return normalized.startsWith("/") || normalized.startsWith("#") || normalized.startsWith("http://") || normalized.startsWith("https://") || normalized.startsWith("mailto:") || normalized.startsWith("tel:"); } /** 清理富文本节点,仅保留前台展示所需的安全标签和属性。 */ function sanitizeRichTextHtml(content: string): string { const container = document.createElement("div"); container.innerHTML = content; Array.from(container.querySelectorAll("*")).forEach((element) => { if (RICH_TEXT_REMOVED_TAGS.has(element.tagName)) { element.remove(); return; } if (!RICH_TEXT_ALLOWED_TAGS.has(element.tagName)) { element.replaceWith(...Array.from(element.childNodes)); return; } Array.from(element.attributes).forEach((attribute) => { const allowed = element.tagName === "A" && ["href", "target", "rel"].includes(attribute.name) || element.tagName === "IMG" && ["src", "alt", "title"].includes(attribute.name) || ["TD", "TH"].includes(element.tagName) && ["colspan", "rowspan"].includes(attribute.name); if (!allowed) element.removeAttribute(attribute.name); }); if (element instanceof HTMLAnchorElement) { if (!isSafeRichTextUrl(element.getAttribute("href") || "")) element.removeAttribute("href"); if (element.target === "_blank") element.rel = "noopener noreferrer"; } if (element instanceof HTMLImageElement && !isSafeRichTextUrl(element.getAttribute("src") || "")) { element.removeAttribute("src"); } }); return container.innerHTML; } /** 兼容历史数据中被转义后保存的富文本标签,并统一执行安全清理。 */ function normalizeRichTextHtml(content?: string): string { if (!content) return ""; const decoder = document.createElement("textarea"); let decoded = content; if (/&(?:amp;)?lt;\/?(?:h[1-6]|p|ul|ol|li|blockquote|table|img|a)\b/i.test(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*
/i, "").replace(/<\/code><\/pre>(?:<\/p>)?\s*$/i, "");
return sanitizeRichTextHtml(decoded);
}
function setMeta(name: string, content?: string) {
const selector = `meta[name="${name}"]`;
let element = document.head.querySelector(selector);
if (!content) { element?.remove(); return; }
if (!element) { element = document.createElement("meta"); element.name = name; document.head.appendChild(element); }
element.content = content;
}
function setProperty(property: string, content?: string) {
const selector = `meta[property="${property}"]`;
let element = document.head.querySelector(selector);
if (!content) { element?.remove(); return; }
if (!element) { element = document.createElement("meta"); element.setAttribute("property", property); document.head.appendChild(element); }
element.content = content;
}
function applySeo(data?: SeoData) {
const canonicalValue = data?.canonicalUrl || `${location.origin}${location.pathname}`;
const canonical = new URL(canonicalValue, location.origin).href;
if (data?.title) document.title = data.title;
setMeta("description", data?.description);
setMeta("keywords", data?.keywords);
setMeta("robots", data?.robots || "index,follow");
let link = document.head.querySelector('link[rel="canonical"]');
if (!link) { link = document.createElement("link"); link.rel = "canonical"; document.head.appendChild(link); }
link.href = canonical;
setProperty("og:title", data?.ogTitle || data?.title);
setProperty("og:description", data?.ogDescription || data?.description);
setProperty("og:image", data?.ogImageUrl ? new URL(data.ogImageUrl, location.origin).href : undefined);
setProperty("og:url", canonical);
let structuredData = document.head.querySelector('script[data-shoplix-seo="json-ld"]');
structuredData?.remove();
if (data?.structuredData) {
structuredData = document.createElement("script"); structuredData.type = "application/ld+json";
structuredData.dataset.shoplixSeo = "json-ld"; structuredData.text = data.structuredData;
document.head.appendChild(structuredData);
}
}
function usePageSeo(pageType: string, targetCode = "") {
useEffect(() => {
let active = true;
applySeo();
if (!pageType) return () => { active = false; };
post("/seo/detail", { pageType, targetCode })
.then((data: SeoData) => { if (active) applySeo(data); })
.catch(() => undefined);
return () => { active = false; };
}, [pageType, targetCode]);
}
const nav = [
["Products", "/products"],
["Cases", "/cases"],
["News", "/news"],
["Help", "/help"],
["About", "/about-us"],
];
type NavigationItem = { title: string; url: string; openType: "CURRENT" | "NEW"; children: NavigationItem[] };
/** 读取已发布导航,没有配置时返回既有默认菜单。 */
function useNavigation(position: "HEADER" | "FOOTER"): NavigationItem[] {
const fallback = nav.map(([title, url]) => ({ title, url, openType: "CURRENT" as const, children: [] }));
const [items, setItems] = useState(fallback);
useEffect(() => {
let active = true;
post("/navigations/detail", { position })
.then((data) => { if (active && data.items?.length) setItems(data.items); })
.catch(() => undefined);
return () => { active = false; };
}, [position]);
return items;
}
/** 渲染支持二级菜单的前台导航链接。 */
function NavigationLinks({ items }: { items: NavigationItem[] }) {
return <>{items.map((item) => {item.title}{item.children?.length > 0 && {item.children.map((child) => {child.title})}})}>;
}
function route() {
const p = location.pathname.split("/").filter(Boolean);
const previewPage = new URLSearchParams(location.search).get("previewPage") || undefined;
if (!p.length) return { kind: "home", previewPage };
if (["products", "news", "cases", "help"].includes(p[0]))
return { kind: p[0], slug: p[1], previewPage };
return { kind: "page", slug: p[0], previewPage };
}
function App() {
const r = route();
useEffect(() => {
initializeAnalytics();
const context = { pageCode: routePageCode(), pageName: document.title, scene: r.kind };
trackPageView(context);
const leave = () => trackPageLeave(context);
window.addEventListener("pagehide", leave, { once: true });
return () => window.removeEventListener("pagehide", leave);
}, [r.kind, r.slug]);
const runtime = ;
const seoRuntime = ;
if (r.kind === "home") return <>{runtime}{seoRuntime} >} />>;
if (r.kind === "products") return <>{runtime}{seoRuntime} >} />>;
if (r.kind === "news") return <>{runtime}{seoRuntime} >} />>;
if (r.kind === "cases") return <>{runtime}{seoRuntime} >} />>;
if (r.kind === "help") return <>{runtime}{seoRuntime} >} />>;
return <>{runtime}{seoRuntime} >} />>;
}
function SeoRuntime({ current }: { current: ReturnType }) {
const [target, setTarget] = useState({ pageType: "", targetCode: "" });
useEffect(() => {
let active = true;
const listType = current.kind === "home" ? "HOME"
: current.kind === "products" && !current.slug ? "PRODUCT_LIST"
: current.kind === "news" && !current.slug ? "NEWS_LIST"
: current.kind === "cases" && !current.slug ? "CASE_LIST"
: current.kind === "help" && !current.slug ? "HELP_CATEGORY_LIST" : "";
if (listType) { setTarget({ pageType: listType, targetCode: "" }); return () => { active = false; }; }
setTarget({ pageType: "", targetCode: "" });
if (["products", "news", "cases", "help"].includes(current.kind) && current.slug) {
const product = current.kind === "products";
const contentType = current.kind === "cases" ? "CASE" : current.kind.toUpperCase();
post(product ? "/products/detail" : "/contents/detail", product ? { slug: current.slug } : { contentType, slug: current.slug })
.then(data => { if (active) setTarget({ pageType: product ? "PRODUCT_DETAIL" : `${contentType}_DETAIL`, targetCode: data.productCode || data.contentCode || "" }); })
.catch(() => undefined);
} else if (current.kind === "page" && current.slug) {
post("/pages/detail", { slug: current.slug })
.then(data => { if (active) setTarget({ pageType: data.pageType === "SYSTEM_PAGE" ? "SYSTEM_PAGE" : "CUSTOM_PAGE", targetCode: data.pageCode || "" }); })
.catch(() => undefined);
}
return () => { active = false; };
}, [current.kind, current.slug]);
usePageSeo(target.pageType, target.targetCode);
return null;
}
function CustomCodeRuntime() {
useEffect(() => { let nodes: HTMLElement[] = []; post("/custom-codes/list", { siteCode: "SIT0000000000001" }).then(data => { (data.items || []).forEach((item: { content: string; position: string }) => { const container = item.position === "HEAD" ? document.head : document.body; const wrapper = document.createElement("div"); wrapper.innerHTML = item.content; Array.from(wrapper.children).forEach(child => { let node: HTMLElement = child as HTMLElement; if (child.tagName === "SCRIPT") { const script = document.createElement("script"); Array.from(child.attributes).forEach(attribute => script.setAttribute(attribute.name, attribute.value)); script.text = child.textContent || ""; node = script; } container.insertBefore(node, item.position === "BODY_START" ? container.firstChild : null); nodes.push(node); }); }); }).catch(() => undefined); return () => nodes.forEach(node => node.remove()); }, []);
return null;
}
type DecorationSection = { id:string; type:string; title:string; subtitle:string; imageUrl:string; buttonText:string; buttonUrl:string; sourceType:string; limit:number; visible:boolean; background:string; textColor:string };
type DecorationSchema = { global:{primaryColor:string;backgroundColor:string;textColor:string;fontFamily:string;contentWidth:number};sections:DecorationSection[] };
function DecoratedPage({ pageType, fallback }: { pageType: string; fallback: React.ReactNode }) {
const [schema,setSchema]=useState(null); const [loaded,setLoaded]=useState(false);
useEffect(()=>{setLoaded(false);setSchema(null);post("/decorations/detail",{pageType}).then(data=>{if(data.schema)setSchema(JSON.parse(data.schema));setLoaded(true)}).catch(()=>setLoaded(true))},[pageType]);
if(!loaded) return Loading...;
if(!schema || !schema.sections?.length) return <>{fallback}>;
return {schema.sections.filter(section=>section.visible).map(section=>)} ;
}
function LiveSection({section}:{section:DecorationSection}) {
const style={background:section.background,color:section.textColor};
if(section.type==="ANNOUNCEMENT")return {section.title};
if(section.type==="HEADER")return ;
if(section.type==="HERO")return ;
if(section.type==="RICH_TEXT")return {section.title}
{section.subtitle}
;
if(section.type==="PRODUCT_DETAIL")return ;
if(section.type==="PRODUCTS"||section.type==="CONTENT")return ;
if(section.type==="INQUIRY")return START A PROJECT
{section.title}
{section.subtitle} ;
if(section.type==="FOOTER")return ;
return null;
}
/** 装修模板中的产品详情组件,按当前访问路径加载真实商品。 */
function RuntimeProductDetail() {
const slug = route().slug;
const [product, setProduct] = useState>();
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 ;
if (!product) return Loading product…;
return ;
}
/** 装修页面使用的动态页头。 */
function LiveHeader({ style }: { style: React.CSSProperties }) {
const items = useNavigation("HEADER");
return SHOPLIXGet a quote ;
}
function LiveCollection({section}:{section:DecorationSection}) {
const [items,setItems]=useState- ([]);
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();
return
FEATURED
{section.title}
;
}
function Header() {
const items = useNavigation("HEADER");
return (
SHOPLIX
Industrial Solutions
);
}
function Home() {
return (
<>
ENGINEERED FOR INDUSTRY
Reliable equipment for demanding operations.
Explore industrial products, application expertise and
project-proven solutions from a partner built for B2B delivery.
16+
Industries served
WHAT WE DELIVER
From technical selection to project delivery
01
Product expertise
Clear technical parameters and application-focused
recommendations.
02
Proven applications
Documented case studies for real industrial operating conditions.
03
Responsive support
Direct inquiry routing and practical help throughout your project.
>
);
}
function Collection({
title,
type,
slug,
}: {
title: string;
type: "products" | ContentType;
slug?: string;
}) {
const [data, setData] = useState- >([]);
const [error, setError] = useState("");
useEffect(() => {
const run = async () => {
try {
if (slug) {
setData(
await post(
type === "products" ? "/products/detail" : "/contents/detail",
type === "products" ? { slug } : { contentType: type, slug },
),
);
} else {
const x = await post(
type === "products" ? "/products/list" : "/contents/list",
type === "products" ? {} : { contentType: type },
);
setData(x.items || []);
}
} catch (e) {
setError(e instanceof Error ? e.message : "Unable to load");
}
};
void run();
}, [type, slug]);
if (error) return
;
if (slug && !Array.isArray(data)) {
const d = data as Record;
if (type === "products") return ;
return (
{title.toUpperCase()}
{d.productName || d.title}
{d.summary}
{d.attributes?.length > 0 && Product attributes
{d.attributes.map((a:any,i:number)=>{a.name}{a.value} {a.unit})} }
{d.specifications?.length > 0 && (
Technical specifications
{d.specifications.map((s: any, i: number) => (
{s.groupName && `${s.groupName} · `}
{s.name}
{s.value} {s.unit}
))}
)}
);
}
return (
KNOWLEDGE & SOLUTIONS
{title}
Explore our latest {title.toLowerCase()} and find the information you
need for your next project.
{(data as Item[]).map((item) => (
{item.coverMediaUrl && (
)}
{type === "products" ? "PRODUCT" : type}
{item.model || (item.publishTime ? new Date(item.publishTime).toLocaleDateString("en-CA") : "INSIGHT")}
{item.productName || item.title}
{item.summary || "Explore details and technical information."}
Read more
))}
);
}
/** B2B 商品详情主体,集中展示主图、核心信息、参数、详情和询盘入口。 */
function ProductDetailView({ data: d }: { data: Record }) {
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
{d.coverMediaUrl
?
: Product image coming soon }
PRODUCT
{d.productName}
{d.model && Model {d.model}}
{d.summary}
{d.inquiryEnabled && }
{d.attributes?.length > 0 && Product attributes
{d.attributes.map((a:any,i:number)=>{a.name}{a.value} {a.unit})} }
{d.specifications?.length > 0 && Technical specifications
{d.specifications.map((s:any,i:number)=>{s.groupName&&`${s.groupName} · `}{s.name}{s.value} {s.unit})} }
{d.inquiryEnabled && inquiryOpen && (
setInquiryOpen(false)}>
event.stopPropagation()}>
)}
;
}
function Page({ slug }: { slug: string }) {
if (slug === "contact-us")
return (
START A CONVERSATION
Tell us about your project.
Share your requirements and our team will respond with practical next
steps.
);
return ;
}
function ConfiguredPage({ slug }: { slug: string }) {
const [data, setData] = useState();
const [error, setError] = useState("");
useEffect(() => {
post("/pages/detail", { slug })
.then(setData)
.catch((e) => setError(e.message));
}, [slug]);
if (error) return ;
if (!data) return Loading…;
const agreementPage = ["COOKIE_POLICY", "PRIVACY_POLICY", "TERMS_OF_SERVICE"].includes(data.systemPageType);
return (
{agreementPage ? "LEGAL INFORMATION" : "COMPANY INFORMATION"}
{data.pageName}
{data.summary && {data.summary}
}
);
}
function InquiryForm({
scene,
sourceCode,
}: {
scene: "PRODUCT" | "CONTACT" | "GENERAL";
sourceCode?: string;
}) {
const [definition, setDefinition] = useState();
const [form, setForm] = useState({
name: "",
email: "",
phone: "",
company: "",
countryCode: "",
message: "",
privacyConsent: false,
website: "",
});
const [custom, setCustom] = useState>({});
const [busy, setBusy] = useState(false);
const [uploadingField, setUploadingField] = useState("");
const [notice, setNotice] = useState("");
useEffect(() => {
post("/inquiries/form-detail", { scene })
.then(setDefinition)
.catch((e) => setNotice(e.message));
}, [scene]);
const uploadImage = async (fieldCode: string, file?: File) => {
if (!file) return;
try {
setUploadingField(fieldCode);
setNotice("");
const body = new FormData();
body.append("file", file);
const response = await fetch(`${API}/inquiries/upload-image`, { method: "POST", body });
if (!response.ok) throw new Error((await response.json()).message || "Unable to upload image");
const result = await response.json();
setCustom((values) => ({ ...values, [fieldCode]: result.url }));
} catch (error) {
setNotice(error instanceof Error ? error.message : "Unable to upload image");
} finally {
setUploadingField("");
}
};
const submit = async (e: React.FormEvent) => {
e.preventDefault();
if (!definition) return;
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] || "",
})),
landingUrl: sessionStorage.getItem("landingUrl") || location.href,
});
trackInquirySubmitted(result.inquiryCode, scene);
setNotice(result.successMessage);
} catch (err) {
setNotice(
err instanceof Error ? err.message : "Unable to submit inquiry",
);
} finally {
setBusy(false);
}
};
if (!definition)
return (
Request information
{notice || "Loading inquiry form…"}
);
return (
REQUEST INFORMATION
Discuss your requirements
{definition.description && {definition.description}
}
);
}
function Crumbs({ current }: { current: string }) {
return (
);
}
function ErrorState({ message }: { message: string }) {
return (
CONTENT UNAVAILABLE
We could not load this page.
{message}
Return home
);
}
function Footer() {
return (
);
}
createRoot(document.getElementById("root")!).render(
,
);