bug修复
This commit is contained in:
1 parent
3893b25848
commit
de8d37e0e6
5 files changed
+542
-20
No files matched your search
@@ -0,0 +1,26 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import PageEditor from "./PageEditor";
|
||||||
|
import { apiPost } from "./api";
|
||||||
|
|
||||||
|
const SITE = "SIT0000000000001";
|
||||||
|
|
||||||
|
/** 关于我们固定页面设置入口。 */
|
||||||
|
export default function AboutUsSettingsPage() {
|
||||||
|
const [pageCode, setPageCode] = useState<string>();
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void apiPost("/pages/list", { siteCode: SITE })
|
||||||
|
.then((data) => {
|
||||||
|
const page = (data.items || []).find((item: { systemPageType?: string }) => item.systemPageType === "ABOUT_US");
|
||||||
|
setPageCode(page?.pageCode);
|
||||||
|
})
|
||||||
|
.catch((cause) => setError(cause instanceof Error ? cause.message : "关于我们页面加载失败"))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (loading) return <div className="empty"><strong>正在加载关于我们页面</strong></div>;
|
||||||
|
if (error) return <div className="notice">{error}</div>;
|
||||||
|
return <PageEditor key={pageCode || "new-about-us"} pageCode={pageCode} onBack={() => undefined} fixedSystemPageType="ABOUT_US" standaloneTitle="关于我们设置" onSaved={setPageCode}/>;
|
||||||
|
}
|
||||||
@@ -132,6 +132,36 @@ export default function CategoryManager({ contentType }: Props) {
|
|||||||
append(tree);
|
append(tree);
|
||||||
return result;
|
return result;
|
||||||
}, [tree, expanded]);
|
}, [tree, expanded]);
|
||||||
|
const parentOptions = useMemo(() => {
|
||||||
|
const unavailableCodes = new Set<string>();
|
||||||
|
let subtreeHeight = 1;
|
||||||
|
const visit = (node: TreeCategory): number => {
|
||||||
|
if (editing?.categoryCode === node.categoryCode) {
|
||||||
|
const collect = (current: TreeCategory) => {
|
||||||
|
unavailableCodes.add(current.categoryCode);
|
||||||
|
current.children.forEach(collect);
|
||||||
|
};
|
||||||
|
collect(node);
|
||||||
|
}
|
||||||
|
const height = 1 + Math.max(0, ...node.children.map(visit));
|
||||||
|
if (editing?.categoryCode === node.categoryCode) subtreeHeight = height;
|
||||||
|
return height;
|
||||||
|
};
|
||||||
|
tree.forEach(visit);
|
||||||
|
const result: TreeCategory[] = [];
|
||||||
|
const flatten = (nodes: TreeCategory[]) => nodes.forEach((node) => { result.push(node); flatten(node.children); });
|
||||||
|
flatten(tree);
|
||||||
|
return result.filter((node) => !unavailableCodes.has(node.categoryCode) && node.depth + subtreeHeight <= maxDepth);
|
||||||
|
}, [tree, editing, maxDepth]);
|
||||||
|
/** 修改父级分类并同步完整层级路径。 */
|
||||||
|
const changeParent = (nextParentCode: string) => {
|
||||||
|
const parent = items.find((item) => item.categoryCode === nextParentCode);
|
||||||
|
const leafSlug = form.slug.split("/").filter(Boolean).pop() || "";
|
||||||
|
const slug = parent ? `${parent.slug}/${leafSlug}` : leafSlug;
|
||||||
|
setParentCode(nextParentCode);
|
||||||
|
setForm({ ...form, slug });
|
||||||
|
setSeo({ ...seo, canonicalUrl: `/${isProduct ? "products" : contentType!.toLowerCase()}/${slug}` });
|
||||||
|
};
|
||||||
/** 打开分类独立编辑页面。 */
|
/** 打开分类独立编辑页面。 */
|
||||||
const openEditor = (item: Category | null, requestedParentCode = "") => {
|
const openEditor = (item: Category | null, requestedParentCode = "") => {
|
||||||
setEditing(item);
|
setEditing(item);
|
||||||
@@ -227,9 +257,6 @@ export default function CategoryManager({ contentType }: Props) {
|
|||||||
</button>
|
</button>
|
||||||
<div>
|
<div>
|
||||||
<h1>{editing ? `编辑${label}分类` : `新增${label}分类`}</h1>
|
<h1>{editing ? `编辑${label}分类` : `新增${label}分类`}</h1>
|
||||||
<p>
|
|
||||||
{parentCode ? "当前分类将创建在所选父分类下" : "创建顶级分类"}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="header-actions">
|
<div className="header-actions">
|
||||||
@@ -252,6 +279,13 @@ export default function CategoryManager({ contentType }: Props) {
|
|||||||
<section className="edit-section">
|
<section className="edit-section">
|
||||||
<h2>分类信息</h2>
|
<h2>分类信息</h2>
|
||||||
<div className="form-grid">
|
<div className="form-grid">
|
||||||
|
<label className="wide">
|
||||||
|
<span>父级分类</span>
|
||||||
|
<select value={parentCode} onChange={(event) => changeParent(event.target.value)}>
|
||||||
|
<option value="">无(顶级分类)</option>
|
||||||
|
{parentOptions.map((option) => <option key={option.categoryCode} value={option.categoryCode}>{`${" ".repeat(option.depth - 1)}${option.categoryName}`}</option>)}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
<label>
|
<label>
|
||||||
<span>分类名称 *</span>
|
<span>分类名称 *</span>
|
||||||
<input
|
<input
|
||||||
@@ -370,7 +404,6 @@ export default function CategoryManager({ contentType }: Props) {
|
|||||||
<div className="category-heading">
|
<div className="category-heading">
|
||||||
<div>
|
<div>
|
||||||
<h1>{label}分类</h1>
|
<h1>{label}分类</h1>
|
||||||
<p>最多支持 {maxDepth} 级分类,使用英文名称维护前台目录。</p>
|
|
||||||
</div>
|
</div>
|
||||||
<button className="primary" onClick={() => openEditor(null)}>
|
<button className="primary" onClick={() => openEditor(null)}>
|
||||||
<Plus size={17} />
|
<Plus size={17} />
|
||||||
|
|||||||
+469
-15
@@ -3,26 +3,480 @@ import { EditorContent, useEditor } from "@tiptap/react";
|
|||||||
import StarterKit from "@tiptap/starter-kit";
|
import StarterKit from "@tiptap/starter-kit";
|
||||||
import Link from "@tiptap/extension-link";
|
import Link from "@tiptap/extension-link";
|
||||||
import Image from "@tiptap/extension-image";
|
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 } from "./api";
|
import { API } from "./api";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = "SIT0000000000001";
|
||||||
type Heading = { level: number; text: string; sortNo: number };
|
type Heading = { level: number; text: string; sortNo: number };
|
||||||
type Props = { pageCode?: string; onBack: () => void };
|
type Props = {
|
||||||
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 || "请求失败"); return response.json(); }
|
pageCode?: string;
|
||||||
|
onBack: () => void;
|
||||||
|
fixedSystemPageType?: string;
|
||||||
|
standaloneTitle?: string;
|
||||||
|
onSaved?: (pageCode: string) => void;
|
||||||
|
};
|
||||||
|
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 || "请求失败");
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
/** 固定页面和自定义页面内容、SEO 编辑器。 */
|
/** 固定页面和自定义页面内容、SEO 编辑器。 */
|
||||||
export default function PageEditor({ pageCode, onBack }: Props) {
|
export default function PageEditor({
|
||||||
const [form, setForm] = useState({ pageType: "SYSTEM_PAGE", systemPageType: "ABOUT_US", pageName: "", slug: "", summary: "", coverMediaCode: "", coverMediaUrl: "", sortNo: 30, status: "DRAFT" });
|
pageCode,
|
||||||
const [seo, setSeo] = useState({ title: "", description: "", keywords: "", h1: "", canonicalUrl: "", robots: "index,follow", ogTitle: "", ogDescription: "", ogImageUrl: "", status: "DRAFT" });
|
onBack,
|
||||||
|
fixedSystemPageType,
|
||||||
|
standaloneTitle,
|
||||||
|
onSaved,
|
||||||
|
}: Props) {
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
pageType: "SYSTEM_PAGE",
|
||||||
|
systemPageType: "ABOUT_US",
|
||||||
|
pageName: "",
|
||||||
|
slug: "",
|
||||||
|
summary: "",
|
||||||
|
coverMediaCode: "",
|
||||||
|
coverMediaUrl: "",
|
||||||
|
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 [headings, setHeadings] = useState<Heading[]>([]);
|
||||||
const [saving, setSaving] = useState(false); const [notice, setNotice] = useState("");
|
const [saving, setSaving] = useState(false);
|
||||||
const editor = useEditor({ extensions: [StarterKit, Link.configure({ openOnClick: false }), Image], content: "<p></p>" });
|
const [notice, setNotice] = useState("");
|
||||||
useEffect(() => { if (!pageCode) return; post("/pages/detail", { siteCode: SITE, pageCode }).then((data) => { setForm({ ...data, coverMediaUrl: data.coverMediaUrl || "" }); editor?.commands.setContent(data.pageContent || "<p></p>"); post("/seo/detail", { siteCode: SITE, pageType: data.pageType === "SYSTEM_PAGE" ? "SYSTEM_PAGE" : "CUSTOM_PAGE", targetCode: pageCode }).then((seoData) => { setSeo({ title: seoData.title, description: seoData.description, keywords: seoData.keywords || "", h1: seoData.h1, canonicalUrl: seoData.canonicalUrl || "", robots: seoData.robots, ogTitle: seoData.ogTitle || "", ogDescription: seoData.ogDescription || "", ogImageUrl: seoData.ogImageUrl || "", status: seoData.status }); setHeadings(seoData.headings || []); }).catch(() => undefined); }).catch((error) => setNotice(error.message)); }, [pageCode, editor]);
|
const editor = useEditor({
|
||||||
const save = async () => { if (!editor) return; try { setSaving(true); setNotice(""); const result = await post("/pages/save", { pageCode, siteCode: SITE, pageType: form.pageType, systemPageType: form.pageType === "SYSTEM_PAGE" ? form.systemPageType : null, pageName: form.pageName, slug: form.slug, pageContent: editor.getHTML(), summary: form.summary, coverMediaCode: form.coverMediaCode, sortNo: form.sortNo, status: form.status }); await post("/seo/save", { siteCode: SITE, pageType: form.pageType === "SYSTEM_PAGE" ? "SYSTEM_PAGE" : "CUSTOM_PAGE", targetCode: result.pageCode, title: seo.title || form.pageName, description: seo.description || form.summary, keywords: seo.keywords, h1: seo.h1 || form.pageName, canonicalUrl: seo.canonicalUrl || `/${form.slug}`, robots: seo.robots, ogTitle: seo.ogTitle, ogDescription: seo.ogDescription, ogImageUrl: seo.ogImageUrl, structuredData: null, status: form.status, headings }); setNotice("页面与 SEO 已保存"); if (!pageCode) setTimeout(onBack, 500); } catch (error) { setNotice(error instanceof Error ? error.message : "保存失败"); } finally { setSaving(false); } };
|
extensions: [StarterKit, Link.configure({ openOnClick: false }), Image],
|
||||||
const addLink = () => { const href = window.prompt("请输入链接地址"); if (href) editor?.chain().focus().setLink({ href }).run(); };
|
content: "<p></p>",
|
||||||
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>{pageCode ? "编辑页面" : "新增页面"}</h1>{notice && <em>{notice}</em>}</div><div className="editor-actions"><button onClick={onBack}>取消</button><button className="primary" disabled={saving || !form.pageName || !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.pageName} onChange={(event) => setForm({ ...form, pageName: 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="页面类型"><select value={form.pageType} onChange={(event) => setForm({ ...form, pageType: event.target.value })}><option value="SYSTEM_PAGE">固定页面</option><option value="CUSTOM_PAGE">自定义页面</option></select></Field>{form.pageType === "SYSTEM_PAGE" && <Field label="固定页面类型"><select value={form.systemPageType || "ABOUT_US"} onChange={(event) => setForm({ ...form, systemPageType: event.target.value })}><option value="ABOUT_US">关于我们</option><option value="CONTACT_US">联系我们</option><option value="TERMS_OF_SERVICE">服务协议</option><option value="PRIVACY_POLICY">隐私协议</option><option value="COOKIE_POLICY">Cookie 协议</option><option value="INQUIRY_SUCCESS">询盘成功页</option></select></Field>}<Field label="排序"><input type="number" value={form.sortNo} onChange={(event) => setForm({ ...form, sortNo: Number(event.target.value) })}/></Field><Field wide label="页面摘要"><textarea rows={4} value={form.summary || ""} onChange={(event) => setForm({ ...form, summary: event.target.value })}/></Field></div></section><section className="edit-section"><h2>页面正文 *</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="粗体" onClick={() => editor?.chain().focus().toggleBold().run()}><Bold/></Tool><Tool title="斜体" onClick={() => editor?.chain().focus().toggleItalic().run()}><Italic/></Tool><Tool title="二级标题" onClick={() => editor?.chain().focus().toggleHeading({ level: 2 }).run()}><Heading2/></Tool><Tool title="三级标题" 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></section><section className="edit-section"><h2>页面 SEO 设置</h2><Field label="SEO 标题"><input maxLength={70} value={seo.title} onChange={(event) => setSeo({ ...seo, title: event.target.value })}/></Field><Field label="SEO 描述"><textarea rows={4} maxLength={160} 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 value={seo.h1} onChange={(event) => setSeo({ ...seo, h1: event.target.value })}/></Field><Field label="Canonical"><input value={seo.canonicalUrl} placeholder={`/${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))}><TrLine truncated
|
useEffect(() => {
|
||||||
|
if (pageCode || !fixedSystemPageType) return;
|
||||||
|
setForm((current) => ({
|
||||||
|
...current,
|
||||||
|
pageType: "SYSTEM_PAGE",
|
||||||
|
systemPageType: fixedSystemPageType,
|
||||||
|
pageName: fixedSystemPageType === "ABOUT_US" ? "About Us" : current.pageName,
|
||||||
|
slug: fixedSystemPageType === "ABOUT_US" ? "about-us" : current.slug,
|
||||||
|
}));
|
||||||
|
}, [pageCode, fixedSystemPageType]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!pageCode) return;
|
||||||
|
post("/pages/detail", { siteCode: SITE, pageCode })
|
||||||
|
.then((data) => {
|
||||||
|
setForm({ ...data, coverMediaUrl: data.coverMediaUrl || "" });
|
||||||
|
editor?.commands.setContent(data.pageContent || "<p></p>");
|
||||||
|
post("/seo/detail", {
|
||||||
|
siteCode: SITE,
|
||||||
|
pageType:
|
||||||
|
data.pageType === "SYSTEM_PAGE" ? "SYSTEM_PAGE" : "CUSTOM_PAGE",
|
||||||
|
targetCode: pageCode,
|
||||||
|
})
|
||||||
|
.then((seoData) => {
|
||||||
|
setSeo({
|
||||||
|
title: seoData.title,
|
||||||
|
description: seoData.description,
|
||||||
|
keywords: seoData.keywords || "",
|
||||||
|
h1: seoData.h1,
|
||||||
|
canonicalUrl: seoData.canonicalUrl || "",
|
||||||
|
robots: seoData.robots,
|
||||||
|
ogTitle: seoData.ogTitle || "",
|
||||||
|
ogDescription: seoData.ogDescription || "",
|
||||||
|
ogImageUrl: seoData.ogImageUrl || "",
|
||||||
|
status: seoData.status,
|
||||||
|
});
|
||||||
|
setHeadings(seoData.headings || []);
|
||||||
|
})
|
||||||
|
.catch(() => undefined);
|
||||||
|
})
|
||||||
|
.catch((error) => setNotice(error.message));
|
||||||
|
}, [pageCode, editor]);
|
||||||
|
const save = async () => {
|
||||||
|
if (!editor) return;
|
||||||
|
try {
|
||||||
|
setSaving(true);
|
||||||
|
setNotice("");
|
||||||
|
const result = await post("/pages/save", {
|
||||||
|
pageCode,
|
||||||
|
siteCode: SITE,
|
||||||
|
pageType: form.pageType,
|
||||||
|
systemPageType:
|
||||||
|
form.pageType === "SYSTEM_PAGE" ? form.systemPageType : null,
|
||||||
|
pageName: form.pageName,
|
||||||
|
slug: form.slug,
|
||||||
|
pageContent: editor.getHTML(),
|
||||||
|
summary: form.summary,
|
||||||
|
coverMediaCode: form.coverMediaCode,
|
||||||
|
sortNo: form.sortNo,
|
||||||
|
status: form.status,
|
||||||
|
});
|
||||||
|
await post("/seo/save", {
|
||||||
|
siteCode: SITE,
|
||||||
|
pageType:
|
||||||
|
form.pageType === "SYSTEM_PAGE" ? "SYSTEM_PAGE" : "CUSTOM_PAGE",
|
||||||
|
targetCode: result.pageCode,
|
||||||
|
title: seo.title || form.pageName,
|
||||||
|
description: seo.description || form.summary,
|
||||||
|
keywords: seo.keywords,
|
||||||
|
h1: seo.h1 || form.pageName,
|
||||||
|
canonicalUrl: seo.canonicalUrl || `/${form.slug}`,
|
||||||
|
robots: seo.robots,
|
||||||
|
ogTitle: seo.ogTitle,
|
||||||
|
ogDescription: seo.ogDescription,
|
||||||
|
ogImageUrl: seo.ogImageUrl,
|
||||||
|
structuredData: null,
|
||||||
|
status: form.status,
|
||||||
|
headings,
|
||||||
|
});
|
||||||
|
setNotice("页面与 SEO 已保存");
|
||||||
|
onSaved?.(result.pageCode);
|
||||||
|
if (!pageCode && !onSaved) setTimeout(onBack, 500);
|
||||||
|
} 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();
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="product-editor">
|
||||||
|
<div className="editor-top">
|
||||||
|
<div className="breadcrumb-title">
|
||||||
|
{!standaloneTitle && <><button className="back" onClick={onBack}><ArrowLeft size={17} />页面管理</button><span>/</span></>}
|
||||||
|
<h1>{standaloneTitle || (pageCode ? "编辑页面" : "新增页面")}</h1>
|
||||||
|
{notice && <em>{notice}</em>}
|
||||||
|
</div>
|
||||||
|
<div className="editor-actions">
|
||||||
|
{!standaloneTitle && <button onClick={onBack}>取消</button>}
|
||||||
|
<button
|
||||||
|
className="primary"
|
||||||
|
disabled={saving || !form.pageName || !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.pageName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, pageName: 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>
|
||||||
|
{!fixedSystemPageType && <Field label="页面类型">
|
||||||
|
<select
|
||||||
|
value={form.pageType}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, pageType: event.target.value })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="SYSTEM_PAGE">固定页面</option>
|
||||||
|
<option value="CUSTOM_PAGE">自定义页面</option>
|
||||||
|
</select>
|
||||||
|
</Field>}
|
||||||
|
{form.pageType === "SYSTEM_PAGE" && !fixedSystemPageType && (
|
||||||
|
<Field label="固定页面类型">
|
||||||
|
<select
|
||||||
|
value={form.systemPageType || "ABOUT_US"}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, systemPageType: event.target.value })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="ABOUT_US">关于我们</option>
|
||||||
|
<option value="CONTACT_US">联系我们</option>
|
||||||
|
<option value="TERMS_OF_SERVICE">服务协议</option>
|
||||||
|
<option value="PRIVACY_POLICY">隐私协议</option>
|
||||||
|
<option value="COOKIE_POLICY">Cookie 协议</option>
|
||||||
|
<option value="INQUIRY_SUCCESS">询盘成功页</option>
|
||||||
|
</select>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
<Field label="排序">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={form.sortNo}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, sortNo: Number(event.target.value) })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field wide label="页面摘要">
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
value={form.summary || ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, summary: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section className="edit-section">
|
||||||
|
<h2>页面正文 *</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="粗体"
|
||||||
|
onClick={() => editor?.chain().focus().toggleBold().run()}
|
||||||
|
>
|
||||||
|
<Bold />
|
||||||
|
</Tool>
|
||||||
|
<Tool
|
||||||
|
title="斜体"
|
||||||
|
onClick={() => editor?.chain().focus().toggleItalic().run()}
|
||||||
|
>
|
||||||
|
<Italic />
|
||||||
|
</Tool>
|
||||||
|
<Tool
|
||||||
|
title="二级标题"
|
||||||
|
onClick={() =>
|
||||||
|
editor?.chain().focus().toggleHeading({ level: 2 }).run()
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Heading2 />
|
||||||
|
</Tool>
|
||||||
|
<Tool
|
||||||
|
title="三级标题"
|
||||||
|
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>
|
||||||
|
</section>
|
||||||
|
<section className="edit-section">
|
||||||
|
<h2>页面 SEO 设置</h2>
|
||||||
|
<Field label="SEO 标题">
|
||||||
|
<input
|
||||||
|
maxLength={70}
|
||||||
|
value={seo.title}
|
||||||
|
onChange={(event) =>
|
||||||
|
setSeo({ ...seo, title: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="SEO 描述">
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
maxLength={160}
|
||||||
|
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
|
||||||
|
value={seo.h1}
|
||||||
|
onChange={(event) => setSeo({ ...seo, h1: event.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="Canonical">
|
||||||
|
<input
|
||||||
|
value={seo.canonicalUrl}
|
||||||
|
placeholder={`/${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,
|
||||||
|
onClick,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
onClick: () => void;
|
||||||
|
children: React.ReactElement;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<button type="button" title={title} 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, onClick, children }: { title: string; onClick: () => void; children: React.ReactElement }) { return <button type="button" title={title} onClick={onClick}>{React.cloneElement(children, { size: 18 } as never)}</button>; }
|
|
||||||
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
|
|||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import {
|
import {
|
||||||
Boxes,
|
Boxes,
|
||||||
|
Building2,
|
||||||
Code2,
|
Code2,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
FileText,
|
FileText,
|
||||||
@@ -35,6 +36,7 @@ import SettingsPage from "./SettingsPage";
|
|||||||
import SeoSettingsPage from "./SeoSettingsPage";
|
import SeoSettingsPage from "./SeoSettingsPage";
|
||||||
import NavigationManager from "./NavigationManager";
|
import NavigationManager from "./NavigationManager";
|
||||||
import AgreementSettingsPage from "./AgreementSettingsPage";
|
import AgreementSettingsPage from "./AgreementSettingsPage";
|
||||||
|
import AboutUsSettingsPage from "./AboutUsSettingsPage";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
import { statusLabel } from "./statusLabels";
|
import { statusLabel } from "./statusLabels";
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ type Section =
|
|||||||
| "decoration"
|
| "decoration"
|
||||||
| "custom-code"
|
| "custom-code"
|
||||||
| "agreements"
|
| "agreements"
|
||||||
|
| "about-us"
|
||||||
| "media"
|
| "media"
|
||||||
| "inquiries"
|
| "inquiries"
|
||||||
| "inquiry-settings"
|
| "inquiry-settings"
|
||||||
@@ -113,6 +116,7 @@ async function post(path: string, body: unknown) {
|
|||||||
|
|
||||||
const frontSiteMenus = [
|
const frontSiteMenus = [
|
||||||
{ key: "pages" as Section, label: "页面", icon: FileText },
|
{ key: "pages" as Section, label: "页面", icon: FileText },
|
||||||
|
{ key: "about-us" as Section, label: "关于我们", icon: Building2 },
|
||||||
{ key: "navigation" as Section, label: "菜单导航", icon: Menu },
|
{ key: "navigation" as Section, label: "菜单导航", icon: Menu },
|
||||||
{ key: "decoration" as Section, label: "店铺装修", icon: Paintbrush },
|
{ key: "decoration" as Section, label: "店铺装修", icon: Paintbrush },
|
||||||
{ key: "custom-code" as Section, label: "自定义代码", icon: Code2 },
|
{ key: "custom-code" as Section, label: "自定义代码", icon: Code2 },
|
||||||
@@ -141,6 +145,7 @@ const sectionLabels: Record<Section, string> = {
|
|||||||
"inquiry-settings": "询盘设置",
|
"inquiry-settings": "询盘设置",
|
||||||
"seo-settings": "页面 SEO",
|
"seo-settings": "页面 SEO",
|
||||||
agreements: "协议设置",
|
agreements: "协议设置",
|
||||||
|
"about-us": "关于我们",
|
||||||
settings: "系统设置",
|
settings: "系统设置",
|
||||||
};
|
};
|
||||||
function App({
|
function App({
|
||||||
@@ -227,6 +232,8 @@ function App({
|
|||||||
? { items: [] }
|
? { items: [] }
|
||||||
: section === "agreements"
|
: section === "agreements"
|
||||||
? { items: [] }
|
? { items: [] }
|
||||||
|
: section === "about-us"
|
||||||
|
? { items: [] }
|
||||||
: section === "products"
|
: section === "products"
|
||||||
? await post("/products/list", { siteCode: SITE })
|
? await post("/products/list", { siteCode: SITE })
|
||||||
: section === "pages"
|
: section === "pages"
|
||||||
@@ -583,6 +590,8 @@ function App({
|
|||||||
onAccount={onAccount}
|
onAccount={onAccount}
|
||||||
onLogout={onLogout}
|
onLogout={onLogout}
|
||||||
/>
|
/>
|
||||||
|
) : section === "about-us" ? (
|
||||||
|
<AboutUsSettingsPage />
|
||||||
) : section === "seo-settings" ? (
|
) : section === "seo-settings" ? (
|
||||||
<SeoSettingsPage />
|
<SeoSettingsPage />
|
||||||
) : section === "agreements" ? (
|
) : section === "agreements" ? (
|
||||||
@@ -630,7 +639,6 @@ function App({
|
|||||||
<header>
|
<header>
|
||||||
<div>
|
<div>
|
||||||
<h1>{title}管理</h1>
|
<h1>{title}管理</h1>
|
||||||
<p>Local Development Site · 英文站内容</p>
|
|
||||||
</div>
|
</div>
|
||||||
{!["inquiries", "inquiry-settings"].includes(section) && (
|
{!["inquiries", "inquiry-settings"].includes(section) && (
|
||||||
<div className="header-actions">
|
<div className="header-actions">
|
||||||
|
|||||||
@@ -433,3 +433,4 @@ header p {
|
|||||||
.category-editor{max-width:1500px;margin:0 auto}.category-editor-layout{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(330px,.6fr);gap:20px;align-items:start}.category-editor .edit-section{background:#fff;border:1px solid #dfe5e9;border-radius:6px;padding:24px;margin-bottom:20px}.category-editor .edit-section h2{font-size:18px;font-weight:500;margin:0 0 20px}.category-editor .form-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px}.category-editor label{display:grid;gap:7px;margin-bottom:16px}.category-editor label>span{font-size:13px;font-weight:600}.category-editor input,.category-editor textarea,.category-editor select{width:100%;box-sizing:border-box;border:1px solid #d8dee3;border-radius:5px;padding:11px 12px;font:inherit;resize:vertical}.category-editor .wide{grid-column:1/-1}@media(max-width:900px){.category-editor-layout{grid-template-columns:1fr}.category-editor .form-grid{grid-template-columns:1fr}.category-editor .wide{grid-column:auto}}
|
.category-editor{max-width:1500px;margin:0 auto}.category-editor-layout{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(330px,.6fr);gap:20px;align-items:start}.category-editor .edit-section{background:#fff;border:1px solid #dfe5e9;border-radius:6px;padding:24px;margin-bottom:20px}.category-editor .edit-section h2{font-size:18px;font-weight:500;margin:0 0 20px}.category-editor .form-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px}.category-editor label{display:grid;gap:7px;margin-bottom:16px}.category-editor label>span{font-size:13px;font-weight:600}.category-editor input,.category-editor textarea,.category-editor select{width:100%;box-sizing:border-box;border:1px solid #d8dee3;border-radius:5px;padding:11px 12px;font:inherit;resize:vertical}.category-editor .wide{grid-column:1/-1}@media(max-width:900px){.category-editor-layout{grid-template-columns:1fr}.category-editor .form-grid{grid-template-columns:1fr}.category-editor .wide{grid-column:auto}}
|
||||||
.agreement-settings{max-width:1500px;margin:0 auto;padding:0 0 60px}.agreement-top{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:22px}.agreement-top h1{margin:0 0 8px;font-size:28px}.agreement-top p{margin:0;color:#71808a}.agreement-top button{border:1px solid #d8dee3;background:#fff;border-radius:5px;padding:10px 16px;display:inline-flex;align-items:center;gap:7px;cursor:pointer}.agreement-top .primary{background:#176b5b;color:#fff}.agreement-tabs{display:flex;gap:28px;background:#fff;border-bottom:1px solid #dde3e7;padding:0 22px}.agreement-tabs button{border:0;background:transparent;padding:16px 2px;color:#71808a;font:inherit;cursor:pointer;border-bottom:3px solid transparent}.agreement-tabs button.active{color:#176b5b;border-bottom-color:#176b5b}.agreement-card{background:#fff;border:1px solid #dde3e7;border-radius:6px;padding:24px;margin-top:20px;display:grid;gap:22px}.agreement-card-head{display:flex;align-items:center;justify-content:space-between}.agreement-card-head h2{margin:0;font-size:18px}.agreement-card-head select,.agreement-title input{border:1px solid #d8dee3;border-radius:5px;padding:10px 12px;font:inherit}.agreement-title,.agreement-content{display:grid;gap:8px}.agreement-title span,.agreement-content>span{font-weight:600;font-size:14px}.agreement-title input{width:100%;box-sizing:border-box}.agreement-content .ProseMirror{min-height:520px}.agreement-notice{color:#176b5b;margin:14px 0 0}
|
.agreement-settings{max-width:1500px;margin:0 auto;padding:0 0 60px}.agreement-top{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:22px}.agreement-top h1{margin:0 0 8px;font-size:28px}.agreement-top p{margin:0;color:#71808a}.agreement-top button{border:1px solid #d8dee3;background:#fff;border-radius:5px;padding:10px 16px;display:inline-flex;align-items:center;gap:7px;cursor:pointer}.agreement-top .primary{background:#176b5b;color:#fff}.agreement-tabs{display:flex;gap:28px;background:#fff;border-bottom:1px solid #dde3e7;padding:0 22px}.agreement-tabs button{border:0;background:transparent;padding:16px 2px;color:#71808a;font:inherit;cursor:pointer;border-bottom:3px solid transparent}.agreement-tabs button.active{color:#176b5b;border-bottom-color:#176b5b}.agreement-card{background:#fff;border:1px solid #dde3e7;border-radius:6px;padding:24px;margin-top:20px;display:grid;gap:22px}.agreement-card-head{display:flex;align-items:center;justify-content:space-between}.agreement-card-head h2{margin:0;font-size:18px}.agreement-card-head select,.agreement-title input{border:1px solid #d8dee3;border-radius:5px;padding:10px 12px;font:inherit}.agreement-title,.agreement-content{display:grid;gap:8px}.agreement-title span,.agreement-content>span{font-weight:600;font-size:14px}.agreement-title input{width:100%;box-sizing:border-box}.agreement-content .ProseMirror{min-height:520px}.agreement-notice{color:#176b5b;margin:14px 0 0}
|
||||||
.cover-upload label.uploading span{background:#71808a;cursor:wait}.cover-upload .upload-notice{display:block;color:#176b5b;font-size:12px;text-align:center}.cover-upload input:disabled+span{cursor:wait}
|
.cover-upload label.uploading span{background:#71808a;cursor:wait}.cover-upload .upload-notice{display:block;color:#176b5b;font-size:12px;text-align:center}.cover-upload input:disabled+span{cursor:wait}
|
||||||
|
.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}
|
||||||
Reference in new issue
Block a user