Compare commits

..
2 Commits
Author SHA1 Message Date
张锐 7f4f62702a bug修复 2026-11-26 07:15:37 +08:00
张锐 288f8bb851 新增素材库图片选择弹窗 2026-11-26 00:53:15 +08:00
4 changed files with 1571 additions and 109 deletions

No files matched your search

+520 -36
View File
@@ -3,83 +3,567 @@ import { EditorContent, useEditor } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import Link from "@tiptap/extension-link";
import Image from "@tiptap/extension-image";
import { ArrowLeft, Bold, Heading2, Heading3, Image as ImageIcon, Italic, Link as LinkIcon, List, Plus, Redo2, Save, Trash2, Undo2 } from "lucide-react";
import {
ArrowLeft,
Bold,
Heading2,
Heading3,
Image as ImageIcon,
Italic,
Link as LinkIcon,
List,
Plus,
Redo2,
Save,
Trash2,
Undo2,
} from "lucide-react";
import { API, assetUrl } from "./api";
const SITE = "SIT0000000000001";
type ContentType = "NEWS" | "CASE" | "HELP";
type Heading = { level: number; text: string; sortNo: number };
type Props = { contentType: ContentType; contentCode?: string; onBack: () => void };
const META: Record<ContentType, { label: string; route: string; seoType: string }> = {
type Props = {
contentType: ContentType;
contentCode?: string;
onBack: () => void;
};
const META: Record<
ContentType,
{ label: string; route: string; seoType: string }
> = {
NEWS: { label: "新闻", route: "news", seoType: "NEWS_DETAIL" },
CASE: { label: "案例", route: "cases", seoType: "CASE_DETAIL" },
HELP: { label: "帮助", route: "help", seoType: "HELP_DETAIL" },
};
async function post(path: string, body: unknown) {
const response = await fetch(API + path, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
if (!response.ok) throw new Error((await response.json()).message || "请求失败");
const response = await fetch(API + path, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!response.ok)
throw new Error((await response.json()).message || "请求失败");
return response.json();
}
/** 新闻、案例和帮助共用的独立内容编辑页。 */
export default function ContentEditor({ contentType, contentCode, onBack }: Props) {
export default function ContentEditor({
contentType,
contentCode,
onBack,
}: Props) {
const meta = META[contentType];
const [form, setForm] = useState({ title: "", slug: "", summary: "", primaryCategoryCode: "", coverMediaCode: "", coverMediaUrl: "", authorName: "", sourceName: "", featured: false, sortNo: 30, status: "DRAFT" });
const [seo, setSeo] = useState({ title: "", description: "", keywords: "", h1: "", canonicalUrl: "", robots: "index,follow", ogTitle: "", ogDescription: "", ogImageUrl: "", status: "DRAFT" });
const [form, setForm] = useState({
title: "",
slug: "",
summary: "",
primaryCategoryCode: "",
coverMediaCode: "",
coverMediaUrl: "",
authorName: "",
sourceName: "",
featured: false,
sortNo: 30,
status: "DRAFT",
});
const [seo, setSeo] = useState({
title: "",
description: "",
keywords: "",
h1: "",
canonicalUrl: "",
robots: "index,follow",
ogTitle: "",
ogDescription: "",
ogImageUrl: "",
status: "DRAFT",
});
const [headings, setHeadings] = useState<Heading[]>([]);
const [saving, setSaving] = useState(false);
const [uploading, setUploading] = useState(false);
const [notice, setNotice] = useState("");
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(() => {
if (!contentCode) return;
post("/contents/detail", { siteCode: SITE, contentCode, contentType }).then((data) => {
post("/contents/detail", { siteCode: SITE, contentCode, contentType })
.then((data) => {
setForm({ ...data, coverMediaUrl: data.coverMediaUrl || "" });
editor?.commands.setContent(data.contentBody || "<p></p>");
}).catch((error) => setNotice(error.message));
post("/seo/detail", { siteCode: SITE, pageType: meta.seoType, targetCode: contentCode }).then((data) => {
setSeo({ title: data.title, description: data.description, keywords: data.keywords || "", h1: data.h1, canonicalUrl: data.canonicalUrl || "", robots: data.robots, ogTitle: data.ogTitle || "", ogDescription: data.ogDescription || "", ogImageUrl: data.ogImageUrl || "", status: data.status });
})
.catch((error) => setNotice(error.message));
post("/seo/detail", {
siteCode: SITE,
pageType: meta.seoType,
targetCode: contentCode,
})
.then((data) => {
setSeo({
title: data.title,
description: data.description,
keywords: data.keywords || "",
h1: data.h1,
canonicalUrl: data.canonicalUrl || "",
robots: data.robots,
ogTitle: data.ogTitle || "",
ogDescription: data.ogDescription || "",
ogImageUrl: data.ogImageUrl || "",
status: data.status,
});
setHeadings(data.headings || []);
}).catch(() => undefined);
})
.catch(() => undefined);
}, [contentCode, contentType, editor, meta.seoType]);
const upload = async (file?: File) => {
if (!file) return;
if (file.size > 10 * 1024 * 1024) { setNotice("图片不能超过 10MB"); 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.title); body.append("file", file);
const response = await fetch(API + "/media/upload-image", { method: "POST", body });
if (response.status === 413) throw new Error("图片超过服务器上传限制,请联系管理员调整 Nginx 上传上限");
if (!response.ok) throw new Error((await response.json().catch(() => ({}))).message || "上传失败");
setUploading(true);
setNotice("");
const body = new FormData();
body.append("siteCode", SITE);
body.append("altText", form.title);
body.append("file", file);
const response = await fetch(API + "/media/upload-image", {
method: "POST",
body,
});
if (response.status === 413)
throw new Error(
"图片超过服务器上传限制,请联系管理员调整 Nginx 上传上限",
);
if (!response.ok)
throw new Error(
(await response.json().catch(() => ({}))).message || "上传失败",
);
const data = await response.json();
setForm((current) => ({ ...current, coverMediaCode: data.mediaCode, coverMediaUrl: data.url }));
setForm((current) => ({
...current,
coverMediaCode: data.mediaCode,
coverMediaUrl: data.url,
}));
setNotice(`${meta.label}封面上传成功`);
} catch (error) { setNotice(error instanceof Error ? error.message : "上传失败"); }
finally { setUploading(false); if (coverInputRef.current) coverInputRef.current.value = ""; }
} catch (error) {
setNotice(error instanceof Error ? error.message : "上传失败");
} finally {
setUploading(false);
if (coverInputRef.current) coverInputRef.current.value = "";
}
};
const save = async () => {
if (!editor) return;
try {
setSaving(true); setNotice("");
const result = await post("/contents/save", { contentCode, siteCode: SITE, contentType, primaryCategoryCode: form.primaryCategoryCode, title: form.title, slug: form.slug, summary: form.summary, contentBody: editor.getHTML(), coverMediaCode: form.coverMediaCode, authorName: form.authorName, sourceName: form.sourceName, featured: form.featured, sortNo: form.sortNo, status: form.status });
await post("/seo/save", { siteCode: SITE, pageType: meta.seoType, targetCode: result.contentCode, title: seo.title || form.title, description: seo.description || form.summary, keywords: seo.keywords, h1: seo.h1 || form.title, canonicalUrl: seo.canonicalUrl || `/${meta.route}/${form.slug}`, robots: seo.robots, ogTitle: seo.ogTitle, ogDescription: seo.ogDescription, ogImageUrl: seo.ogImageUrl || form.coverMediaUrl, structuredData: null, status: form.status, headings });
setSaving(true);
setNotice("");
const result = await post("/contents/save", {
contentCode,
siteCode: SITE,
contentType,
primaryCategoryCode: form.primaryCategoryCode,
title: form.title,
slug: form.slug,
summary: form.summary,
contentBody: editor.getHTML(),
coverMediaCode: form.coverMediaCode,
authorName: form.authorName,
sourceName: form.sourceName,
featured: form.featured,
sortNo: form.sortNo,
status: form.status,
});
await post("/seo/save", {
siteCode: SITE,
pageType: meta.seoType,
targetCode: result.contentCode,
title: seo.title || form.title,
description: seo.description || form.summary,
keywords: seo.keywords,
h1: seo.h1 || form.title,
canonicalUrl: seo.canonicalUrl || `/${meta.route}/${form.slug}`,
robots: seo.robots,
ogTitle: seo.ogTitle,
ogDescription: seo.ogDescription,
ogImageUrl: seo.ogImageUrl || form.coverMediaUrl,
structuredData: null,
status: form.status,
headings,
});
setNotice(`${meta.label}与 SEO 已保存`);
if (!contentCode) setTimeout(onBack, 500);
} catch (error) { setNotice(error instanceof Error ? error.message : "保存失败"); } finally { setSaving(false); }
} catch (error) {
setNotice(error instanceof Error ? error.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}/>{meta.label}管理</button><span>/</span><h1>{contentCode ? `编辑${meta.label}` : `新增${meta.label}`}</h1>{notice&&<em>{notice}</em>}</div><div className="editor-actions"><button onClick={onBack}>取消</button><button className="primary" disabled={saving || !form.title || !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={`${meta.label}标题 *`}><input value={form.title} onChange={(event) => setForm({ ...form, title: event.target.value })}/></Field><Field label="英文路径 *"><input value={form.slug} onChange={(event) => setForm({ ...form, slug: event.target.value.toLowerCase().replace(/[^a-z0-9-]/g, "-") })}/></Field><Field label="作者"><input value={form.authorName || ""} onChange={(event) => setForm({ ...form, authorName: event.target.value })}/></Field><Field label="来源"><input value={form.sourceName || ""} onChange={(event) => setForm({ ...form, sourceName: event.target.value })}/></Field><Field label="排序"><input type="number" value={form.sortNo} onChange={(event) => setForm({ ...form, sortNo: Number(event.target.value) })}/></Field><Field wide label={`${meta.label}简介 *`}><textarea rows={4} value={form.summary || ""} onChange={(event) => setForm({ ...form, summary: event.target.value })}/></Field></div></section>
<section className="edit-section"><h2>{meta.label}封面</h2><div className="cover-upload">{form.coverMediaUrl ? <img src={assetUrl(form.coverMediaUrl)} alt={`${meta.label}封面预览`}/> : <ImageIcon size={42}/>}<label className={uploading ? "uploading" : ""}><span>{uploading ? "上传中..." : "选择图片"}</span><input ref={coverInputRef} disabled={uploading} type="file" accept=".jpg,.jpeg,.png,.webp,.gif,image/jpeg,image/png,image/webp,image/gif" onClick={(event) => { event.currentTarget.value = ""; }} onChange={(event) => void upload(event.currentTarget.files?.[0])}/></label><p>支持 JPG、PNG、WebP、GIF,单图不超过 10MB</p>{notice && <small className="upload-notice">{notice}</small>}</div></section>
<section className="edit-section"><h2>{meta.label}详情 *</h2><div className="rich-editor"><div className="rich-toolbar"><Tool title="撤销" onClick={() => editor?.chain().focus().undo().run()}><Undo2/></Tool><Tool title="重做" onClick={() => editor?.chain().focus().redo().run()}><Redo2/></Tool><Tool title="粗体" active={editor?.isActive("bold")} onClick={() => editor?.chain().focus().toggleBold().run()}><Bold/></Tool><Tool title="斜体" active={editor?.isActive("italic")} onClick={() => editor?.chain().focus().toggleItalic().run()}><Italic/></Tool><Tool title="二级标题" active={editor?.isActive("heading", { level: 2 })} onClick={() => editor?.chain().focus().toggleHeading({ level: 2 }).run()}><Heading2/></Tool><Tool title="三级标题" active={editor?.isActive("heading", { level: 3 })} onClick={() => editor?.chain().focus().toggleHeading({ level: 3 }).run()}><Heading3/></Tool><Tool title="项目列表" onClick={() => editor?.chain().focus().toggleBulletList().run()}><List/></Tool><Tool title="链接" onClick={addLink}><LinkIcon/></Tool><Tool title="插入图片" onClick={addImage}><ImageIcon/></Tool></div><EditorContent editor={editor}/></div></section>
</div><aside className="editor-side"><section className="edit-section"><h2>发布</h2><Field label="状态"><select value={form.status} onChange={(event) => setForm({ ...form, status: event.target.value })}><option value="DRAFT">草稿</option><option value="PUBLISHED">上架</option><option value="OFFLINE">下线</option></select></Field><label className="check"><input type="checkbox" checked={form.featured} onChange={(event) => setForm({ ...form, featured: event.target.checked })}/>推荐内容</label></section><section className="edit-section"><h2>搜索引擎优化</h2><Field label="SEO 标题"><input maxLength={70} value={seo.title} onChange={(event) => setSeo({ ...seo, title: event.target.value })}/></Field><Field label="SEO 描述"><textarea maxLength={160} rows={4} value={seo.description} onChange={(event) => setSeo({ ...seo, description: event.target.value })}/></Field><Field label="SEO 关键词"><input value={seo.keywords} onChange={(event) => setSeo({ ...seo, keywords: event.target.value })}/></Field><Field label="H1"><input maxLength={120} value={seo.h1} onChange={(event) => setSeo({ ...seo, h1: event.target.value })}/></Field><Field label="Canonical"><input value={seo.canonicalUrl} placeholder={`/${meta.route}/${form.slug}`} onChange={(event) => setSeo({ ...seo, canonicalUrl: event.target.value })}/></Field><div className="section-head"><h3>H2 / H3 标签</h3><button onClick={() => setHeadings([...headings, { level: 2, text: "", sortNo: headings.length }])}><Plus size={15}/></button></div>{headings.map((heading, index) => <div className="heading-row" key={index}><select value={heading.level} onChange={(event) => setHeadings(headings.map((item, position) => position === index ? { ...item, level: Number(event.target.value) } : item))}><option value={2}>H2</option><option value={3}>H3</option></select><input value={heading.text} onChange={(event) => setHeadings(headings.map((item, position) => position === index ? { ...item, text: event.target.value } : item))}/><button onClick={() => setHeadings(headings.filter((_, position) => position !== index))}><Trash2 size={15}/></button></div>)}</section></aside></div></div>;
return (
<div className="product-editor">
<div className="editor-top">
<div className="breadcrumb-title">
<button className="back" onClick={onBack}>
<ArrowLeft size={17} />
{meta.label}管理
</button>
<span>/</span>
<h1>{contentCode ? `编辑${meta.label}` : `新增${meta.label}`}</h1>
{notice && <em>{notice}</em>}
</div>
<div className="editor-actions">
<button onClick={onBack}>取消</button>
<button
className="primary"
disabled={saving || !form.title || !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={`${meta.label}标题 *`}>
<input
value={form.title}
onChange={(event) =>
setForm({ ...form, title: event.target.value })
}
/>
</Field>
<Field label="英文路径 *">
<input
value={form.slug}
onChange={(event) =>
setForm({
...form,
slug: event.target.value
.toLowerCase()
.replace(/[^a-z0-9-]/g, "-"),
})
}
/>
</Field>
<Field label="作者">
<input
value={form.authorName || ""}
onChange={(event) =>
setForm({ ...form, authorName: event.target.value })
}
/>
</Field>
<Field label="来源">
<input
value={form.sourceName || ""}
onChange={(event) =>
setForm({ ...form, sourceName: event.target.value })
}
/>
</Field>
<Field label="排序">
<input
type="number"
value={form.sortNo}
onChange={(event) =>
setForm({ ...form, sortNo: Number(event.target.value) })
}
/>
</Field>
<Field wide label={`${meta.label}简介 *`}>
<textarea
rows={4}
value={form.summary || ""}
onChange={(event) =>
setForm({ ...form, summary: event.target.value })
}
/>
</Field>
</div>
</section>
<section className="edit-section">
<h2>{meta.label}封面</h2>
<div className="cover-upload">
{form.coverMediaUrl ? (
<img
src={assetUrl(form.coverMediaUrl)}
alt={`${meta.label}封面预览`}
/>
) : (
<ImageIcon size={42} />
)}
<label className={uploading ? "uploading" : ""}>
<span>{uploading ? "上传中..." : "选择图片"}</span>
<input
ref={coverInputRef}
disabled={uploading}
type="file"
accept=".jpg,.jpeg,.png,.webp,.gif,image/jpeg,image/png,image/webp,image/gif"
onClick={(event) => {
event.currentTarget.value = "";
}}
onChange={(event) =>
void upload(event.currentTarget.files?.[0])
}
/>
</label>
<p>支持 JPG、PNG、WebP、GIF,单图不超过 10MB</p>
{notice && <small className="upload-notice">{notice}</small>}
</div>
</section>
<section className="edit-section">
<h2>{meta.label}详情 *</h2>
<div className="rich-editor">
<div className="rich-toolbar">
<Tool
title="撤销"
onClick={() => editor?.chain().focus().undo().run()}
>
<Undo2 />
</Tool>
<Tool
title="重做"
onClick={() => editor?.chain().focus().redo().run()}
>
<Redo2 />
</Tool>
<Tool
title="粗体"
active={editor?.isActive("bold")}
onClick={() => editor?.chain().focus().toggleBold().run()}
>
<Bold />
</Tool>
<Tool
title="斜体"
active={editor?.isActive("italic")}
onClick={() => editor?.chain().focus().toggleItalic().run()}
>
<Italic />
</Tool>
<Tool
title="二级标题"
active={editor?.isActive("heading", { level: 2 })}
onClick={() =>
editor?.chain().focus().toggleHeading({ level: 2 }).run()
}
>
<Heading2 />
</Tool>
<Tool
title="三级标题"
active={editor?.isActive("heading", { level: 3 })}
onClick={() =>
editor?.chain().focus().toggleHeading({ level: 3 }).run()
}
>
<Heading3 />
</Tool>
<Tool
title="项目列表"
onClick={() =>
editor?.chain().focus().toggleBulletList().run()
}
>
<List />
</Tool>
<Tool title="链接" onClick={addLink}>
<LinkIcon />
</Tool>
<Tool title="插入图片" onClick={addImage}>
<ImageIcon />
</Tool>
</div>
<EditorContent editor={editor} />
</div>
</section>
</div>
<aside className="editor-side">
<section className="edit-section">
<h2>发布</h2>
<Field label="状态">
<select
value={form.status}
onChange={(event) =>
setForm({ ...form, status: event.target.value })
}
>
<option value="DRAFT">草稿</option>
<option value="PUBLISHED">上架</option>
<option value="OFFLINE">下线</option>
</select>
</Field>
<label className="check">
<input
type="checkbox"
checked={form.featured}
onChange={(event) =>
setForm({ ...form, featured: event.target.checked })
}
/>
推荐内容
</label>
</section>
<section className="edit-section">
<h2>搜索引擎优化</h2>
<Field label="SEO 标题">
<input
maxLength={70}
value={seo.title}
onChange={(event) =>
setSeo({ ...seo, title: event.target.value })
}
/>
</Field>
<Field label="SEO 描述">
<textarea
maxLength={160}
rows={4}
value={seo.description}
onChange={(event) =>
setSeo({ ...seo, description: event.target.value })
}
/>
</Field>
<Field label="SEO 关键词">
<input
value={seo.keywords}
onChange={(event) =>
setSeo({ ...seo, keywords: event.target.value })
}
/>
</Field>
<Field label="H1">
<input
maxLength={120}
value={seo.h1}
onChange={(event) => setSeo({ ...seo, h1: event.target.value })}
/>
</Field>
<Field label="Canonical">
<input
value={seo.canonicalUrl}
placeholder={`/${meta.route}/${form.slug}`}
onChange={(event) =>
setSeo({ ...seo, canonicalUrl: event.target.value })
}
/>
</Field>
<div className="section-head">
<h3>H2 / H3 标签</h3>
<button
onClick={() =>
setHeadings([
...headings,
{ level: 2, text: "", sortNo: headings.length },
])
}
>
<Plus size={15} />
</button>
</div>
{headings.map((heading, index) => (
<div className="heading-row" key={index}>
<select
value={heading.level}
onChange={(event) =>
setHeadings(
headings.map((item, position) =>
position === index
? { ...item, level: Number(event.target.value) }
: item,
),
)
}
>
<option value={2}>H2</option>
<option value={3}>H3</option>
</select>
<input
value={heading.text}
onChange={(event) =>
setHeadings(
headings.map((item, position) =>
position === index
? { ...item, text: event.target.value }
: item,
),
)
}
/>
<button
onClick={() =>
setHeadings(
headings.filter((_, position) => position !== index),
)
}
>
<Trash2 size={15} />
</button>
</div>
))}
</section>
</aside>
</div>
</div>
);
}
function Field({ label, wide, children }: { label: string; wide?: boolean; children: React.ReactNode }) { return <label className={wide ? "wide" : ""}><span>{label}</span>{children}</label>; }
function Tool({ title, active, onClick, children }: { title: string; active?: boolean; onClick: () => void; children: React.ReactElement }) { return <button type="button" title={title} className={active ? "active" : ""} onClick={onClick}>{React.cloneElement(children, { size: 18 } as never)}</button>; }
function Field({
label,
wide,
children,
}: {
label: string;
wide?: boolean;
children: React.ReactNode;
}) {
return (
<label className={wide ? "wide" : ""}>
<span>{label}</span>
{children}
</label>
);
}
function Tool({
title,
active,
onClick,
children,
}: {
title: string;
active?: boolean;
onClick: () => void;
children: React.ReactElement;
}) {
return (
<button
type="button"
title={title}
className={active ? "active" : ""}
onClick={onClick}
>
{React.cloneElement(children, { size: 18 } as never)}
</button>
);
}
+105 -24
View File
@@ -64,7 +64,14 @@ type Schema = {
};
sections: Section[];
};
type PreviewProduct = {productCode:string;productName:string;model?:string;summary?:string;coverMediaUrl?:string;attributes?:Array<{name:string;value:string;unit?:string}>};
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> = {
ANNOUNCEMENT: "公告栏",
HEADER: "导航栏",
@@ -137,7 +144,14 @@ function createSection(type: SectionType): Section {
}
/** 为产品详情页提供可直接发布的基础组件结构。 */
function productDetailSchema(schema: Schema): Schema {
return {...schema,sections:[createSection("HEADER"),createSection("PRODUCT_DETAIL"),createSection("FOOTER")]};
return {
...schema,
sections: [
createSection("HEADER"),
createSection("PRODUCT_DETAIL"),
createSection("FOOTER"),
],
};
}
export default function DecorationEditor({ onBack }: { onBack: () => void }) {
const [pageType, setPageType] = useState("HOME");
@@ -159,13 +173,32 @@ export default function DecorationEditor({ onBack }: { onBack: () => void }) {
post("/decorations/detail", { siteCode: SITE, pageType })
.then((data) => {
const loaded = JSON.parse(data.schema) as Schema;
setSchema(pageType==="PRODUCT_DETAIL"&&!loaded.sections.length?productDetailSchema(loaded):loaded);
setSchema(
pageType === "PRODUCT_DETAIL" && !loaded.sections.length
? productDetailSchema(loaded)
: loaded,
);
setStatus(data.status);
setVersion(data.publishedVersion);
})
.catch((error) => setNotice(error.message));
}, [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]);
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) => {
setHistory((items) => [...items.slice(-19), schema]);
setFuture([]);
@@ -509,7 +542,8 @@ function PreviewSection({
className="pv-hero"
style={{
...style,
backgroundImage: (item.imageUrls?.[0] || item.imageUrl)
backgroundImage:
item.imageUrls?.[0] || item.imageUrl
? `linear-gradient(90deg,rgba(0,0,0,.65),rgba(0,0,0,.1)),url(${item.imageUrls?.[0] || item.imageUrl})`
: undefined,
}}
@@ -559,24 +593,52 @@ function PreviewSection({
</section>
);
if (item.type === "PRODUCT_DETAIL") {
const attributes=product?.attributes?.slice(0,item.productInformationLimit||8)||[];
const showInformation=item.showProductInformation!==false&&(Boolean(product?.model)||attributes.length>0);
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>
const attributes =
product?.attributes?.slice(0, item.productInformationLimit || 8) || [];
const showInformation =
item.showProductInformation !== false &&
(Boolean(product?.model) || attributes.length > 0);
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 className="pv-product-summary">
<span>PRODUCT</span>
<h1>{product?.productName || "Product title"}</h1>
<p>{product?.summary||"Product summary and key selling points will be loaded from the selected product."}</p>
{showInformation&&<div className="pv-product-information">
<p>
{product?.summary ||
"Product summary and key selling points will be loaded from the selected product."}
</p>
{showInformation && (
<div className="pv-product-information">
<h2>{item.productInformationTitle || "Product information"}</h2>
<dl>
{product?.model&&<div><dt>Model</dt><dd>{product.model}</dd></div>}
{attributes.map(attribute=><div key={attribute.name}><dt>{attribute.name}</dt><dd>{attribute.value} {attribute.unit}</dd></div>)}
{product?.model && (
<div>
<dt>Model</dt>
<dd>{product.model}</dd>
</div>
)}
{attributes.map((attribute) => (
<div key={attribute.name}>
<dt>{attribute.name}</dt>
<dd>
{attribute.value} {attribute.unit}
</dd>
</div>
))}
</dl>
</div>}
</div>
)}
<button style={{ background: primary }}>Request a quote</button>
</div>
</section>;
</section>
);
}
if (item.type === "INQUIRY")
return (
@@ -612,9 +674,7 @@ function PreviewSection({
<br />
Privacy Policy
</div>
<small>
{item.subtitle || "Copyright © 2026. All rights reserved."}
</small>
<small>{item.subtitle || "Copyright © 2026. All rights reserved."}</small>
</section>
);
}
@@ -703,7 +763,9 @@ function SectionSettings({
return (
<div>
<h3>{labels[item.type]}设置</h3>
{item.type!=="PRODUCT_DETAIL"&&<><Field label="英文标题">
{item.type !== "PRODUCT_DETAIL" && (
<>
<Field label="英文标题">
<input
value={item.title}
onChange={(e) => onChange({ title: e.target.value })}
@@ -716,7 +778,8 @@ function SectionSettings({
onChange={(e) => onChange({ subtitle: e.target.value })}
/>
</Field>
</>}
</>
)}
{item.type === "HERO" && (
<>
<Field label="背景图片 URL">
@@ -726,7 +789,19 @@ function SectionSettings({
/>
</Field>
<Field label="轮播图片 URL(每行一张)">
<textarea rows={4} value={(item.imageUrls || []).join("\n")} onChange={(e) => onChange({ imageUrls: e.target.value.split(/\r?\n/).map((value) => value.trim()).filter(Boolean) })} placeholder="https://..." />
<textarea
rows={4}
value={(item.imageUrls || []).join("\n")}
onChange={(e) =>
onChange({
imageUrls: e.target.value
.split(/\r?\n/)
.map((value) => value.trim())
.filter(Boolean),
})
}
placeholder="https://..."
/>
</Field>
<Field label="按钮文案">
<input
@@ -760,14 +835,18 @@ function SectionSettings({
<input
type="checkbox"
checked={item.showProductInformation !== false}
onChange={(e) => onChange({ showProductInformation: e.target.checked })}
onChange={(e) =>
onChange({ showProductInformation: e.target.checked })
}
/>
展示产品信息
</label>
<Field label="产品信息英文标题">
<input
value={item.productInformationTitle || "Product information"}
onChange={(e) => onChange({ productInformationTitle: e.target.value })}
onChange={(e) =>
onChange({ productInformationTitle: e.target.value })
}
disabled={item.showProductInformation === false}
/>
</Field>
@@ -777,7 +856,9 @@ function SectionSettings({
min="1"
max="20"
value={item.productInformationLimit || 8}
onChange={(e) => onChange({ productInformationLimit: Number(e.target.value) })}
onChange={(e) =>
onChange({ productInformationLimit: Number(e.target.value) })
}
disabled={item.showProductInformation === false}
/>
</Field>
File diff suppressed because it is too large. Load diff
+1
View File
@@ -439,6 +439,7 @@ 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}
.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}
.gallery-upload-button{border:1px solid #d8dee3;border-radius:5px;padding:8px 12px;color:#176b5b;display:inline-flex;align-items:center;gap:6px;cursor:pointer;font-size:13px}.gallery-upload-button.uploading{color:#71808a;cursor:wait}.gallery-upload-button input{display:none}.gallery-help{margin:-8px 0 16px;color:#81908b;font-size:12px}.product-gallery-editor{display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:14px}.product-gallery-editor article{border:1px solid #d8dee3;border-radius:5px;overflow:hidden;background:#f8faf9}.product-gallery-editor article>div{position:relative;aspect-ratio:1/1;background:#fff}.product-gallery-editor img{width:100%;height:100%;object-fit:contain}.product-gallery-editor article>div>span{position:absolute;z-index:1;top:7px;left:7px;background:#176b5b;color:#fff;padding:3px 7px;font-size:11px}.product-gallery-editor footer{display:flex;justify-content:center;gap:5px;padding:7px}.product-gallery-editor footer button{width:32px;height:30px;border:1px solid #d8dee3;background:#fff;color:#596873;display:grid;place-items:center;cursor:pointer}.product-gallery-editor footer button:last-child{color:#a43333}.product-gallery-editor footer button:disabled{opacity:.35;cursor:not-allowed}.gallery-empty{min-height:150px;border:1px dashed #bdc8c4;display:grid;place-items:center;align-content:center;gap:8px;color:#81908b;font-size:13px}
.media-picker-backdrop{position:fixed;inset:0;z-index:1000;background:#101a1888;display:grid;place-items:center;padding:24px}.media-picker{width:min(980px,100%);max-height:calc(100vh - 48px);display:grid;grid-template-rows:auto auto 1fr auto;background:#fff;border-radius:7px;box-shadow:0 20px 60px #10211d40;overflow:hidden}.media-picker>header{display:flex;justify-content:space-between;align-items:center;padding:16px 20px;border-bottom:1px solid #e4e9e7}.media-picker>header h2{margin:0;font-size:18px}.media-picker>header button{border:0;background:transparent;display:grid;place-items:center;cursor:pointer}.media-picker-toolbar{display:flex;gap:12px;padding:14px 20px;border-bottom:1px solid #e4e9e7}.media-picker-toolbar>label:first-child{display:flex;align-items:center;gap:8px;flex:1;border:1px solid #d8dee3;border-radius:5px;padding:0 11px;color:#7d8a86}.media-picker-toolbar input{border:0;outline:0;padding:10px 0;min-width:0;flex:1;font:inherit}.media-local-upload{display:inline-flex;align-items:center;gap:6px;border:1px solid #176b5b;color:#176b5b;padding:9px 13px;cursor:pointer}.media-local-upload input{display:none}.media-picker-grid{padding:18px 20px;overflow:auto;display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:14px}.media-picker-item{position:relative;border:1px solid #dce3e0;background:#fff;padding:0;text-align:left;cursor:pointer;overflow:hidden}.media-picker-item.selected{border:2px solid #176b5b}.media-picker-item img{display:block;width:100%;aspect-ratio:1;object-fit:cover;background:#f4f7f6}.media-picker-item span{display:flex;align-items:center;gap:3px;padding:8px;font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.media-picker-empty{grid-column:1/-1;min-height:200px;display:grid;place-items:center;color:#82908b}.media-picker>footer{display:flex;justify-content:flex-end;gap:10px;padding:14px 20px;border-top:1px solid #e4e9e7}.media-picker>footer button{border:1px solid #d8dee3;background:#fff;padding:9px 14px;border-radius:4px;cursor:pointer}.media-picker>footer .primary{background:#176b5b;color:#fff;border-color:#176b5b}@media(max-width:700px){.media-picker-toolbar{flex-direction:column}.media-picker-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
.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-summary>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 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-information{margin:18px 0;max-height:210px;overflow:auto}.pv-product-information h2{font:500 14px Georgia,serif;margin:0 0 8px}.pv-product-information dl{margin:0}.pv-product-information dl>div{display:grid;grid-template-columns:90px minmax(0,1fr);gap:14px;padding:6px 0}.pv-product-information dt,.pv-product-information dd{margin:0;font-size:12px}.pv-product-information dt{color:#7a8783}.pv-product-information dd{font-weight:500;overflow-wrap:anywhere}.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}}