bug修复
This commit is contained in:
1 parent
529c255e5b
commit
3893b25848
9 files changed
+2484
-183
No files matched your search
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package com.shoplix.admin.modules.category.constants;
|
||||||
|
|
||||||
|
/** 分类层级路径校验常量。 */
|
||||||
|
public final class CategoryPathConstants {
|
||||||
|
|
||||||
|
/** 分类路径格式:每一级仅允许小写字母、数字和中划线,级别之间使用斜杠分隔。 */
|
||||||
|
public static final String PATTERN = "^[a-z0-9]+(?:-[a-z0-9]+)*(?:/[a-z0-9]+(?:-[a-z0-9]+)*)*$";
|
||||||
|
|
||||||
|
/** 工具类不允许实例化。 */
|
||||||
|
private CategoryPathConstants() {
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
package com.shoplix.admin.modules.content.req;
|
package com.shoplix.admin.modules.content.req;
|
||||||
|
|
||||||
import com.shoplix.modules.common.enums.PublishStatusEnum;
|
import com.shoplix.modules.common.enums.PublishStatusEnum;
|
||||||
|
import com.shoplix.admin.modules.category.constants.CategoryPathConstants;
|
||||||
import com.shoplix.modules.content.enums.ContentTypeEnum;
|
import com.shoplix.modules.content.enums.ContentTypeEnum;
|
||||||
import jakarta.validation.constraints.*;
|
import jakarta.validation.constraints.*;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public record SaveContentCategoryAdminReq(
|
|||||||
/** 内容类型。 */ @NotNull ContentTypeEnum contentType,
|
/** 内容类型。 */ @NotNull ContentTypeEnum contentType,
|
||||||
/** 父分类业务编号,顶级为空。 */ @Size(max = 16) String parentCategoryCode,
|
/** 父分类业务编号,顶级为空。 */ @Size(max = 16) String parentCategoryCode,
|
||||||
/** 英文分类名称。 */ @NotBlank @Size(max = 100) String categoryName,
|
/** 英文分类名称。 */ @NotBlank @Size(max = 100) String categoryName,
|
||||||
/** 英文路径标识。 */ @NotBlank @Pattern(regexp = "^[a-z0-9]+(?:-[a-z0-9]+)*$") @Size(max = 100) String slug,
|
/** 英文层级路径。 */ @NotBlank @Pattern(regexp = CategoryPathConstants.PATTERN) @Size(max = 100) String slug,
|
||||||
/** 英文分类描述。 */ @Size(max = 500) String description,
|
/** 英文分类描述。 */ @Size(max = 500) String description,
|
||||||
/** 封面媒体业务编号。 */ @Size(max = 16) String coverMediaCode,
|
/** 封面媒体业务编号。 */ @Size(max = 16) String coverMediaCode,
|
||||||
/** 排序值。 */ @NotNull Integer sortNo,
|
/** 排序值。 */ @NotNull Integer sortNo,
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
package com.shoplix.admin.modules.product.req;
|
package com.shoplix.admin.modules.product.req;
|
||||||
|
|
||||||
import com.shoplix.modules.common.enums.PublishStatusEnum;
|
import com.shoplix.modules.common.enums.PublishStatusEnum;
|
||||||
|
import com.shoplix.admin.modules.category.constants.CategoryPathConstants;
|
||||||
import jakarta.validation.constraints.*;
|
import jakarta.validation.constraints.*;
|
||||||
|
|
||||||
/** 运营后台保存产品分类请求。 */
|
/** 运营后台保存产品分类请求。 */
|
||||||
@@ -9,7 +10,7 @@ public record SaveProductCategoryAdminReq(
|
|||||||
/** 所属站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode,
|
/** 所属站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode,
|
||||||
/** 父分类业务编号,顶级为空。 */ @Size(max = 16) String parentCategoryCode,
|
/** 父分类业务编号,顶级为空。 */ @Size(max = 16) String parentCategoryCode,
|
||||||
/** 英文分类名称。 */ @NotBlank @Size(max = 100) String categoryName,
|
/** 英文分类名称。 */ @NotBlank @Size(max = 100) String categoryName,
|
||||||
/** 英文路径标识。 */ @NotBlank @Pattern(regexp = "^[a-z0-9]+(?:-[a-z0-9]+)*$") @Size(max = 100) String slug,
|
/** 英文层级路径。 */ @NotBlank @Pattern(regexp = CategoryPathConstants.PATTERN) @Size(max = 100) String slug,
|
||||||
/** 英文分类描述。 */ @Size(max = 500) String description,
|
/** 英文分类描述。 */ @Size(max = 500) String description,
|
||||||
/** 封面媒体业务编号。 */ @Size(max = 16) String coverMediaCode,
|
/** 封面媒体业务编号。 */ @Size(max = 16) String coverMediaCode,
|
||||||
/** 排序值。 */ @NotNull Integer sortNo,
|
/** 排序值。 */ @NotNull Integer sortNo,
|
||||||
|
|||||||
@@ -1,28 +1,448 @@
|
|||||||
import { ArrowLeft, ChevronDown, ChevronRight, Edit3, Plus, Save } from "lucide-react";
|
import {
|
||||||
|
ArrowLeft,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronRight,
|
||||||
|
Edit3,
|
||||||
|
Plus,
|
||||||
|
Save,
|
||||||
|
} from "lucide-react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { API } from "./api";
|
import { API } from "./api";
|
||||||
|
import { statusLabel } from "./statusLabels";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = "SIT0000000000001";
|
||||||
type ContentType = "NEWS" | "CASE" | "HELP";
|
type ContentType = "NEWS" | "CASE" | "HELP";
|
||||||
type Category = { categoryCode: string; parentCategoryCode: string; categoryName: string; slug: string; description?: string; sortNo: number; status: string };
|
type Category = {
|
||||||
|
categoryCode: string;
|
||||||
|
parentCategoryCode: string;
|
||||||
|
categoryName: string;
|
||||||
|
slug: string;
|
||||||
|
description?: string;
|
||||||
|
sortNo: number;
|
||||||
|
status: string;
|
||||||
|
};
|
||||||
type TreeCategory = Category & { depth: number; children: TreeCategory[] };
|
type TreeCategory = Category & { depth: number; children: TreeCategory[] };
|
||||||
type Props = { contentType?: ContentType };
|
type Props = { contentType?: ContentType };
|
||||||
type Seo = { title: string; description: string; keywords: string; h1: string; canonicalUrl: string; robots: string; status: string };
|
type Seo = {
|
||||||
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(); }
|
title: string;
|
||||||
|
description: string;
|
||||||
|
keywords: string;
|
||||||
|
h1: string;
|
||||||
|
canonicalUrl: string;
|
||||||
|
robots: string;
|
||||||
|
status: string;
|
||||||
|
};
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 规范分类层级路径,保留斜杠并清理每一级中的非法字符。 */
|
||||||
|
function normalizeCategoryPath(value: string): string {
|
||||||
|
return value
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9/-]/g, "-")
|
||||||
|
.replace(/-{2,}/g, "-")
|
||||||
|
.replace(/\/{2,}/g, "/")
|
||||||
|
.replace(/^\/+/, "");
|
||||||
|
}
|
||||||
|
|
||||||
/** 产品、新闻、案例和帮助分类管理及分类 SEO 编辑页面。 */
|
/** 产品、新闻、案例和帮助分类管理及分类 SEO 编辑页面。 */
|
||||||
export default function CategoryManager({ contentType }: Props) {
|
export default function CategoryManager({ contentType }: Props) {
|
||||||
const isProduct = !contentType; const label = isProduct ? "产品" : ({ NEWS: "新闻", CASE: "案例", HELP: "帮助" } as const)[contentType]; const maxDepth = isProduct ? 3 : 2; const basePath = isProduct ? "/products/categories" : "/contents/categories"; const seoPageType = isProduct ? "PRODUCT_CATEGORY_DETAIL" : `${contentType}_CATEGORY_DETAIL`;
|
const isProduct = !contentType;
|
||||||
const [items, setItems] = useState<Category[]>([]); const [expanded, setExpanded] = useState<Set<string>>(new Set()); const [editing, setEditing] = useState<Category | null | undefined>(undefined); const [parentCode, setParentCode] = useState(""); const [error, setError] = useState(""); const [saving, setSaving] = useState(false);
|
const label = isProduct
|
||||||
const [form, setForm] = useState({ categoryName: "", slug: "", description: "", sortNo: 30, status: "DRAFT" }); const [seo, setSeo] = useState<Seo>({ title: "", description: "", keywords: "", h1: "", canonicalUrl: "", robots: "index,follow", status: "DRAFT" });
|
? "产品"
|
||||||
const load = async () => { try { setError(""); const data = await post(`${basePath}/list`, isProduct ? { siteCode: SITE } : { siteCode: SITE, contentType }); setItems(data.items || []); setExpanded(new Set((data.items || []).map((item: Category) => item.categoryCode))); } catch (e) { setError(e instanceof Error ? e.message : "分类加载失败"); } };
|
: ({ NEWS: "新闻", CASE: "案例", HELP: "帮助" } as const)[contentType];
|
||||||
useEffect(() => { void load(); }, [contentType]);
|
const maxDepth = isProduct ? 3 : 2;
|
||||||
const tree = useMemo(() => { const map = new Map<string, Category[]>(); items.forEach((item) => { const parent = item.parentCategoryCode || ""; map.set(parent, [...(map.get(parent) || []), item]); }); const build = (parent: string, depth: number): TreeCategory[] => (map.get(parent) || []).sort((a, b) => a.sortNo - b.sortNo).map((item) => ({ ...item, depth, children: build(item.categoryCode, depth + 1) })); return build("", 1); }, [items]);
|
const basePath = isProduct ? "/products/categories" : "/contents/categories";
|
||||||
const rows = useMemo(() => { const result: TreeCategory[] = []; const append = (nodes: TreeCategory[]) => nodes.forEach((node) => { result.push(node); if (expanded.has(node.categoryCode)) append(node.children); }); append(tree); return result; }, [tree, expanded]);
|
const seoPageType = isProduct
|
||||||
|
? "PRODUCT_CATEGORY_DETAIL"
|
||||||
|
: `${contentType}_CATEGORY_DETAIL`;
|
||||||
|
const [items, setItems] = useState<Category[]>([]);
|
||||||
|
const [expanded, setExpanded] = useState<Set<string>>(new Set());
|
||||||
|
const [editing, setEditing] = useState<Category | null | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
const [parentCode, setParentCode] = useState("");
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
categoryName: "",
|
||||||
|
slug: "",
|
||||||
|
description: "",
|
||||||
|
sortNo: 30,
|
||||||
|
status: "DRAFT",
|
||||||
|
});
|
||||||
|
const [seo, setSeo] = useState<Seo>({
|
||||||
|
title: "",
|
||||||
|
description: "",
|
||||||
|
keywords: "",
|
||||||
|
h1: "",
|
||||||
|
canonicalUrl: "",
|
||||||
|
robots: "index,follow",
|
||||||
|
status: "DRAFT",
|
||||||
|
});
|
||||||
|
const load = async () => {
|
||||||
|
try {
|
||||||
|
setError("");
|
||||||
|
const data = await post(
|
||||||
|
`${basePath}/list`,
|
||||||
|
isProduct ? { siteCode: SITE } : { siteCode: SITE, contentType },
|
||||||
|
);
|
||||||
|
setItems(data.items || []);
|
||||||
|
setExpanded(
|
||||||
|
new Set((data.items || []).map((item: Category) => item.categoryCode)),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
setError(e instanceof Error ? e.message : "分类加载失败");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, [contentType]);
|
||||||
|
const tree = useMemo(() => {
|
||||||
|
const map = new Map<string, Category[]>();
|
||||||
|
items.forEach((item) => {
|
||||||
|
const parent = item.parentCategoryCode || "";
|
||||||
|
map.set(parent, [...(map.get(parent) || []), item]);
|
||||||
|
});
|
||||||
|
const build = (parent: string, depth: number): TreeCategory[] =>
|
||||||
|
(map.get(parent) || [])
|
||||||
|
.sort((a, b) => a.sortNo - b.sortNo)
|
||||||
|
.map((item) => ({
|
||||||
|
...item,
|
||||||
|
depth,
|
||||||
|
children: build(item.categoryCode, depth + 1),
|
||||||
|
}));
|
||||||
|
return build("", 1);
|
||||||
|
}, [items]);
|
||||||
|
const rows = useMemo(() => {
|
||||||
|
const result: TreeCategory[] = [];
|
||||||
|
const append = (nodes: TreeCategory[]) =>
|
||||||
|
nodes.forEach((node) => {
|
||||||
|
result.push(node);
|
||||||
|
if (expanded.has(node.categoryCode)) append(node.children);
|
||||||
|
});
|
||||||
|
append(tree);
|
||||||
|
return result;
|
||||||
|
}, [tree, expanded]);
|
||||||
/** 打开分类独立编辑页面。 */
|
/** 打开分类独立编辑页面。 */
|
||||||
const openEditor = (item: Category | null, parent = "") => { setEditing(item); setParentCode(item?.parentCategoryCode || parent); setForm({ categoryName: item?.categoryName || "", slug: item?.slug || "", description: item?.description || "", sortNo: item?.sortNo || 30, status: item?.status || "DRAFT" }); setSeo({ title: item?.categoryName || "", description: item?.description || "", keywords: "", h1: item?.categoryName || "", canonicalUrl: item ? `/${isProduct ? "products" : contentType!.toLowerCase()}/${item.slug}` : "", robots: "index,follow", status: item?.status || "DRAFT" }); if (item) void post("/seo/detail", { siteCode: SITE, pageType: seoPageType, targetCode: item.categoryCode }).then((data) => setSeo({ title: data.title || item.categoryName, description: data.description || item.description || "", keywords: data.keywords || "", h1: data.h1 || item.categoryName, canonicalUrl: data.canonicalUrl || `/${isProduct ? "products" : contentType!.toLowerCase()}/${item.slug}`, robots: data.robots || "index,follow", status: data.status || item.status })).catch(() => undefined); };
|
const openEditor = (item: Category | null, requestedParentCode = "") => {
|
||||||
|
setEditing(item);
|
||||||
|
setParentCode(item?.parentCategoryCode || requestedParentCode);
|
||||||
|
const parent = requestedParentCode
|
||||||
|
? items.find((category) => category.categoryCode === requestedParentCode)
|
||||||
|
: undefined;
|
||||||
|
setForm({
|
||||||
|
categoryName: item?.categoryName || "",
|
||||||
|
slug: item?.slug || (parent ? `${parent.slug}/` : ""),
|
||||||
|
description: item?.description || "",
|
||||||
|
sortNo: item?.sortNo || 30,
|
||||||
|
status: item?.status || "DRAFT",
|
||||||
|
});
|
||||||
|
setSeo({
|
||||||
|
title: item?.categoryName || "",
|
||||||
|
description: item?.description || "",
|
||||||
|
keywords: "",
|
||||||
|
h1: item?.categoryName || "",
|
||||||
|
canonicalUrl: item
|
||||||
|
? `/${isProduct ? "products" : contentType!.toLowerCase()}/${item.slug}`
|
||||||
|
: "",
|
||||||
|
robots: "index,follow",
|
||||||
|
status: item?.status || "DRAFT",
|
||||||
|
});
|
||||||
|
if (item)
|
||||||
|
void post("/seo/detail", {
|
||||||
|
siteCode: SITE,
|
||||||
|
pageType: seoPageType,
|
||||||
|
targetCode: item.categoryCode,
|
||||||
|
})
|
||||||
|
.then((data) =>
|
||||||
|
setSeo({
|
||||||
|
title: data.title || item.categoryName,
|
||||||
|
description: data.description || item.description || "",
|
||||||
|
keywords: data.keywords || "",
|
||||||
|
h1: data.h1 || item.categoryName,
|
||||||
|
canonicalUrl:
|
||||||
|
data.canonicalUrl ||
|
||||||
|
`/${isProduct ? "products" : contentType!.toLowerCase()}/${item.slug}`,
|
||||||
|
robots: data.robots || "index,follow",
|
||||||
|
status: data.status || item.status,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.catch(() => undefined);
|
||||||
|
};
|
||||||
/** 保存分类与已有分类 SEO。 */
|
/** 保存分类与已有分类 SEO。 */
|
||||||
const save = async () => { try { setSaving(true); setError(""); await post(`${basePath}/save`, { categoryCode: editing?.categoryCode, siteCode: SITE, ...(isProduct ? {} : { contentType }), parentCategoryCode: parentCode, categoryName: form.categoryName, slug: form.slug, description: form.description, coverMediaCode: null, sortNo: form.sortNo, status: form.status }); if (editing?.categoryCode) await post("/seo/save", { siteCode: SITE, pageType: seoPageType, targetCode: editing.categoryCode, ...seo, ogTitle: seo.title, ogDescription: seo.description, structuredData: null, headings: [] }); setEditing(undefined); await load(); } catch (e) { setError(e instanceof Error ? e.message : "分类保存失败"); } finally { setSaving(false); } };
|
const save = async () => {
|
||||||
if (editing !== undefined) return <div className="category-editor"><header><div className="navigation-editor-title"><button className="icon-button" onClick={() => setEditing(undefined)}><ArrowLeft size={18}/></button><div><h1>{editing ? `编辑${label}分类` : `新增${label}分类`}</h1><p>{parentCode ? "当前分类将创建在所选父分类下" : "创建顶级分类"}</p></div></div><div className="header-actions"><button className="secondary" onClick={() => setEditing(undefined)}>取消</button><button className="primary" disabled={saving || !form.categoryName || !form.slug} onClick={() => void save()}><Save size={17}/>{saving ? "保存中" : "保存"}</button></div></header>{error && <div className="notice">{error}</div>}<div className="category-editor-layout"><section className="category-editor-main"><section className="edit-section"><h2>分类信息</h2><div className="form-grid"><label><span>分类名称 *</span><input value={form.categoryName} onChange={(e) => setForm({ ...form, categoryName: e.target.value })}/></label><label><span>英文路径 *</span><input value={form.slug} onChange={(e) => setForm({ ...form, slug: e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, "-") })}/></label><label className="wide"><span>分类描述</span><textarea rows={5} value={form.description} onChange={(e) => setForm({ ...form, description: e.target.value })}/></label><label><span>排序</span><input type="number" value={form.sortNo} onChange={(e) => setForm({ ...form, sortNo: Number(e.target.value) })}/></label></div></section></section><aside className="category-editor-side"><section className="edit-section"><h2>发布</h2><label><span>状态</span><select value={form.status} onChange={(e) => { setForm({ ...form, status: e.target.value }); setSeo({ ...seo, status: e.target.value }); }}><option value="DRAFT">草稿</option><option value="PUBLISHED">上架</option><option value="OFFLINE">下线</option></select></label></section><section className="edit-section"><h2>搜索引擎优化</h2>{(["title", "description", "keywords", "h1", "canonicalUrl"] as const).map((key) => <label key={key}><span>{{ title: "SEO 标题 *", description: "SEO 描述 *", keywords: "SEO 关键词", h1: "页面 H1 *", canonicalUrl: "Canonical" }[key]}</span>{key === "description" ? <textarea rows={5} value={seo[key]} onChange={(e) => setSeo({ ...seo, [key]: e.target.value })}/> : <input value={seo[key]} onChange={(e) => setSeo({ ...seo, [key]: e.target.value })}/>}</label>)}<label><span>Robots</span><select value={seo.robots} onChange={(e) => setSeo({ ...seo, robots: e.target.value })}><option value="index,follow">允许索引并跟踪链接</option><option value="noindex,nofollow">不索引且不跟踪链接</option></select></label></section></aside></div></div>;
|
try {
|
||||||
return <div className="category-manager"><div className="category-heading"><div><h1>{label}分类</h1><p>最多支持 {maxDepth} 级分类,使用英文名称维护前台目录。</p></div><button className="primary" onClick={() => openEditor(null)}><Plus size={17}/>添加分类</button></div>{error && <div className="notice">{error}</div>}<section className="category-table"><div className="category-table-head"><span>分类</span><span>英文路径</span><span>状态</span><span>操作</span></div>{rows.length === 0 ? <div className="empty"><strong>暂无{label}分类</strong><p>点击右上角添加第一个顶级分类。</p></div> : rows.map((item) => <div className="category-row" key={item.categoryCode}><div className="category-name" style={{ paddingLeft: `${(item.depth - 1) * 28}px` }}>{item.children.length ? <button className="tree-toggle" onClick={() => setExpanded((current) => { const next = new Set(current); next.has(item.categoryCode) ? next.delete(item.categoryCode) : next.add(item.categoryCode); return next; })}>{expanded.has(item.categoryCode) ? <ChevronDown size={17}/> : <ChevronRight size={17}/>}</button> : <span className="tree-space"/>}<strong>{item.categoryName}</strong><small>{item.categoryCode}</small></div><code>/{item.slug}</code><span className={`status ${item.status.toLowerCase()}`}>{item.status}</span><div className="category-actions">{item.depth < maxDepth && <button title="新增子分类" onClick={() => openEditor(null, item.categoryCode)}><Plus size={17}/></button>}<button title="编辑分类" onClick={() => openEditor(item)}><Edit3 size={17}/></button></div></div>)}</section></div>;
|
setSaving(true);
|
||||||
|
setError("");
|
||||||
|
await post(`${basePath}/save`, {
|
||||||
|
categoryCode: editing?.categoryCode,
|
||||||
|
siteCode: SITE,
|
||||||
|
...(isProduct ? {} : { contentType }),
|
||||||
|
parentCategoryCode: parentCode,
|
||||||
|
categoryName: form.categoryName,
|
||||||
|
slug: form.slug,
|
||||||
|
description: form.description,
|
||||||
|
coverMediaCode: null,
|
||||||
|
sortNo: form.sortNo,
|
||||||
|
status: form.status,
|
||||||
|
});
|
||||||
|
if (editing?.categoryCode)
|
||||||
|
await post("/seo/save", {
|
||||||
|
siteCode: SITE,
|
||||||
|
pageType: seoPageType,
|
||||||
|
targetCode: editing.categoryCode,
|
||||||
|
...seo,
|
||||||
|
ogTitle: seo.title,
|
||||||
|
ogDescription: seo.description,
|
||||||
|
structuredData: null,
|
||||||
|
headings: [],
|
||||||
|
});
|
||||||
|
setEditing(undefined);
|
||||||
|
await load();
|
||||||
|
} catch (e) {
|
||||||
|
setError(e instanceof Error ? e.message : "分类保存失败");
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (editing !== undefined)
|
||||||
|
return (
|
||||||
|
<div className="category-editor">
|
||||||
|
<header>
|
||||||
|
<div className="navigation-editor-title">
|
||||||
|
<button
|
||||||
|
className="icon-button"
|
||||||
|
onClick={() => setEditing(undefined)}
|
||||||
|
>
|
||||||
|
<ArrowLeft size={18} />
|
||||||
|
</button>
|
||||||
|
<div>
|
||||||
|
<h1>{editing ? `编辑${label}分类` : `新增${label}分类`}</h1>
|
||||||
|
<p>
|
||||||
|
{parentCode ? "当前分类将创建在所选父分类下" : "创建顶级分类"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="header-actions">
|
||||||
|
<button className="secondary" onClick={() => setEditing(undefined)}>
|
||||||
|
取消
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="primary"
|
||||||
|
disabled={saving || !form.categoryName || !form.slug}
|
||||||
|
onClick={() => void save()}
|
||||||
|
>
|
||||||
|
<Save size={17} />
|
||||||
|
{saving ? "保存中" : "保存"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
{error && <div className="notice">{error}</div>}
|
||||||
|
<div className="category-editor-layout">
|
||||||
|
<section className="category-editor-main">
|
||||||
|
<section className="edit-section">
|
||||||
|
<h2>分类信息</h2>
|
||||||
|
<div className="form-grid">
|
||||||
|
<label>
|
||||||
|
<span>分类名称 *</span>
|
||||||
|
<input
|
||||||
|
value={form.categoryName}
|
||||||
|
onChange={(e) =>
|
||||||
|
setForm({ ...form, categoryName: e.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>英文路径 *</span>
|
||||||
|
<input
|
||||||
|
value={form.slug}
|
||||||
|
onChange={(e) => setForm({ ...form, slug: normalizeCategoryPath(e.target.value) })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="wide">
|
||||||
|
<span>分类描述</span>
|
||||||
|
<textarea
|
||||||
|
rows={5}
|
||||||
|
value={form.description}
|
||||||
|
onChange={(e) =>
|
||||||
|
setForm({ ...form, description: e.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>排序</span>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={form.sortNo}
|
||||||
|
onChange={(e) =>
|
||||||
|
setForm({ ...form, sortNo: Number(e.target.value) })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
<aside className="category-editor-side">
|
||||||
|
<section className="edit-section">
|
||||||
|
<h2>发布</h2>
|
||||||
|
<label>
|
||||||
|
<span>状态</span>
|
||||||
|
<select
|
||||||
|
value={form.status}
|
||||||
|
onChange={(e) => {
|
||||||
|
setForm({ ...form, status: e.target.value });
|
||||||
|
setSeo({ ...seo, status: e.target.value });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="DRAFT">草稿</option>
|
||||||
|
<option value="PUBLISHED">上架</option>
|
||||||
|
<option value="OFFLINE">下线</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
<section className="edit-section">
|
||||||
|
<h2>搜索引擎优化</h2>
|
||||||
|
{(
|
||||||
|
[
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"keywords",
|
||||||
|
"h1",
|
||||||
|
"canonicalUrl",
|
||||||
|
] as const
|
||||||
|
).map((key) => (
|
||||||
|
<label key={key}>
|
||||||
|
<span>
|
||||||
|
{
|
||||||
|
{
|
||||||
|
title: "SEO 标题 *",
|
||||||
|
description: "SEO 描述 *",
|
||||||
|
keywords: "SEO 关键词",
|
||||||
|
h1: "页面 H1 *",
|
||||||
|
canonicalUrl: "Canonical",
|
||||||
|
}[key]
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
{key === "description" ? (
|
||||||
|
<textarea
|
||||||
|
rows={5}
|
||||||
|
value={seo[key]}
|
||||||
|
onChange={(e) =>
|
||||||
|
setSeo({ ...seo, [key]: e.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<input
|
||||||
|
value={seo[key]}
|
||||||
|
onChange={(e) =>
|
||||||
|
setSeo({ ...seo, [key]: e.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
<label>
|
||||||
|
<span>Robots</span>
|
||||||
|
<select
|
||||||
|
value={seo.robots}
|
||||||
|
onChange={(e) => setSeo({ ...seo, robots: e.target.value })}
|
||||||
|
>
|
||||||
|
<option value="index,follow">允许索引并跟踪链接</option>
|
||||||
|
<option value="noindex,nofollow">不索引且不跟踪链接</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<div className="category-manager">
|
||||||
|
<div className="category-heading">
|
||||||
|
<div>
|
||||||
|
<h1>{label}分类</h1>
|
||||||
|
<p>最多支持 {maxDepth} 级分类,使用英文名称维护前台目录。</p>
|
||||||
|
</div>
|
||||||
|
<button className="primary" onClick={() => openEditor(null)}>
|
||||||
|
<Plus size={17} />
|
||||||
|
添加分类
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{error && <div className="notice">{error}</div>}
|
||||||
|
<section className="category-table">
|
||||||
|
<div className="category-table-head">
|
||||||
|
<span>分类</span>
|
||||||
|
<span>英文路径</span>
|
||||||
|
<span>状态</span>
|
||||||
|
<span>操作</span>
|
||||||
|
</div>
|
||||||
|
{rows.length === 0 ? (
|
||||||
|
<div className="empty">
|
||||||
|
<strong>暂无{label}分类</strong>
|
||||||
|
<p>点击右上角添加第一个顶级分类。</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
rows.map((item) => (
|
||||||
|
<div className="category-row" key={item.categoryCode}>
|
||||||
|
<div
|
||||||
|
className="category-name"
|
||||||
|
style={{ paddingLeft: `${(item.depth - 1) * 28}px` }}
|
||||||
|
>
|
||||||
|
{item.children.length ? (
|
||||||
|
<button
|
||||||
|
className="tree-toggle"
|
||||||
|
onClick={() =>
|
||||||
|
setExpanded((current) => {
|
||||||
|
const next = new Set(current);
|
||||||
|
next.has(item.categoryCode)
|
||||||
|
? next.delete(item.categoryCode)
|
||||||
|
: next.add(item.categoryCode);
|
||||||
|
return next;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{expanded.has(item.categoryCode) ? (
|
||||||
|
<ChevronDown size={17} />
|
||||||
|
) : (
|
||||||
|
<ChevronRight size={17} />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<span className="tree-space" />
|
||||||
|
)}
|
||||||
|
<strong>{item.categoryName}</strong>
|
||||||
|
<small>{item.categoryCode}</small>
|
||||||
|
</div>
|
||||||
|
<code>/{item.slug}</code>
|
||||||
|
<span className={`status ${item.status.toLowerCase()}`}>
|
||||||
|
{statusLabel(item.status)}
|
||||||
|
</span>
|
||||||
|
<div className="category-actions">
|
||||||
|
{item.depth < maxDepth && (
|
||||||
|
<button
|
||||||
|
title="新增子分类"
|
||||||
|
onClick={() => openEditor(null, item.categoryCode)}
|
||||||
|
>
|
||||||
|
<Plus size={17} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<button title="编辑分类" onClick={() => openEditor(item)}>
|
||||||
|
<Edit3 size={17} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -1,51 +1,745 @@
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { ChevronDown, ChevronUp, Copy, Eye, EyeOff, GripVertical, Monitor, Plus, Redo2, Save, Smartphone, Tablet, Trash2, Undo2, X, ExternalLink } from "lucide-react";
|
import {
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
|
Copy,
|
||||||
|
Eye,
|
||||||
|
EyeOff,
|
||||||
|
GripVertical,
|
||||||
|
Monitor,
|
||||||
|
Plus,
|
||||||
|
Redo2,
|
||||||
|
Save,
|
||||||
|
Smartphone,
|
||||||
|
Tablet,
|
||||||
|
Trash2,
|
||||||
|
Undo2,
|
||||||
|
X,
|
||||||
|
ExternalLink,
|
||||||
|
} from "lucide-react";
|
||||||
import { API } from "./api";
|
import { API } from "./api";
|
||||||
|
import { statusLabel } from "./statusLabels";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = "SIT0000000000001";
|
||||||
type Viewport = "desktop" | "tablet" | "mobile";
|
type Viewport = "desktop" | "tablet" | "mobile";
|
||||||
type SectionType = "ANNOUNCEMENT" | "HEADER" | "HERO" | "RICH_TEXT" | "PRODUCTS" | "CONTENT" | "INQUIRY" | "FOOTER";
|
type SectionType =
|
||||||
type Section = { id: string; type: SectionType; title: string; subtitle: string; imageUrl: string; buttonText: string; buttonUrl: string; sourceType: string; limit: number; visible: boolean; background: string; textColor: string };
|
| "ANNOUNCEMENT"
|
||||||
type Schema = { global: { primaryColor: string; backgroundColor: string; textColor: string; fontFamily: string; contentWidth: number }; sections: Section[] };
|
| "HEADER"
|
||||||
const labels: Record<SectionType, string> = { ANNOUNCEMENT: "公告栏", HEADER: "导航栏", HERO: "轮播横幅", RICH_TEXT: "富文本", PRODUCTS: "产品展示", CONTENT: "内容展示", INQUIRY: "询盘表单", FOOTER: "页脚" };
|
| "HERO"
|
||||||
const initialSchema: Schema = { global: { primaryColor: "#176b5d", backgroundColor: "#ffffff", textColor: "#17211f", fontFamily: "Inter", contentWidth: 1200 }, sections: [] };
|
| "RICH_TEXT"
|
||||||
const pageOptions = [{ value: "HOME", label: "首页", path: "/" }, { value: "PRODUCT_CATEGORY", label: "产品分类页", path: "/products" }, { value: "PRODUCT_DETAIL", label: "产品详情页", path: "/products" }, { value: "NEWS_CATEGORY", label: "新闻分类页", path: "/news" }, { value: "NEWS_DETAIL", label: "新闻详情页", path: "/news" }, { value: "CASE_CATEGORY", label: "案例分类页", path: "/cases" }, { value: "CASE_DETAIL", label: "案例详情页", path: "/cases" }, { value: "HELP_CATEGORY", label: "帮助分类页", path: "/help" }, { value: "HELP_DETAIL", label: "帮助详情页", path: "/help" }, { value: "ABOUT_US", label: "关于我们", path: "/about-us" }, { value: "CUSTOM_PAGE", label: "自定义页面", path: "/custom-page" }];
|
| "PRODUCTS"
|
||||||
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(); }
|
| "CONTENT"
|
||||||
function createSection(type: SectionType): Section { return { id: `${type.toLowerCase()}-${Date.now()}`, type, title: type === "HERO" ? "Reliable equipment for demanding operations." : labels[type], subtitle: type === "HERO" ? "Industrial products and project-proven solutions for global B2B customers." : "", imageUrl: "", buttonText: type === "HERO" ? "Explore Products" : "", buttonUrl: type === "HERO" ? "/products" : "", sourceType: type === "CONTENT" ? "CASE" : "", limit: 3, visible: true, background: type === "HEADER" || type === "FOOTER" ? "#101a25" : "#ffffff", textColor: type === "HEADER" || type === "FOOTER" ? "#ffffff" : "#17211f" }; }
|
| "INQUIRY"
|
||||||
|
| "FOOTER";
|
||||||
|
type Section = {
|
||||||
|
id: string;
|
||||||
|
type: SectionType;
|
||||||
|
title: string;
|
||||||
|
subtitle: string;
|
||||||
|
imageUrl: string;
|
||||||
|
buttonText: string;
|
||||||
|
buttonUrl: string;
|
||||||
|
sourceType: string;
|
||||||
|
limit: number;
|
||||||
|
visible: boolean;
|
||||||
|
background: string;
|
||||||
|
textColor: string;
|
||||||
|
};
|
||||||
|
type Schema = {
|
||||||
|
global: {
|
||||||
|
primaryColor: string;
|
||||||
|
backgroundColor: string;
|
||||||
|
textColor: string;
|
||||||
|
fontFamily: string;
|
||||||
|
contentWidth: number;
|
||||||
|
};
|
||||||
|
sections: Section[];
|
||||||
|
};
|
||||||
|
const labels: Record<SectionType, string> = {
|
||||||
|
ANNOUNCEMENT: "公告栏",
|
||||||
|
HEADER: "导航栏",
|
||||||
|
HERO: "轮播横幅",
|
||||||
|
RICH_TEXT: "富文本",
|
||||||
|
PRODUCTS: "产品展示",
|
||||||
|
CONTENT: "内容展示",
|
||||||
|
INQUIRY: "询盘表单",
|
||||||
|
FOOTER: "页脚",
|
||||||
|
};
|
||||||
|
const initialSchema: Schema = {
|
||||||
|
global: {
|
||||||
|
primaryColor: "#176b5d",
|
||||||
|
backgroundColor: "#ffffff",
|
||||||
|
textColor: "#17211f",
|
||||||
|
fontFamily: "Inter",
|
||||||
|
contentWidth: 1200,
|
||||||
|
},
|
||||||
|
sections: [],
|
||||||
|
};
|
||||||
|
const pageOptions = [
|
||||||
|
{ value: "HOME", label: "首页", path: "/" },
|
||||||
|
{ value: "PRODUCT_CATEGORY", label: "产品分类页", path: "/products" },
|
||||||
|
{ value: "PRODUCT_DETAIL", label: "产品详情页", path: "/products" },
|
||||||
|
{ value: "NEWS_CATEGORY", label: "新闻分类页", path: "/news" },
|
||||||
|
{ value: "NEWS_DETAIL", label: "新闻详情页", path: "/news" },
|
||||||
|
{ value: "CASE_CATEGORY", label: "案例分类页", path: "/cases" },
|
||||||
|
{ value: "CASE_DETAIL", label: "案例详情页", path: "/cases" },
|
||||||
|
{ value: "HELP_CATEGORY", label: "帮助分类页", path: "/help" },
|
||||||
|
{ value: "HELP_DETAIL", label: "帮助详情页", path: "/help" },
|
||||||
|
{ value: "ABOUT_US", label: "关于我们", path: "/about-us" },
|
||||||
|
{ value: "CUSTOM_PAGE", label: "自定义页面", path: "/custom-page" },
|
||||||
|
];
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
function createSection(type: SectionType): Section {
|
||||||
|
return {
|
||||||
|
id: `${type.toLowerCase()}-${Date.now()}`,
|
||||||
|
type,
|
||||||
|
title:
|
||||||
|
type === "HERO"
|
||||||
|
? "Reliable equipment for demanding operations."
|
||||||
|
: labels[type],
|
||||||
|
subtitle:
|
||||||
|
type === "HERO"
|
||||||
|
? "Industrial products and project-proven solutions for global B2B customers."
|
||||||
|
: "",
|
||||||
|
imageUrl: "",
|
||||||
|
buttonText: type === "HERO" ? "Explore Products" : "",
|
||||||
|
buttonUrl: type === "HERO" ? "/products" : "",
|
||||||
|
sourceType: type === "CONTENT" ? "CASE" : "",
|
||||||
|
limit: 3,
|
||||||
|
visible: true,
|
||||||
|
background: type === "HEADER" || type === "FOOTER" ? "#101a25" : "#ffffff",
|
||||||
|
textColor: type === "HEADER" || type === "FOOTER" ? "#ffffff" : "#17211f",
|
||||||
|
};
|
||||||
|
}
|
||||||
export default function DecorationEditor({ onBack }: { onBack: () => void }) {
|
export default function DecorationEditor({ onBack }: { onBack: () => void }) {
|
||||||
const [pageType, setPageType] = useState("HOME");
|
const [pageType, setPageType] = useState("HOME");
|
||||||
const [schema, setSchema] = useState<Schema>(initialSchema); const [history, setHistory] = useState<Schema[]>([]); const [future, setFuture] = useState<Schema[]>([]);
|
const [schema, setSchema] = useState<Schema>(initialSchema);
|
||||||
const [selected, setSelected] = useState<string | null>(null); const [globalMode, setGlobalMode] = useState(false); const [viewport, setViewport] = useState<Viewport>("desktop"); const [notice, setNotice] = useState(""); const [status, setStatus] = useState("DRAFT"); const [version, setVersion] = useState(0);
|
const [history, setHistory] = useState<Schema[]>([]);
|
||||||
useEffect(() => { setSelected(null); setGlobalMode(false); setHistory([]); setFuture([]); post("/decorations/detail", { siteCode: SITE, pageType }).then(data => { setSchema(JSON.parse(data.schema)); setStatus(data.status); setVersion(data.publishedVersion); }).catch(error => setNotice(error.message)); }, [pageType]);
|
const [future, setFuture] = useState<Schema[]>([]);
|
||||||
const commit = (next: Schema) => { setHistory(items => [...items.slice(-19), schema]); setFuture([]); setSchema(next); };
|
const [selected, setSelected] = useState<string | null>(null);
|
||||||
const updateSection = (id: string, patch: Partial<Section>) => commit({ ...schema, sections: schema.sections.map(item => item.id === id ? { ...item, ...patch } : item) });
|
const [globalMode, setGlobalMode] = useState(false);
|
||||||
const active = schema.sections.find(item => item.id === selected);
|
const [viewport, setViewport] = useState<Viewport>("desktop");
|
||||||
const add = (type: SectionType) => { const item = createSection(type); commit({ ...schema, sections: [...schema.sections, item] }); setSelected(item.id); setGlobalMode(false); };
|
const [notice, setNotice] = useState("");
|
||||||
const move = (index: number, offset: number) => { const target = index + offset; if (target < 0 || target >= schema.sections.length) return; const sections = [...schema.sections]; [sections[index], sections[target]] = [sections[target], sections[index]]; commit({ ...schema, sections }); };
|
const [status, setStatus] = useState("DRAFT");
|
||||||
const undo = () => { const previous = history.at(-1); if (!previous) return; setFuture(items => [schema, ...items]); setSchema(previous); setHistory(items => items.slice(0, -1)); };
|
const [version, setVersion] = useState(0);
|
||||||
const redo = () => { const next = future[0]; if (!next) return; setHistory(items => [...items, schema]); setSchema(next); setFuture(items => items.slice(1)); };
|
useEffect(() => {
|
||||||
const save = async () => { await post("/decorations/save", { siteCode: SITE, pageType, schema: JSON.stringify(schema) }); setNotice("装修草稿已保存"); };
|
setSelected(null);
|
||||||
const publish = async () => { await save(); await post("/decorations/publish", { siteCode: SITE, pageType }); setStatus("PUBLISHED"); setVersion(value => value + 1); setNotice("已发布到英文前台站"); };
|
setGlobalMode(false);
|
||||||
const preview = () => { const target = pageOptions.find(item => item.value === pageType) || pageOptions[0]; window.open(`http://localhost:5174${target.path}?previewPage=${pageType}`, "_blank", "noopener,noreferrer"); };
|
setHistory([]);
|
||||||
const previewWidth = useMemo(() => viewport === "desktop" ? "100%" : viewport === "tablet" ? "820px" : "390px", [viewport]);
|
setFuture([]);
|
||||||
return <div className="decorator">
|
post("/decorations/detail", { siteCode: SITE, pageType })
|
||||||
<div className="decorator-top"><button className="icon" onClick={onBack} title="返回"><X size={19}/></button><strong>{pageOptions.find(item => item.value === pageType)?.label || "页面装修"}</strong><span className={`status ${status.toLowerCase()}`}>{status === "PUBLISHED" ? `已发布 V${version}` : "草稿"}</span><select className="decorator-page-select" value={pageType} onChange={event => setPageType(event.target.value)}>{pageOptions.map(item => <option key={item.value} value={item.value}>{item.label}</option>)}</select><button className="icon" onClick={undo} disabled={!history.length} title="撤销"><Undo2 size={18}/></button><button className="icon" onClick={redo} disabled={!future.length} title="重做"><Redo2 size={18}/></button><div className="viewport-switch"><button className={viewport === "desktop" ? "active" : ""} onClick={() => setViewport("desktop")} title="桌面"><Monitor size={18}/></button><button className={viewport === "tablet" ? "active" : ""} onClick={() => setViewport("tablet")} title="平板"><Tablet size={18}/></button><button className={viewport === "mobile" ? "active" : ""} onClick={() => setViewport("mobile")} title="手机"><Smartphone size={18}/></button></div><button className="secondary" onClick={preview}><ExternalLink size={16}/>预览</button><button className="secondary" onClick={save}><Save size={16}/>保存草稿</button><button className="primary" onClick={publish}>发布</button></div>
|
.then((data) => {
|
||||||
|
setSchema(JSON.parse(data.schema));
|
||||||
|
setStatus(data.status);
|
||||||
|
setVersion(data.publishedVersion);
|
||||||
|
})
|
||||||
|
.catch((error) => setNotice(error.message));
|
||||||
|
}, [pageType]);
|
||||||
|
const commit = (next: Schema) => {
|
||||||
|
setHistory((items) => [...items.slice(-19), schema]);
|
||||||
|
setFuture([]);
|
||||||
|
setSchema(next);
|
||||||
|
};
|
||||||
|
const updateSection = (id: string, patch: Partial<Section>) =>
|
||||||
|
commit({
|
||||||
|
...schema,
|
||||||
|
sections: schema.sections.map((item) =>
|
||||||
|
item.id === id ? { ...item, ...patch } : item,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
const active = schema.sections.find((item) => item.id === selected);
|
||||||
|
const add = (type: SectionType) => {
|
||||||
|
const item = createSection(type);
|
||||||
|
commit({ ...schema, sections: [...schema.sections, item] });
|
||||||
|
setSelected(item.id);
|
||||||
|
setGlobalMode(false);
|
||||||
|
};
|
||||||
|
const move = (index: number, offset: number) => {
|
||||||
|
const target = index + offset;
|
||||||
|
if (target < 0 || target >= schema.sections.length) return;
|
||||||
|
const sections = [...schema.sections];
|
||||||
|
[sections[index], sections[target]] = [sections[target], sections[index]];
|
||||||
|
commit({ ...schema, sections });
|
||||||
|
};
|
||||||
|
const undo = () => {
|
||||||
|
const previous = history.at(-1);
|
||||||
|
if (!previous) return;
|
||||||
|
setFuture((items) => [schema, ...items]);
|
||||||
|
setSchema(previous);
|
||||||
|
setHistory((items) => items.slice(0, -1));
|
||||||
|
};
|
||||||
|
const redo = () => {
|
||||||
|
const next = future[0];
|
||||||
|
if (!next) return;
|
||||||
|
setHistory((items) => [...items, schema]);
|
||||||
|
setSchema(next);
|
||||||
|
setFuture((items) => items.slice(1));
|
||||||
|
};
|
||||||
|
const save = async () => {
|
||||||
|
await post("/decorations/save", {
|
||||||
|
siteCode: SITE,
|
||||||
|
pageType,
|
||||||
|
schema: JSON.stringify(schema),
|
||||||
|
});
|
||||||
|
setNotice("装修草稿已保存");
|
||||||
|
};
|
||||||
|
const publish = async () => {
|
||||||
|
await save();
|
||||||
|
await post("/decorations/publish", { siteCode: SITE, pageType });
|
||||||
|
setStatus("PUBLISHED");
|
||||||
|
setVersion((value) => value + 1);
|
||||||
|
setNotice("已发布到英文前台站");
|
||||||
|
};
|
||||||
|
const preview = () => {
|
||||||
|
const target =
|
||||||
|
pageOptions.find((item) => item.value === pageType) || pageOptions[0];
|
||||||
|
window.open(
|
||||||
|
`http://localhost:5174${target.path}?previewPage=${pageType}`,
|
||||||
|
"_blank",
|
||||||
|
"noopener,noreferrer",
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const previewWidth = useMemo(
|
||||||
|
() =>
|
||||||
|
viewport === "desktop"
|
||||||
|
? "100%"
|
||||||
|
: viewport === "tablet"
|
||||||
|
? "820px"
|
||||||
|
: "390px",
|
||||||
|
[viewport],
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<div className="decorator">
|
||||||
|
<div className="decorator-top">
|
||||||
|
<button className="icon" onClick={onBack} title="返回">
|
||||||
|
<X size={19} />
|
||||||
|
</button>
|
||||||
|
<strong>
|
||||||
|
{pageOptions.find((item) => item.value === pageType)?.label ||
|
||||||
|
"页面装修"}
|
||||||
|
</strong>
|
||||||
|
<span className={`status ${status.toLowerCase()}`}>
|
||||||
|
{statusLabel(status)}
|
||||||
|
{status === "PUBLISHED" ? ` V${version}` : ""}
|
||||||
|
</span>
|
||||||
|
<select
|
||||||
|
className="decorator-page-select"
|
||||||
|
value={pageType}
|
||||||
|
onChange={(event) => setPageType(event.target.value)}
|
||||||
|
>
|
||||||
|
{pageOptions.map((item) => (
|
||||||
|
<option key={item.value} value={item.value}>
|
||||||
|
{item.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
className="icon"
|
||||||
|
onClick={undo}
|
||||||
|
disabled={!history.length}
|
||||||
|
title="撤销"
|
||||||
|
>
|
||||||
|
<Undo2 size={18} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="icon"
|
||||||
|
onClick={redo}
|
||||||
|
disabled={!future.length}
|
||||||
|
title="重做"
|
||||||
|
>
|
||||||
|
<Redo2 size={18} />
|
||||||
|
</button>
|
||||||
|
<div className="viewport-switch">
|
||||||
|
<button
|
||||||
|
className={viewport === "desktop" ? "active" : ""}
|
||||||
|
onClick={() => setViewport("desktop")}
|
||||||
|
title="桌面"
|
||||||
|
>
|
||||||
|
<Monitor size={18} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={viewport === "tablet" ? "active" : ""}
|
||||||
|
onClick={() => setViewport("tablet")}
|
||||||
|
title="平板"
|
||||||
|
>
|
||||||
|
<Tablet size={18} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={viewport === "mobile" ? "active" : ""}
|
||||||
|
onClick={() => setViewport("mobile")}
|
||||||
|
title="手机"
|
||||||
|
>
|
||||||
|
<Smartphone size={18} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<button className="secondary" onClick={preview}>
|
||||||
|
<ExternalLink size={16} />
|
||||||
|
预览
|
||||||
|
</button>
|
||||||
|
<button className="secondary" onClick={save}>
|
||||||
|
<Save size={16} />
|
||||||
|
保存草稿
|
||||||
|
</button>
|
||||||
|
<button className="primary" onClick={publish}>
|
||||||
|
发布
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
{notice && <div className="decorator-notice">{notice}</div>}
|
{notice && <div className="decorator-notice">{notice}</div>}
|
||||||
<div className="decorator-body"><aside className="decorator-tree"><div className="decorator-tabs"><button className={!globalMode ? "active" : ""} onClick={() => setGlobalMode(false)}>装修组件</button><button className={globalMode ? "active" : ""} onClick={() => { setGlobalMode(true); setSelected(null); }}>全局设置</button></div>{!globalMode && <><div className="section-tree">{schema.sections.map((item, index) => <button key={item.id} className={selected === item.id ? "selected" : ""} onClick={() => setSelected(item.id)}><GripVertical size={15}/><span>{labels[item.type]}<small>{item.title}</small></span><i onClick={event => { event.stopPropagation(); updateSection(item.id, { visible: !item.visible }); }}>{item.visible ? <Eye size={15}/> : <EyeOff size={15}/>}</i><i onClick={event => { event.stopPropagation(); move(index, -1); }}><ChevronUp size={14}/></i><i onClick={event => { event.stopPropagation(); move(index, 1); }}><ChevronDown size={14}/></i></button>)}</div><div className="component-palette"><h3>添加组件</h3>{(Object.keys(labels) as SectionType[]).map(type => <button key={type} onClick={() => add(type)}><Plus size={15}/>{labels[type]}</button>)}</div></>}</aside>
|
<div className="decorator-body">
|
||||||
<div className="decorator-stage"><div className="preview-frame" style={{ width: previewWidth, background: schema.global.backgroundColor, color: schema.global.textColor, fontFamily: schema.global.fontFamily }}>{schema.sections.filter(item => item.visible).length ? schema.sections.filter(item => item.visible).map(item => <PreviewSection key={item.id} item={item} primary={schema.global.primaryColor} selected={selected === item.id} onSelect={() => { setSelected(item.id); setGlobalMode(false); }}/>) : <div className="preview-empty"><Panels/><h2>开始装修首页</h2><p>从左侧添加轮播横幅、产品、案例或询盘表单等组件。</p></div>}</div></div>
|
<aside className="decorator-tree">
|
||||||
<aside className="decorator-settings">{globalMode ? <GlobalSettings schema={schema} onChange={global => commit({ ...schema, global })}/> : active ? <SectionSettings item={active} onChange={patch => updateSection(active.id, patch)} onDuplicate={() => { const copy = { ...active, id: `${active.type.toLowerCase()}-${Date.now()}` }; commit({ ...schema, sections: [...schema.sections, copy] }); setSelected(copy.id); }} onDelete={() => { commit({ ...schema, sections: schema.sections.filter(item => item.id !== active.id) }); setSelected(null); }}/> : <div className="settings-empty"><h3>组件设置</h3><p>在左侧组件树或中间预览中选择一个组件进行编辑。</p></div>}</aside></div>
|
<div className="decorator-tabs">
|
||||||
</div>;
|
<button
|
||||||
|
className={!globalMode ? "active" : ""}
|
||||||
|
onClick={() => setGlobalMode(false)}
|
||||||
|
>
|
||||||
|
装修组件
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={globalMode ? "active" : ""}
|
||||||
|
onClick={() => {
|
||||||
|
setGlobalMode(true);
|
||||||
|
setSelected(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
全局设置
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{!globalMode && (
|
||||||
|
<>
|
||||||
|
<div className="section-tree">
|
||||||
|
{schema.sections.map((item, index) => (
|
||||||
|
<button
|
||||||
|
key={item.id}
|
||||||
|
className={selected === item.id ? "selected" : ""}
|
||||||
|
onClick={() => setSelected(item.id)}
|
||||||
|
>
|
||||||
|
<GripVertical size={15} />
|
||||||
|
<span>
|
||||||
|
{labels[item.type]}
|
||||||
|
<small>{item.title}</small>
|
||||||
|
</span>
|
||||||
|
<i
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
updateSection(item.id, { visible: !item.visible });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.visible ? <Eye size={15} /> : <EyeOff size={15} />}
|
||||||
|
</i>
|
||||||
|
<i
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
move(index, -1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ChevronUp size={14} />
|
||||||
|
</i>
|
||||||
|
<i
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
move(index, 1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ChevronDown size={14} />
|
||||||
|
</i>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="component-palette">
|
||||||
|
<h3>添加组件</h3>
|
||||||
|
{(Object.keys(labels) as SectionType[]).map((type) => (
|
||||||
|
<button key={type} onClick={() => add(type)}>
|
||||||
|
<Plus size={15} />
|
||||||
|
{labels[type]}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</aside>
|
||||||
|
<div className="decorator-stage">
|
||||||
|
<div
|
||||||
|
className="preview-frame"
|
||||||
|
style={{
|
||||||
|
width: previewWidth,
|
||||||
|
background: schema.global.backgroundColor,
|
||||||
|
color: schema.global.textColor,
|
||||||
|
fontFamily: schema.global.fontFamily,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{schema.sections.filter((item) => item.visible).length ? (
|
||||||
|
schema.sections
|
||||||
|
.filter((item) => item.visible)
|
||||||
|
.map((item) => (
|
||||||
|
<PreviewSection
|
||||||
|
key={item.id}
|
||||||
|
item={item}
|
||||||
|
primary={schema.global.primaryColor}
|
||||||
|
selected={selected === item.id}
|
||||||
|
onSelect={() => {
|
||||||
|
setSelected(item.id);
|
||||||
|
setGlobalMode(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="preview-empty">
|
||||||
|
<Panels />
|
||||||
|
<h2>开始装修首页</h2>
|
||||||
|
<p>从左侧添加轮播横幅、产品、案例或询盘表单等组件。</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<aside className="decorator-settings">
|
||||||
|
{globalMode ? (
|
||||||
|
<GlobalSettings
|
||||||
|
schema={schema}
|
||||||
|
onChange={(global) => commit({ ...schema, global })}
|
||||||
|
/>
|
||||||
|
) : active ? (
|
||||||
|
<SectionSettings
|
||||||
|
item={active}
|
||||||
|
onChange={(patch) => updateSection(active.id, patch)}
|
||||||
|
onDuplicate={() => {
|
||||||
|
const copy = {
|
||||||
|
...active,
|
||||||
|
id: `${active.type.toLowerCase()}-${Date.now()}`,
|
||||||
|
};
|
||||||
|
commit({ ...schema, sections: [...schema.sections, copy] });
|
||||||
|
setSelected(copy.id);
|
||||||
|
}}
|
||||||
|
onDelete={() => {
|
||||||
|
commit({
|
||||||
|
...schema,
|
||||||
|
sections: schema.sections.filter(
|
||||||
|
(item) => item.id !== active.id,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
setSelected(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="settings-empty">
|
||||||
|
<h3>组件设置</h3>
|
||||||
|
<p>在左侧组件树或中间预览中选择一个组件进行编辑。</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
function Panels() { return <div className="empty-panels"><span/><span/><span/></div>; }
|
function Panels() {
|
||||||
function PreviewSection({ item, primary, selected, onSelect }: { item: Section; primary: string; selected: boolean; onSelect: () => void }) { const style = { background: item.background, color: item.textColor, outline: selected ? `2px solid ${primary}` : undefined };
|
return (
|
||||||
if (item.type === "ANNOUNCEMENT") return <section className="pv-announcement" style={style} onClick={onSelect}>{item.title || "Free consultation for your next industrial project"}</section>;
|
<div className="empty-panels">
|
||||||
if (item.type === "HEADER") return <section className="pv-header" style={style} onClick={onSelect}><b>SHOPLIX</b><nav>Products Solutions News About Us Contact</nav><button style={{background:primary}}>Get a quote</button></section>;
|
<span />
|
||||||
if (item.type === "HERO") return <section className="pv-hero" style={{...style, backgroundImage: item.imageUrl ? `linear-gradient(90deg,rgba(0,0,0,.65),rgba(0,0,0,.1)),url(${item.imageUrl})` : undefined}} onClick={onSelect}><div><span>ENGINEERED FOR INDUSTRY</span><h1>{item.title}</h1><p>{item.subtitle}</p>{item.buttonText && <button style={{background:primary}}>{item.buttonText}</button>}</div></section>;
|
<span />
|
||||||
if (item.type === "RICH_TEXT") return <section className="pv-rich" style={style} onClick={onSelect}><h2>{item.title}</h2><p>{item.subtitle || "Add your English introduction, advantages or service description here."}</p></section>;
|
<span />
|
||||||
if (item.type === "PRODUCTS" || item.type === "CONTENT") return <section className="pv-collection" style={style} onClick={onSelect}><p>FEATURED</p><h2>{item.title}</h2><div>{Array.from({length: Math.min(item.limit, 4)}, (_, i) => <article key={i}><span>{item.type === "PRODUCTS" ? "PRODUCT" : item.sourceType || "CONTENT"}</span><b>{item.type === "PRODUCTS" ? `Industrial product ${i + 1}` : `Project story ${i + 1}`}</b></article>)}</div></section>;
|
</div>
|
||||||
if (item.type === "INQUIRY") return <section className="pv-inquiry" style={style} onClick={onSelect}><div><h2>{item.title}</h2><p>{item.subtitle}</p></div><form><input placeholder="Your name"/><input placeholder="Business email"/><textarea placeholder="Project requirements"/><button type="button" style={{background:primary}}>Submit Inquiry</button></form></section>;
|
);
|
||||||
return <section className="pv-footer" style={style} onClick={onSelect}><b>SHOPLIX</b><div>Products<br/>Solutions<br/>Case Studies</div><div>About Us<br/>Contact Us<br/>Privacy Policy</div><small>{item.subtitle || "Copyright © 2026. All rights reserved."}</small></section>;
|
}
|
||||||
|
function PreviewSection({
|
||||||
|
item,
|
||||||
|
primary,
|
||||||
|
selected,
|
||||||
|
onSelect,
|
||||||
|
}: {
|
||||||
|
item: Section;
|
||||||
|
primary: string;
|
||||||
|
selected: boolean;
|
||||||
|
onSelect: () => void;
|
||||||
|
}) {
|
||||||
|
const style = {
|
||||||
|
background: item.background,
|
||||||
|
color: item.textColor,
|
||||||
|
outline: selected ? `2px solid ${primary}` : undefined,
|
||||||
|
};
|
||||||
|
if (item.type === "ANNOUNCEMENT")
|
||||||
|
return (
|
||||||
|
<section className="pv-announcement" style={style} onClick={onSelect}>
|
||||||
|
{item.title || "Free consultation for your next industrial project"}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
if (item.type === "HEADER")
|
||||||
|
return (
|
||||||
|
<section className="pv-header" style={style} onClick={onSelect}>
|
||||||
|
<b>SHOPLIX</b>
|
||||||
|
<nav>Products Solutions News About Us Contact</nav>
|
||||||
|
<button style={{ background: primary }}>Get a quote</button>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
if (item.type === "HERO")
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
className="pv-hero"
|
||||||
|
style={{
|
||||||
|
...style,
|
||||||
|
backgroundImage: item.imageUrl
|
||||||
|
? `linear-gradient(90deg,rgba(0,0,0,.65),rgba(0,0,0,.1)),url(${item.imageUrl})`
|
||||||
|
: undefined,
|
||||||
|
}}
|
||||||
|
onClick={onSelect}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<span>ENGINEERED FOR INDUSTRY</span>
|
||||||
|
<h1>{item.title}</h1>
|
||||||
|
<p>{item.subtitle}</p>
|
||||||
|
{item.buttonText && (
|
||||||
|
<button style={{ background: primary }}>{item.buttonText}</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
if (item.type === "RICH_TEXT")
|
||||||
|
return (
|
||||||
|
<section className="pv-rich" style={style} onClick={onSelect}>
|
||||||
|
<h2>{item.title}</h2>
|
||||||
|
<p>
|
||||||
|
{item.subtitle ||
|
||||||
|
"Add your English introduction, advantages or service description here."}
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
if (item.type === "PRODUCTS" || item.type === "CONTENT")
|
||||||
|
return (
|
||||||
|
<section className="pv-collection" style={style} onClick={onSelect}>
|
||||||
|
<p>FEATURED</p>
|
||||||
|
<h2>{item.title}</h2>
|
||||||
|
<div>
|
||||||
|
{Array.from({ length: Math.min(item.limit, 4) }, (_, i) => (
|
||||||
|
<article key={i}>
|
||||||
|
<span>
|
||||||
|
{item.type === "PRODUCTS"
|
||||||
|
? "PRODUCT"
|
||||||
|
: item.sourceType || "CONTENT"}
|
||||||
|
</span>
|
||||||
|
<b>
|
||||||
|
{item.type === "PRODUCTS"
|
||||||
|
? `Industrial product ${i + 1}`
|
||||||
|
: `Project story ${i + 1}`}
|
||||||
|
</b>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
if (item.type === "INQUIRY")
|
||||||
|
return (
|
||||||
|
<section className="pv-inquiry" style={style} onClick={onSelect}>
|
||||||
|
<div>
|
||||||
|
<h2>{item.title}</h2>
|
||||||
|
<p>{item.subtitle}</p>
|
||||||
|
</div>
|
||||||
|
<form>
|
||||||
|
<input placeholder="Your name" />
|
||||||
|
<input placeholder="Business email" />
|
||||||
|
<textarea placeholder="Project requirements" />
|
||||||
|
<button type="button" style={{ background: primary }}>
|
||||||
|
Submit Inquiry
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<section className="pv-footer" style={style} onClick={onSelect}>
|
||||||
|
<b>SHOPLIX</b>
|
||||||
|
<div>
|
||||||
|
Products
|
||||||
|
<br />
|
||||||
|
Solutions
|
||||||
|
<br />
|
||||||
|
Case Studies
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
About Us
|
||||||
|
<br />
|
||||||
|
Contact Us
|
||||||
|
<br />
|
||||||
|
Privacy Policy
|
||||||
|
</div>
|
||||||
|
<small>
|
||||||
|
{item.subtitle || "Copyright © 2026. All rights reserved."}
|
||||||
|
</small>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function Field({
|
||||||
|
label,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<label className="decor-field">
|
||||||
|
<span>{label}</span>
|
||||||
|
{children}
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function GlobalSettings({
|
||||||
|
schema,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
schema: Schema;
|
||||||
|
onChange: (global: Schema["global"]) => void;
|
||||||
|
}) {
|
||||||
|
const g = schema.global;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3>全局设置</h3>
|
||||||
|
<p>统一控制整站装修的基础视觉。</p>
|
||||||
|
<Field label="品牌主色">
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
value={g.primaryColor}
|
||||||
|
onChange={(e) => onChange({ ...g, primaryColor: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="页面背景">
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
value={g.backgroundColor}
|
||||||
|
onChange={(e) => onChange({ ...g, backgroundColor: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="正文颜色">
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
value={g.textColor}
|
||||||
|
onChange={(e) => onChange({ ...g, textColor: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="英文字体">
|
||||||
|
<select
|
||||||
|
value={g.fontFamily}
|
||||||
|
onChange={(e) => onChange({ ...g, fontFamily: e.target.value })}
|
||||||
|
>
|
||||||
|
<option>Inter</option>
|
||||||
|
<option>Arial</option>
|
||||||
|
<option>Georgia</option>
|
||||||
|
</select>
|
||||||
|
</Field>
|
||||||
|
<Field label="内容最大宽度">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="960"
|
||||||
|
max="1600"
|
||||||
|
value={g.contentWidth}
|
||||||
|
onChange={(e) =>
|
||||||
|
onChange({ ...g, contentWidth: Number(e.target.value) })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function SectionSettings({
|
||||||
|
item,
|
||||||
|
onChange,
|
||||||
|
onDuplicate,
|
||||||
|
onDelete,
|
||||||
|
}: {
|
||||||
|
item: Section;
|
||||||
|
onChange: (patch: Partial<Section>) => void;
|
||||||
|
onDuplicate: () => void;
|
||||||
|
onDelete: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3>{labels[item.type]}设置</h3>
|
||||||
|
<Field label="英文标题">
|
||||||
|
<input
|
||||||
|
value={item.title}
|
||||||
|
onChange={(e) => onChange({ title: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="英文副标题/内容">
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
value={item.subtitle}
|
||||||
|
onChange={(e) => onChange({ subtitle: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
{item.type === "HERO" && (
|
||||||
|
<>
|
||||||
|
<Field label="背景图片 URL">
|
||||||
|
<input
|
||||||
|
value={item.imageUrl}
|
||||||
|
onChange={(e) => onChange({ imageUrl: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="按钮文案">
|
||||||
|
<input
|
||||||
|
value={item.buttonText}
|
||||||
|
onChange={(e) => onChange({ buttonText: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="按钮链接">
|
||||||
|
<input
|
||||||
|
value={item.buttonUrl}
|
||||||
|
onChange={(e) => onChange({ buttonUrl: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{item.type === "CONTENT" && (
|
||||||
|
<Field label="内容来源">
|
||||||
|
<select
|
||||||
|
value={item.sourceType}
|
||||||
|
onChange={(e) => onChange({ sourceType: e.target.value })}
|
||||||
|
>
|
||||||
|
<option value="CASE">案例</option>
|
||||||
|
<option value="NEWS">新闻</option>
|
||||||
|
<option value="HELP">帮助</option>
|
||||||
|
</select>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
{["PRODUCTS", "CONTENT"].includes(item.type) && (
|
||||||
|
<Field label="展示数量">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="12"
|
||||||
|
value={item.limit}
|
||||||
|
onChange={(e) => onChange({ limit: Number(e.target.value) })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
<Field label="区块背景">
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
value={item.background}
|
||||||
|
onChange={(e) => onChange({ background: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="文字颜色">
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
value={item.textColor}
|
||||||
|
onChange={(e) => onChange({ textColor: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<div className="section-actions">
|
||||||
|
<button onClick={onDuplicate}>
|
||||||
|
<Copy size={15} />
|
||||||
|
复制组件
|
||||||
|
</button>
|
||||||
|
<button className="danger" onClick={onDelete}>
|
||||||
|
<Trash2 size={15} />
|
||||||
|
删除组件
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
function Field({ label, children }: { label: string; children: React.ReactNode }) { return <label className="decor-field"><span>{label}</span>{children}</label>; }
|
|
||||||
function GlobalSettings({ schema, onChange }: { schema: Schema; onChange: (global: Schema["global"]) => void }) { const g = schema.global; return <div><h3>全局设置</h3><p>统一控制整站装修的基础视觉。</p><Field label="品牌主色"><input type="color" value={g.primaryColor} onChange={e => onChange({...g, primaryColor:e.target.value})}/></Field><Field label="页面背景"><input type="color" value={g.backgroundColor} onChange={e => onChange({...g, backgroundColor:e.target.value})}/></Field><Field label="正文颜色"><input type="color" value={g.textColor} onChange={e => onChange({...g, textColor:e.target.value})}/></Field><Field label="英文字体"><select value={g.fontFamily} onChange={e => onChange({...g, fontFamily:e.target.value})}><option>Inter</option><option>Arial</option><option>Georgia</option></select></Field><Field label="内容最大宽度"><input type="number" min="960" max="1600" value={g.contentWidth} onChange={e => onChange({...g, contentWidth:Number(e.target.value)})}/></Field></div>; }
|
|
||||||
function SectionSettings({ item, onChange, onDuplicate, onDelete }: { item: Section; onChange: (patch: Partial<Section>) => void; onDuplicate: () => void; onDelete: () => void }) { return <div><h3>{labels[item.type]}设置</h3><Field label="英文标题"><input value={item.title} onChange={e => onChange({title:e.target.value})}/></Field><Field label="英文副标题/内容"><textarea rows={4} value={item.subtitle} onChange={e => onChange({subtitle:e.target.value})}/></Field>{item.type === "HERO" && <><Field label="背景图片 URL"><input value={item.imageUrl} onChange={e => onChange({imageUrl:e.target.value})}/></Field><Field label="按钮文案"><input value={item.buttonText} onChange={e => onChange({buttonText:e.target.value})}/></Field><Field label="按钮链接"><input value={item.buttonUrl} onChange={e => onChange({buttonUrl:e.target.value})}/></Field></>}{item.type === "CONTENT" && <Field label="内容来源"><select value={item.sourceType} onChange={e => onChange({sourceType:e.target.value})}><option value="CASE">案例</option><option value="NEWS">新闻</option><option value="HELP">帮助</option></select></Field>}{["PRODUCTS","CONTENT"].includes(item.type) && <Field label="展示数量"><input type="number" min="1" max="12" value={item.limit} onChange={e => onChange({limit:Number(e.target.value)})}/></Field>}<Field label="区块背景"><input type="color" value={item.background} onChange={e => onChange({background:e.target.value})}/></Field><Field label="文字颜色"><input type="color" value={item.textColor} onChange={e => onChange({textColor:e.target.value})}/></Field><div className="section-actions"><button onClick={onDuplicate}><Copy size={15}/>复制组件</button><button className="danger" onClick={onDelete}><Trash2 size={15}/>删除组件</button></div></div>; }
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { ArrowLeft, Edit3, Plus, Save, Trash2, X } from "lucide-react";
|
import { ArrowLeft, Edit3, Plus, Save, Trash2, X } from "lucide-react";
|
||||||
import { API } from "./api";
|
import { API } from "./api";
|
||||||
|
import { statusLabel } from "./statusLabels";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = "SIT0000000000001";
|
||||||
type Field = {
|
type Field = {
|
||||||
@@ -76,7 +77,12 @@ const fieldTypeLabels: Record<string, string> = {
|
|||||||
IMAGE: "图片上传",
|
IMAGE: "图片上传",
|
||||||
COUNTRY: "国家",
|
COUNTRY: "国家",
|
||||||
};
|
};
|
||||||
const optionFieldTypes = new Set(["SINGLE_SELECT", "MULTI_SELECT", "RADIO", "CHECKBOX"]);
|
const optionFieldTypes = new Set([
|
||||||
|
"SINGLE_SELECT",
|
||||||
|
"MULTI_SELECT",
|
||||||
|
"RADIO",
|
||||||
|
"CHECKBOX",
|
||||||
|
]);
|
||||||
|
|
||||||
async function post(path: string, body: unknown) {
|
async function post(path: string, body: unknown) {
|
||||||
const response = await fetch(API + path, {
|
const response = await fetch(API + path, {
|
||||||
@@ -112,7 +118,10 @@ export default function InquirySettingsPanel() {
|
|||||||
const [editing, setEditing] = useState<Form | null>(null);
|
const [editing, setEditing] = useState<Form | null>(null);
|
||||||
const [notice, setNotice] = useState("");
|
const [notice, setNotice] = useState("");
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [fieldEditor, setFieldEditor] = useState<{ index: number | null; value: Field } | null>(null);
|
const [fieldEditor, setFieldEditor] = useState<{
|
||||||
|
index: number | null;
|
||||||
|
value: Field;
|
||||||
|
} | null>(null);
|
||||||
const loadForms = () =>
|
const loadForms = () =>
|
||||||
post("/inquiries/forms/list", { siteCode: SITE })
|
post("/inquiries/forms/list", { siteCode: SITE })
|
||||||
.then((data) => setForms(data.items || []))
|
.then((data) => setForms(data.items || []))
|
||||||
@@ -157,12 +166,18 @@ export default function InquirySettingsPanel() {
|
|||||||
};
|
};
|
||||||
const saveField = () => {
|
const saveField = () => {
|
||||||
if (!editing || !fieldEditor) return;
|
if (!editing || !fieldEditor) return;
|
||||||
const value = { ...fieldEditor.value, sortNo: fieldEditor.index ?? editing.fields.length };
|
const value = {
|
||||||
|
...fieldEditor.value,
|
||||||
|
sortNo: fieldEditor.index ?? editing.fields.length,
|
||||||
|
};
|
||||||
setEditing({
|
setEditing({
|
||||||
...editing,
|
...editing,
|
||||||
fields: fieldEditor.index === null
|
fields:
|
||||||
|
fieldEditor.index === null
|
||||||
? [...editing.fields, value]
|
? [...editing.fields, value]
|
||||||
: editing.fields.map((field, index) => index === fieldEditor.index ? value : field),
|
: editing.fields.map((field, index) =>
|
||||||
|
index === fieldEditor.index ? value : field,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
setFieldEditor(null);
|
setFieldEditor(null);
|
||||||
};
|
};
|
||||||
@@ -229,7 +244,10 @@ export default function InquirySettingsPanel() {
|
|||||||
maxLength={1000}
|
maxLength={1000}
|
||||||
value={editing.description || ""}
|
value={editing.description || ""}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setEditing({ ...editing, description: event.target.value })
|
setEditing({
|
||||||
|
...editing,
|
||||||
|
description: event.target.value,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
@@ -251,27 +269,72 @@ export default function InquirySettingsPanel() {
|
|||||||
<div className="section-head">
|
<div className="section-head">
|
||||||
<h2>表单字段</h2>
|
<h2>表单字段</h2>
|
||||||
<button
|
<button
|
||||||
onClick={() => setFieldEditor({ index: null, value: emptyField() })}
|
onClick={() =>
|
||||||
|
setFieldEditor({ index: null, value: emptyField() })
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Plus size={16} />
|
<Plus size={16} />
|
||||||
添加字段
|
添加字段
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-field-table">
|
<div className="form-field-table">
|
||||||
<div className="form-field-head"><span>标题</span><span>字段键</span><span>类型</span><span>必填</span><span>宽度</span><span>操作</span></div>
|
<div className="form-field-head">
|
||||||
{editing.fields.length === 0 ? <div className="field-empty">暂无字段,点击右上角添加字段</div> : editing.fields.map((field, index) => (
|
<span>标题</span>
|
||||||
<div className="form-field-item" key={field.fieldCode || index}>
|
<span>字段键</span>
|
||||||
|
<span>类型</span>
|
||||||
|
<span>必填</span>
|
||||||
|
<span>宽度</span>
|
||||||
|
<span>操作</span>
|
||||||
|
</div>
|
||||||
|
{editing.fields.length === 0 ? (
|
||||||
|
<div className="field-empty">
|
||||||
|
暂无字段,点击右上角添加字段
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
editing.fields.map((field, index) => (
|
||||||
|
<div
|
||||||
|
className="form-field-item"
|
||||||
|
key={field.fieldCode || index}
|
||||||
|
>
|
||||||
<strong>{field.label}</strong>
|
<strong>{field.label}</strong>
|
||||||
<code>{field.fieldKey}</code>
|
<code>{field.fieldKey}</code>
|
||||||
<span>{fieldTypeLabels[field.fieldType] || field.fieldType}</span>
|
<span>
|
||||||
|
{fieldTypeLabels[field.fieldType] || field.fieldType}
|
||||||
|
</span>
|
||||||
<span>{field.required ? "是" : "否"}</span>
|
<span>{field.required ? "是" : "否"}</span>
|
||||||
<span>{field.widthType === "HALF" ? "半行" : "整行"}</span>
|
<span>
|
||||||
|
{field.widthType === "HALF" ? "半行" : "整行"}
|
||||||
|
</span>
|
||||||
<div className="field-actions">
|
<div className="field-actions">
|
||||||
<button title="编辑字段" onClick={() => setFieldEditor({ index, value: { ...field } })}><Edit3 size={16}/></button>
|
<button
|
||||||
<button className="danger" title={field.systemField ? "系统字段不可删除" : "删除字段"} disabled={field.systemField} onClick={() => setEditing({ ...editing, fields: editing.fields.filter((_, position) => position !== index) })}><Trash2 size={16}/></button>
|
title="编辑字段"
|
||||||
|
onClick={() =>
|
||||||
|
setFieldEditor({ index, value: { ...field } })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Edit3 size={16} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="danger"
|
||||||
|
title={
|
||||||
|
field.systemField ? "系统字段不可删除" : "删除字段"
|
||||||
|
}
|
||||||
|
disabled={field.systemField}
|
||||||
|
onClick={() =>
|
||||||
|
setEditing({
|
||||||
|
...editing,
|
||||||
|
fields: editing.fields.filter(
|
||||||
|
(_, position) => position !== index,
|
||||||
|
),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Trash2 size={16} />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section className="edit-section">
|
<section className="edit-section">
|
||||||
@@ -297,7 +360,10 @@ export default function InquirySettingsPanel() {
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={editing.defaultInquiry}
|
checked={editing.defaultInquiry}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setEditing({ ...editing, defaultInquiry: event.target.checked })
|
setEditing({
|
||||||
|
...editing,
|
||||||
|
defaultInquiry: event.target.checked,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<span>设为默认询盘表单</span>
|
<span>设为默认询盘表单</span>
|
||||||
@@ -329,23 +395,218 @@ export default function InquirySettingsPanel() {
|
|||||||
</section>
|
</section>
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
{fieldEditor && <div className="mask" onMouseDown={(event) => { if (event.target === event.currentTarget) setFieldEditor(null); }}>
|
{fieldEditor && (
|
||||||
<section className="field-dialog" role="dialog" aria-modal="true" aria-labelledby="field-dialog-title">
|
<div
|
||||||
<div className="dialog-head"><div><h2 id="field-dialog-title">{fieldEditor.index === null ? "添加字段" : "编辑字段"}</h2><p>配置询盘表单中的字段标题、类型和填写规则。</p></div><button className="icon" aria-label="关闭" onClick={() => setFieldEditor(null)}><X size={19}/></button></div>
|
className="mask"
|
||||||
|
onMouseDown={(event) => {
|
||||||
|
if (event.target === event.currentTarget) setFieldEditor(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<section
|
||||||
|
className="field-dialog"
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-labelledby="field-dialog-title"
|
||||||
|
>
|
||||||
|
<div className="dialog-head">
|
||||||
|
<div>
|
||||||
|
<h2 id="field-dialog-title">
|
||||||
|
{fieldEditor.index === null ? "添加字段" : "编辑字段"}
|
||||||
|
</h2>
|
||||||
|
<p>配置询盘表单中的字段标题、类型和填写规则。</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
className="icon"
|
||||||
|
aria-label="关闭"
|
||||||
|
onClick={() => setFieldEditor(null)}
|
||||||
|
>
|
||||||
|
<X size={19} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<div className="form-grid field-dialog-grid">
|
<div className="form-grid field-dialog-grid">
|
||||||
<Field label="标题 *"><input autoFocus maxLength={100} placeholder="例如 Name" value={fieldEditor.value.label} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, label: event.target.value } })}/></Field>
|
<Field label="标题 *">
|
||||||
<Field label="字段键 *"><input disabled={fieldEditor.value.systemField} maxLength={60} placeholder="例如 name" value={fieldEditor.value.fieldKey} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, fieldKey: event.target.value.toLowerCase().replace(/^[^a-z]+|[^a-z0-9_]/g, "_") } })}/></Field>
|
<input
|
||||||
<Field label="类型"><select value={fieldEditor.value.fieldType} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, fieldType: event.target.value } })}>{Object.entries(fieldTypeLabels).map(([value, label]) => <option value={value} key={value}>{label}</option>)}</select></Field>
|
autoFocus
|
||||||
<Field label="展示宽度"><select value={fieldEditor.value.widthType} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, widthType: event.target.value } })}><option value="FULL">整行</option><option value="HALF">半行</option></select></Field>
|
maxLength={100}
|
||||||
<Field label="框内提示语"><input maxLength={200} placeholder="用户输入前显示的内容" value={fieldEditor.value.placeholder || ""} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, placeholder: event.target.value } })}/></Field>
|
placeholder="例如 Name"
|
||||||
<Field label="限制字数"><input type="number" min={1} max={5000} placeholder="不限制" value={fieldEditor.value.maxLength || ""} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, maxLength: event.target.value ? Number(event.target.value) : null } })}/></Field>
|
value={fieldEditor.value.label}
|
||||||
<Field wide label="提示"><input maxLength={200} placeholder="显示在字段下方的帮助说明" value={fieldEditor.value.helpText || ""} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, helpText: event.target.value } })}/></Field>
|
onChange={(event) =>
|
||||||
{optionFieldTypes.has(fieldEditor.value.fieldType) && <Field wide label="选项配置(JSON)"><textarea rows={4} placeholder='例如 ["Option A","Option B"]' value={fieldEditor.value.optionsJson || ""} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, optionsJson: event.target.value } })}/></Field>}
|
setFieldEditor({
|
||||||
<label className="dialog-check wide"><input type="checkbox" checked={fieldEditor.value.required} onChange={(event) => setFieldEditor({ ...fieldEditor, value: { ...fieldEditor.value, required: event.target.checked } })}/><span>设为必填字段</span></label>
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
label: event.target.value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="字段键 *">
|
||||||
|
<input
|
||||||
|
disabled={fieldEditor.value.systemField}
|
||||||
|
maxLength={60}
|
||||||
|
placeholder="例如 name"
|
||||||
|
value={fieldEditor.value.fieldKey}
|
||||||
|
onChange={(event) =>
|
||||||
|
setFieldEditor({
|
||||||
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
fieldKey: event.target.value
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/^[^a-z]+|[^a-z0-9_]/g, "_"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="类型">
|
||||||
|
<select
|
||||||
|
value={fieldEditor.value.fieldType}
|
||||||
|
onChange={(event) =>
|
||||||
|
setFieldEditor({
|
||||||
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
fieldType: event.target.value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{Object.entries(fieldTypeLabels).map(([value, label]) => (
|
||||||
|
<option value={value} key={value}>
|
||||||
|
{label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</Field>
|
||||||
|
<Field label="展示宽度">
|
||||||
|
<select
|
||||||
|
value={fieldEditor.value.widthType}
|
||||||
|
onChange={(event) =>
|
||||||
|
setFieldEditor({
|
||||||
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
widthType: event.target.value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="FULL">整行</option>
|
||||||
|
<option value="HALF">半行</option>
|
||||||
|
</select>
|
||||||
|
</Field>
|
||||||
|
<Field label="框内提示语">
|
||||||
|
<input
|
||||||
|
maxLength={200}
|
||||||
|
placeholder="用户输入前显示的内容"
|
||||||
|
value={fieldEditor.value.placeholder || ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setFieldEditor({
|
||||||
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
placeholder: event.target.value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field label="限制字数">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
max={5000}
|
||||||
|
placeholder="不限制"
|
||||||
|
value={fieldEditor.value.maxLength || ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setFieldEditor({
|
||||||
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
maxLength: event.target.value
|
||||||
|
? Number(event.target.value)
|
||||||
|
: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
<Field wide label="提示">
|
||||||
|
<input
|
||||||
|
maxLength={200}
|
||||||
|
placeholder="显示在字段下方的帮助说明"
|
||||||
|
value={fieldEditor.value.helpText || ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setFieldEditor({
|
||||||
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
helpText: event.target.value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
{optionFieldTypes.has(fieldEditor.value.fieldType) && (
|
||||||
|
<Field wide label="选项配置(JSON)">
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
placeholder='例如 ["Option A","Option B"]'
|
||||||
|
value={fieldEditor.value.optionsJson || ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setFieldEditor({
|
||||||
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
optionsJson: event.target.value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
<label className="dialog-check wide">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={fieldEditor.value.required}
|
||||||
|
onChange={(event) =>
|
||||||
|
setFieldEditor({
|
||||||
|
...fieldEditor,
|
||||||
|
value: {
|
||||||
|
...fieldEditor.value,
|
||||||
|
required: event.target.checked,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span>设为必填字段</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="dialog-foot">
|
||||||
|
<button onClick={() => setFieldEditor(null)}>取消</button>
|
||||||
|
<button
|
||||||
|
className="primary"
|
||||||
|
disabled={
|
||||||
|
!fieldEditor.value.label.trim() ||
|
||||||
|
!/^[a-z][a-z0-9_]{1,59}$/.test(
|
||||||
|
fieldEditor.value.fieldKey,
|
||||||
|
) ||
|
||||||
|
editing.fields.some(
|
||||||
|
(field, index) =>
|
||||||
|
index !== fieldEditor.index &&
|
||||||
|
field.fieldKey === fieldEditor.value.fieldKey,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onClick={saveField}
|
||||||
|
>
|
||||||
|
保存字段
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="dialog-foot"><button onClick={() => setFieldEditor(null)}>取消</button><button className="primary" disabled={!fieldEditor.value.label.trim() || !/^[a-z][a-z0-9_]{1,59}$/.test(fieldEditor.value.fieldKey) || editing.fields.some((field, index) => index !== fieldEditor.index && field.fieldKey === fieldEditor.value.fieldKey)} onClick={saveField}>保存字段</button></div>
|
|
||||||
</section>
|
</section>
|
||||||
</div>}
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -514,11 +775,7 @@ export default function InquirySettingsPanel() {
|
|||||||
<small>{sceneLabels[form.scene] || form.scene}</small>
|
<small>{sceneLabels[form.scene] || form.scene}</small>
|
||||||
</div>
|
</div>
|
||||||
<span className={`status ${form.status.toLowerCase()}`}>
|
<span className={`status ${form.status.toLowerCase()}`}>
|
||||||
{form.status === "PUBLISHED"
|
{statusLabel(form.status)}
|
||||||
? "已发布"
|
|
||||||
: form.status === "OFFLINE"
|
|
||||||
? "已下线"
|
|
||||||
: "草稿"}
|
|
||||||
</span>
|
</span>
|
||||||
<span>{form.fields.length} 个字段</span>
|
<span>{form.fields.length} 个字段</span>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
import { ArrowLeft, ChevronRight, Menu, Pencil, Plus, Save, Trash2 } from "lucide-react";
|
import {
|
||||||
|
ArrowLeft,
|
||||||
|
ChevronRight,
|
||||||
|
Menu,
|
||||||
|
Pencil,
|
||||||
|
Plus,
|
||||||
|
Save,
|
||||||
|
Trash2,
|
||||||
|
} from "lucide-react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
|
import { statusLabel } from "./statusLabels";
|
||||||
|
|
||||||
const SITE_CODE = "SIT0000000000001";
|
const SITE_CODE = "SIT0000000000001";
|
||||||
|
|
||||||
@@ -51,7 +60,17 @@ function createClientKey(): string {
|
|||||||
|
|
||||||
/** 新建一个空白菜单项。 */
|
/** 新建一个空白菜单项。 */
|
||||||
function createItem(parentClientKey = "", sortNo = 0): NavigationItemForm {
|
function createItem(parentClientKey = "", sortNo = 0): NavigationItemForm {
|
||||||
return { clientKey: createClientKey(), parentClientKey, itemType: "HOME", title: "", targetCode: "", url: "/", openType: "CURRENT", visible: true, sortNo };
|
return {
|
||||||
|
clientKey: createClientKey(),
|
||||||
|
parentClientKey,
|
||||||
|
itemType: "HOME",
|
||||||
|
title: "",
|
||||||
|
targetCode: "",
|
||||||
|
url: "/",
|
||||||
|
openType: "CURRENT",
|
||||||
|
visible: true,
|
||||||
|
sortNo,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 菜单导航列表与独立编辑页。 */
|
/** 菜单导航列表与独立编辑页。 */
|
||||||
@@ -61,7 +80,9 @@ export default function NavigationManager() {
|
|||||||
const [navigationCode, setNavigationCode] = useState("");
|
const [navigationCode, setNavigationCode] = useState("");
|
||||||
const [navigationName, setNavigationName] = useState("");
|
const [navigationName, setNavigationName] = useState("");
|
||||||
const [position, setPosition] = useState<"HEADER" | "FOOTER">("HEADER");
|
const [position, setPosition] = useState<"HEADER" | "FOOTER">("HEADER");
|
||||||
const [status, setStatus] = useState<"DRAFT" | "PUBLISHED" | "OFFLINE">("DRAFT");
|
const [status, setStatus] = useState<"DRAFT" | "PUBLISHED" | "OFFLINE">(
|
||||||
|
"DRAFT",
|
||||||
|
);
|
||||||
const [items, setItems] = useState<NavigationItemForm[]>([]);
|
const [items, setItems] = useState<NavigationItemForm[]>([]);
|
||||||
const [targets, setTargets] = useState<TargetOption[]>([]);
|
const [targets, setTargets] = useState<TargetOption[]>([]);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
@@ -70,7 +91,10 @@ export default function NavigationManager() {
|
|||||||
/** 读取导航列表。 */
|
/** 读取导航列表。 */
|
||||||
const loadList = async () => {
|
const loadList = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await apiPost<{ items: NavigationSummary[] }>("/navigations/list", { siteCode: SITE_CODE });
|
const result = await apiPost<{ items: NavigationSummary[] }>(
|
||||||
|
"/navigations/list",
|
||||||
|
{ siteCode: SITE_CODE },
|
||||||
|
);
|
||||||
setList(result.items || []);
|
setList(result.items || []);
|
||||||
setMessage("");
|
setMessage("");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -78,82 +102,491 @@ export default function NavigationManager() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => { void loadList(); }, []);
|
useEffect(() => {
|
||||||
|
void loadList();
|
||||||
|
}, []);
|
||||||
|
|
||||||
/** 汇总导航可以跳转的固定页面和业务内容。 */
|
/** 汇总导航可以跳转的固定页面和业务内容。 */
|
||||||
const loadTargets = async () => {
|
const loadTargets = async () => {
|
||||||
const options: TargetOption[] = [
|
const options: TargetOption[] = [
|
||||||
{ group: "固定页面", type: "HOME", code: "", label: "首页", url: "/" },
|
{ group: "固定页面", type: "HOME", code: "", label: "首页", url: "/" },
|
||||||
{ group: "固定页面", type: "PRODUCT_LIST", code: "", label: "产品列表页", url: "/products" },
|
{
|
||||||
{ group: "固定页面", type: "NEWS_LIST", code: "", label: "新闻列表页", url: "/news" },
|
group: "固定页面",
|
||||||
{ group: "固定页面", type: "CASE_LIST", code: "", label: "案例列表页", url: "/cases" },
|
type: "PRODUCT_LIST",
|
||||||
{ group: "固定页面", type: "HELP_LIST", code: "", label: "帮助列表页", url: "/help" },
|
code: "",
|
||||||
|
label: "产品列表页",
|
||||||
|
url: "/products",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: "固定页面",
|
||||||
|
type: "NEWS_LIST",
|
||||||
|
code: "",
|
||||||
|
label: "新闻列表页",
|
||||||
|
url: "/news",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: "固定页面",
|
||||||
|
type: "CASE_LIST",
|
||||||
|
code: "",
|
||||||
|
label: "案例列表页",
|
||||||
|
url: "/cases",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: "固定页面",
|
||||||
|
type: "HELP_LIST",
|
||||||
|
code: "",
|
||||||
|
label: "帮助列表页",
|
||||||
|
url: "/help",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
const settled = await Promise.allSettled([
|
const settled = await Promise.allSettled([
|
||||||
apiPost<any>("/pages/list", { siteCode: SITE_CODE }),
|
apiPost<any>("/pages/list", { siteCode: SITE_CODE }),
|
||||||
apiPost<any>("/products/categories/list", { siteCode: SITE_CODE }),
|
apiPost<any>("/products/categories/list", { siteCode: SITE_CODE }),
|
||||||
apiPost<any>("/products/list", { siteCode: SITE_CODE }),
|
apiPost<any>("/products/list", { siteCode: SITE_CODE }),
|
||||||
...(["NEWS", "CASE", "HELP"] as const).flatMap((contentType) => [
|
...(["NEWS", "CASE", "HELP"] as const).flatMap((contentType) => [
|
||||||
apiPost<any>("/contents/categories/list", { siteCode: SITE_CODE, contentType }),
|
apiPost<any>("/contents/categories/list", {
|
||||||
|
siteCode: SITE_CODE,
|
||||||
|
contentType,
|
||||||
|
}),
|
||||||
apiPost<any>("/contents/list", { siteCode: SITE_CODE, contentType }),
|
apiPost<any>("/contents/list", { siteCode: SITE_CODE, contentType }),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
const value = (index: number) => settled[index].status === "fulfilled" ? (settled[index] as PromiseFulfilledResult<any>).value.items || [] : [];
|
const value = (index: number) =>
|
||||||
value(0).forEach((page: any) => options.push({ group: page.pageType === "CUSTOM_PAGE" ? "自定义页面" : "系统页面", type: page.pageType === "CUSTOM_PAGE" ? "CUSTOM_PAGE" : "SYSTEM_PAGE", code: page.pageCode, label: page.pageName, url: `/${page.slug}` }));
|
settled[index].status === "fulfilled"
|
||||||
value(1).forEach((category: any) => options.push({ group: "产品分类", type: "PRODUCT_CATEGORY", code: category.categoryCode, label: category.categoryName, url: `/products/category/${category.slug}` }));
|
? (settled[index] as PromiseFulfilledResult<any>).value.items || []
|
||||||
value(2).forEach((product: any) => options.push({ group: "产品", type: "PRODUCT", code: product.productCode, label: product.productName, url: `/products/${product.slug}` }));
|
: [];
|
||||||
const contentMeta = [{ name: "新闻", prefix: "news", categoryType: "NEWS_CATEGORY", itemType: "NEWS" }, { name: "案例", prefix: "cases", categoryType: "CASE_CATEGORY", itemType: "CASE" }, { name: "帮助", prefix: "help", categoryType: "HELP_CATEGORY", itemType: "HELP" }];
|
value(0).forEach((page: any) =>
|
||||||
|
options.push({
|
||||||
|
group: page.pageType === "CUSTOM_PAGE" ? "自定义页面" : "系统页面",
|
||||||
|
type: page.pageType === "CUSTOM_PAGE" ? "CUSTOM_PAGE" : "SYSTEM_PAGE",
|
||||||
|
code: page.pageCode,
|
||||||
|
label: page.pageName,
|
||||||
|
url: `/${page.slug}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
value(1).forEach((category: any) =>
|
||||||
|
options.push({
|
||||||
|
group: "产品分类",
|
||||||
|
type: "PRODUCT_CATEGORY",
|
||||||
|
code: category.categoryCode,
|
||||||
|
label: category.categoryName,
|
||||||
|
url: `/products/category/${category.slug}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
value(2).forEach((product: any) =>
|
||||||
|
options.push({
|
||||||
|
group: "产品",
|
||||||
|
type: "PRODUCT",
|
||||||
|
code: product.productCode,
|
||||||
|
label: product.productName,
|
||||||
|
url: `/products/${product.slug}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const contentMeta = [
|
||||||
|
{
|
||||||
|
name: "新闻",
|
||||||
|
prefix: "news",
|
||||||
|
categoryType: "NEWS_CATEGORY",
|
||||||
|
itemType: "NEWS",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "案例",
|
||||||
|
prefix: "cases",
|
||||||
|
categoryType: "CASE_CATEGORY",
|
||||||
|
itemType: "CASE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "帮助",
|
||||||
|
prefix: "help",
|
||||||
|
categoryType: "HELP_CATEGORY",
|
||||||
|
itemType: "HELP",
|
||||||
|
},
|
||||||
|
];
|
||||||
contentMeta.forEach((meta, offset) => {
|
contentMeta.forEach((meta, offset) => {
|
||||||
value(3 + offset * 2).forEach((category: any) => options.push({ group: `${meta.name}分类`, type: meta.categoryType, code: category.categoryCode, label: category.categoryName, url: `/${meta.prefix}/category/${category.slug}` }));
|
value(3 + offset * 2).forEach((category: any) =>
|
||||||
value(4 + offset * 2).forEach((content: any) => options.push({ group: meta.name, type: meta.itemType, code: content.contentCode, label: content.title, url: `/${meta.prefix}/${content.slug}` }));
|
options.push({
|
||||||
|
group: `${meta.name}分类`,
|
||||||
|
type: meta.categoryType,
|
||||||
|
code: category.categoryCode,
|
||||||
|
label: category.categoryName,
|
||||||
|
url: `/${meta.prefix}/category/${category.slug}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
value(4 + offset * 2).forEach((content: any) =>
|
||||||
|
options.push({
|
||||||
|
group: meta.name,
|
||||||
|
type: meta.itemType,
|
||||||
|
code: content.contentCode,
|
||||||
|
label: content.title,
|
||||||
|
url: `/${meta.prefix}/${content.slug}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
setTargets(options);
|
setTargets(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 打开新增导航页面。 */
|
/** 打开新增导航页面。 */
|
||||||
const createNavigation = () => {
|
const createNavigation = () => {
|
||||||
setNavigationCode(""); setNavigationName(""); setPosition("HEADER"); setStatus("DRAFT"); setItems([createItem()]); setEditing(true); setMessage("");
|
setNavigationCode("");
|
||||||
|
setNavigationName("");
|
||||||
|
setPosition("HEADER");
|
||||||
|
setStatus("DRAFT");
|
||||||
|
setItems([createItem()]);
|
||||||
|
setEditing(true);
|
||||||
|
setMessage("");
|
||||||
void loadTargets();
|
void loadTargets();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 打开既有导航编辑页面。 */
|
/** 打开既有导航编辑页面。 */
|
||||||
const editNavigation = (navigation: NavigationSummary) => {
|
const editNavigation = (navigation: NavigationSummary) => {
|
||||||
setNavigationCode(navigation.navigationCode); setNavigationName(navigation.navigationName); setPosition(navigation.position); setStatus(navigation.status);
|
setNavigationCode(navigation.navigationCode);
|
||||||
setItems(navigation.items.map((item) => ({ clientKey: item.itemCode, parentClientKey: item.parentItemCode || "", itemType: item.itemType, title: item.title, targetCode: item.targetCode || "", url: item.url, openType: item.openType, visible: item.visible, sortNo: item.sortNo })));
|
setNavigationName(navigation.navigationName);
|
||||||
setEditing(true); setMessage(""); void loadTargets();
|
setPosition(navigation.position);
|
||||||
|
setStatus(navigation.status);
|
||||||
|
setItems(
|
||||||
|
navigation.items.map((item) => ({
|
||||||
|
clientKey: item.itemCode,
|
||||||
|
parentClientKey: item.parentItemCode || "",
|
||||||
|
itemType: item.itemType,
|
||||||
|
title: item.title,
|
||||||
|
targetCode: item.targetCode || "",
|
||||||
|
url: item.url,
|
||||||
|
openType: item.openType,
|
||||||
|
visible: item.visible,
|
||||||
|
sortNo: item.sortNo,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
setEditing(true);
|
||||||
|
setMessage("");
|
||||||
|
void loadTargets();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 更新指定菜单项。 */
|
/** 更新指定菜单项。 */
|
||||||
const updateItem = (key: string, patch: Partial<NavigationItemForm>) => setItems((current) => current.map((item) => item.clientKey === key ? { ...item, ...patch } : item));
|
const updateItem = (key: string, patch: Partial<NavigationItemForm>) =>
|
||||||
|
setItems((current) =>
|
||||||
|
current.map((item) =>
|
||||||
|
item.clientKey === key ? { ...item, ...patch } : item,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/** 选择内部页面或内容作为菜单目标。 */
|
/** 选择内部页面或内容作为菜单目标。 */
|
||||||
const selectTarget = (key: string, encoded: string) => {
|
const selectTarget = (key: string, encoded: string) => {
|
||||||
const option = targets.find((item) => `${item.type}|${item.code}|${item.url}` === encoded);
|
const option = targets.find(
|
||||||
if (option) updateItem(key, { itemType: option.type, targetCode: option.code, url: option.url, title: items.find((item) => item.clientKey === key)?.title || option.label });
|
(item) => `${item.type}|${item.code}|${item.url}` === encoded,
|
||||||
|
);
|
||||||
|
if (option)
|
||||||
|
updateItem(key, {
|
||||||
|
itemType: option.type,
|
||||||
|
targetCode: option.code,
|
||||||
|
url: option.url,
|
||||||
|
title:
|
||||||
|
items.find((item) => item.clientKey === key)?.title || option.label,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 删除菜单项及其直接子项。 */
|
/** 删除菜单项及其直接子项。 */
|
||||||
const deleteItem = (key: string) => setItems((current) => current.filter((item) => item.clientKey !== key && item.parentClientKey !== key));
|
const deleteItem = (key: string) =>
|
||||||
|
setItems((current) =>
|
||||||
|
current.filter(
|
||||||
|
(item) => item.clientKey !== key && item.parentClientKey !== key,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/** 保存完整导航菜单树。 */
|
/** 保存完整导航菜单树。 */
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
if (!navigationName.trim() || items.length === 0 || items.some((item) => !item.title.trim() || !item.url.trim())) { setMessage("请填写导航名称及全部菜单项的标题和目标"); return; }
|
if (
|
||||||
|
!navigationName.trim() ||
|
||||||
|
items.length === 0 ||
|
||||||
|
items.some((item) => !item.title.trim() || !item.url.trim())
|
||||||
|
) {
|
||||||
|
setMessage("请填写导航名称及全部菜单项的标题和目标");
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
setSaving(true); setMessage("");
|
setSaving(true);
|
||||||
await apiPost("/navigations/save", { navigationCode: navigationCode || null, siteCode: SITE_CODE, navigationName, position, status, items: items.map((item, index) => ({ ...item, sortNo: index })) });
|
setMessage("");
|
||||||
setEditing(false); await loadList();
|
await apiPost("/navigations/save", {
|
||||||
} catch (error) { setMessage(error instanceof Error ? error.message : "导航保存失败"); } finally { setSaving(false); }
|
navigationCode: navigationCode || null,
|
||||||
|
siteCode: SITE_CODE,
|
||||||
|
navigationName,
|
||||||
|
position,
|
||||||
|
status,
|
||||||
|
items: items.map((item, index) => ({ ...item, sortNo: index })),
|
||||||
|
});
|
||||||
|
setEditing(false);
|
||||||
|
await loadList();
|
||||||
|
} catch (error) {
|
||||||
|
setMessage(error instanceof Error ? error.message : "导航保存失败");
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 删除导航。 */
|
/** 删除导航。 */
|
||||||
const remove = async (navigation: NavigationSummary) => {
|
const remove = async (navigation: NavigationSummary) => {
|
||||||
if (!window.confirm(`确认删除导航“${navigation.navigationName}”吗?`)) return;
|
if (!window.confirm(`确认删除导航“${navigation.navigationName}”吗?`))
|
||||||
try { await apiPost("/navigations/delete", { siteCode: SITE_CODE, navigationCode: navigation.navigationCode }); await loadList(); } catch (error) { setMessage(error instanceof Error ? error.message : "导航删除失败"); }
|
return;
|
||||||
|
try {
|
||||||
|
await apiPost("/navigations/delete", {
|
||||||
|
siteCode: SITE_CODE,
|
||||||
|
navigationCode: navigation.navigationCode,
|
||||||
|
});
|
||||||
|
await loadList();
|
||||||
|
} catch (error) {
|
||||||
|
setMessage(error instanceof Error ? error.message : "导航删除失败");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const groupedTargets = useMemo(() => Array.from(new Set(targets.map((item) => item.group))), [targets]);
|
const groupedTargets = useMemo(
|
||||||
|
() => Array.from(new Set(targets.map((item) => item.group))),
|
||||||
|
[targets],
|
||||||
|
);
|
||||||
|
|
||||||
if (!editing) return <div className="navigation-manager"><header><div><h1>菜单导航</h1><p>配置前台站页头与页脚显示的菜单结构。</p></div><button className="primary" onClick={createNavigation}><Plus size={17}/>添加导航</button></header>{message && <div className="notice">{message}</div>}<section className="navigation-list"><div className="navigation-list-head"><span>导航</span><span>菜单项</span><span>位置 / 状态</span><span>操作</span></div>{list.length === 0 ? <div className="empty"><Menu size={34}/><strong>暂无导航配置</strong><p>点击“添加导航”创建前台菜单。</p></div> : list.map((navigation) => <div className="navigation-list-row" key={navigation.navigationCode}><strong>{navigation.navigationName}</strong><span>{navigation.items.filter((item) => !item.parentItemCode).map((item) => item.title).join("、") || "--"}</span><span>{navigation.position === "HEADER" ? "页头" : "页脚"} · {navigation.status === "PUBLISHED" ? "已发布" : navigation.status === "OFFLINE" ? "已下线" : "草稿"}</span><div><button title="编辑导航" onClick={() => editNavigation(navigation)}><Pencil size={17}/></button><button className="danger" title="删除导航" onClick={() => void remove(navigation)}><Trash2 size={17}/></button></div></div>)}</section></div>;
|
if (!editing)
|
||||||
|
return (
|
||||||
|
<div className="navigation-manager">
|
||||||
|
<header>
|
||||||
|
<div>
|
||||||
|
<h1>菜单导航</h1>
|
||||||
|
<p>配置前台站页头与页脚显示的菜单结构。</p>
|
||||||
|
</div>
|
||||||
|
<button className="primary" onClick={createNavigation}>
|
||||||
|
<Plus size={17} />
|
||||||
|
添加导航
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
{message && <div className="notice">{message}</div>}
|
||||||
|
<section className="navigation-list">
|
||||||
|
<div className="navigation-list-head">
|
||||||
|
<span>导航</span>
|
||||||
|
<span>菜单项</span>
|
||||||
|
<span>位置 / 状态</span>
|
||||||
|
<span>操作</span>
|
||||||
|
</div>
|
||||||
|
{list.length === 0 ? (
|
||||||
|
<div className="empty">
|
||||||
|
<Menu size={34} />
|
||||||
|
<strong>暂无导航配置</strong>
|
||||||
|
<p>点击“添加导航”创建前台菜单。</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
list.map((navigation) => (
|
||||||
|
<div
|
||||||
|
className="navigation-list-row"
|
||||||
|
key={navigation.navigationCode}
|
||||||
|
>
|
||||||
|
<strong>{navigation.navigationName}</strong>
|
||||||
|
<span>
|
||||||
|
{navigation.items
|
||||||
|
.filter((item) => !item.parentItemCode)
|
||||||
|
.map((item) => item.title)
|
||||||
|
.join("、") || "--"}
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
{navigation.position === "HEADER" ? "页头" : "页脚"} ·{" "}
|
||||||
|
{statusLabel(navigation.status)}
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
title="编辑导航"
|
||||||
|
onClick={() => editNavigation(navigation)}
|
||||||
|
>
|
||||||
|
<Pencil size={17} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="danger"
|
||||||
|
title="删除导航"
|
||||||
|
onClick={() => void remove(navigation)}
|
||||||
|
>
|
||||||
|
<Trash2 size={17} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return <div className="navigation-editor"><header><div className="navigation-editor-title"><button className="icon-button" onClick={() => setEditing(false)}><ArrowLeft size={18}/></button><div><h1>{navigationCode ? "编辑导航" : "新增导航"}</h1><p>设置菜单层级、跳转目标和打开方式。</p></div></div><div className="header-actions"><button className="secondary" onClick={() => setEditing(false)}>取消</button><button className="primary" disabled={saving} onClick={() => void save()}><Save size={17}/>{saving ? "保存中" : "保存"}</button></div></header>{message && <div className="notice">{message}</div>}<section className="navigation-base"><label><span>导航标题 *</span><input maxLength={100} value={navigationName} onChange={(event) => setNavigationName(event.target.value)} placeholder="例如:主导航"/></label><label><span>展示位置</span><select value={position} onChange={(event) => setPosition(event.target.value as "HEADER" | "FOOTER")}><option value="HEADER">页头导航</option><option value="FOOTER">页脚导航</option></select></label><label><span>发布状态</span><select value={status} onChange={(event) => setStatus(event.target.value as typeof status)}><option value="DRAFT">草稿</option><option value="PUBLISHED">发布</option><option value="OFFLINE">下线</option></select></label></section><section className="navigation-items"><div className="navigation-items-heading"><div><h2>菜单项</h2><p>菜单项可以指向固定页面、分类、具体内容或自定义地址。</p></div><button className="secondary" onClick={() => setItems((current) => [...current, createItem("", current.length)])}><Plus size={16}/>添加菜单项</button></div><div className="navigation-item-head"><span>菜单标题</span><span>页面打开方式</span><span>跳转目标</span><span>显示</span><span>操作</span></div>{items.map((item) => <div className={`navigation-item-row ${item.parentClientKey ? "child" : ""}`} key={item.clientKey}>{item.parentClientKey && <ChevronRight className="child-marker" size={16}/>}<input value={item.title} onChange={(event) => updateItem(item.clientKey, { title: event.target.value })} placeholder="菜单标题"/><select value={item.openType} onChange={(event) => updateItem(item.clientKey, { openType: event.target.value as NavigationItemForm["openType"] })}><option value="CURRENT">当前页面打开</option><option value="NEW">新窗口打开</option></select><select value={`${item.itemType}|${item.targetCode}|${item.url}`} onChange={(event) => selectTarget(item.clientKey, event.target.value)}><option value={`${item.itemType}|${item.targetCode}|${item.url}`}>{targets.length ? "请选择页面或内容" : "正在加载目标..."}</option>{groupedTargets.map((group) => <optgroup label={group} key={group}>{targets.filter((target) => target.group === group).map((target) => <option key={`${target.type}-${target.code}-${target.url}`} value={`${target.type}|${target.code}|${target.url}`}>{target.label}</option>)}</optgroup>)}</select><label className="switch"><input type="checkbox" checked={item.visible} onChange={(event) => updateItem(item.clientKey, { visible: event.target.checked })}/><span/></label><div className="navigation-row-actions">{!item.parentClientKey && <button title="添加子菜单" onClick={() => setItems((current) => [...current, createItem(item.clientKey, current.length)])}><Plus size={17}/></button>}<button className="danger" title="删除菜单项" onClick={() => deleteItem(item.clientKey)}><Trash2 size={17}/></button></div></div>)}{items.length === 0 && <div className="empty"><strong>暂无菜单项</strong><p>添加至少一个菜单项后才能保存。</p></div>}</section></div>;
|
return (
|
||||||
|
<div className="navigation-editor">
|
||||||
|
<header>
|
||||||
|
<div className="navigation-editor-title">
|
||||||
|
<button className="icon-button" onClick={() => setEditing(false)}>
|
||||||
|
<ArrowLeft size={18} />
|
||||||
|
</button>
|
||||||
|
<div>
|
||||||
|
<h1>{navigationCode ? "编辑导航" : "新增导航"}</h1>
|
||||||
|
<p>设置菜单层级、跳转目标和打开方式。</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="header-actions">
|
||||||
|
<button className="secondary" onClick={() => setEditing(false)}>
|
||||||
|
取消
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="primary"
|
||||||
|
disabled={saving}
|
||||||
|
onClick={() => void save()}
|
||||||
|
>
|
||||||
|
<Save size={17} />
|
||||||
|
{saving ? "保存中" : "保存"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
{message && <div className="notice">{message}</div>}
|
||||||
|
<section className="navigation-base">
|
||||||
|
<label>
|
||||||
|
<span>导航标题 *</span>
|
||||||
|
<input
|
||||||
|
maxLength={100}
|
||||||
|
value={navigationName}
|
||||||
|
onChange={(event) => setNavigationName(event.target.value)}
|
||||||
|
placeholder="例如:主导航"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>展示位置</span>
|
||||||
|
<select
|
||||||
|
value={position}
|
||||||
|
onChange={(event) =>
|
||||||
|
setPosition(event.target.value as "HEADER" | "FOOTER")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="HEADER">页头导航</option>
|
||||||
|
<option value="FOOTER">页脚导航</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>发布状态</span>
|
||||||
|
<select
|
||||||
|
value={status}
|
||||||
|
onChange={(event) => setStatus(event.target.value as typeof status)}
|
||||||
|
>
|
||||||
|
<option value="DRAFT">草稿</option>
|
||||||
|
<option value="PUBLISHED">发布</option>
|
||||||
|
<option value="OFFLINE">下线</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</section>
|
||||||
|
<section className="navigation-items">
|
||||||
|
<div className="navigation-items-heading">
|
||||||
|
<div>
|
||||||
|
<h2>菜单项</h2>
|
||||||
|
<p>菜单项可以指向固定页面、分类、具体内容或自定义地址。</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
className="secondary"
|
||||||
|
onClick={() =>
|
||||||
|
setItems((current) => [
|
||||||
|
...current,
|
||||||
|
createItem("", current.length),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Plus size={16} />
|
||||||
|
添加菜单项
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="navigation-item-head">
|
||||||
|
<span>菜单标题</span>
|
||||||
|
<span>页面打开方式</span>
|
||||||
|
<span>跳转目标</span>
|
||||||
|
<span>显示</span>
|
||||||
|
<span>操作</span>
|
||||||
|
</div>
|
||||||
|
{items.map((item) => (
|
||||||
|
<div
|
||||||
|
className={`navigation-item-row ${item.parentClientKey ? "child" : ""}`}
|
||||||
|
key={item.clientKey}
|
||||||
|
>
|
||||||
|
{item.parentClientKey && (
|
||||||
|
<ChevronRight className="child-marker" size={16} />
|
||||||
|
)}
|
||||||
|
<input
|
||||||
|
value={item.title}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateItem(item.clientKey, { title: event.target.value })
|
||||||
|
}
|
||||||
|
placeholder="菜单标题"
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
value={item.openType}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateItem(item.clientKey, {
|
||||||
|
openType: event.target
|
||||||
|
.value as NavigationItemForm["openType"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="CURRENT">当前页面打开</option>
|
||||||
|
<option value="NEW">新窗口打开</option>
|
||||||
|
</select>
|
||||||
|
<select
|
||||||
|
value={`${item.itemType}|${item.targetCode}|${item.url}`}
|
||||||
|
onChange={(event) =>
|
||||||
|
selectTarget(item.clientKey, event.target.value)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value={`${item.itemType}|${item.targetCode}|${item.url}`}>
|
||||||
|
{targets.length ? "请选择页面或内容" : "正在加载目标..."}
|
||||||
|
</option>
|
||||||
|
{groupedTargets.map((group) => (
|
||||||
|
<optgroup label={group} key={group}>
|
||||||
|
{targets
|
||||||
|
.filter((target) => target.group === group)
|
||||||
|
.map((target) => (
|
||||||
|
<option
|
||||||
|
key={`${target.type}-${target.code}-${target.url}`}
|
||||||
|
value={`${target.type}|${target.code}|${target.url}`}
|
||||||
|
>
|
||||||
|
{target.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</optgroup>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<label className="switch">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={item.visible}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateItem(item.clientKey, { visible: event.target.checked })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span />
|
||||||
|
</label>
|
||||||
|
<div className="navigation-row-actions">
|
||||||
|
{!item.parentClientKey && (
|
||||||
|
<button
|
||||||
|
title="添加子菜单"
|
||||||
|
onClick={() =>
|
||||||
|
setItems((current) => [
|
||||||
|
...current,
|
||||||
|
createItem(item.clientKey, current.length),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Plus size={17} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
className="danger"
|
||||||
|
title="删除菜单项"
|
||||||
|
onClick={() => deleteItem(item.clientKey)}
|
||||||
|
>
|
||||||
|
<Trash2 size={17} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{items.length === 0 && (
|
||||||
|
<div className="empty">
|
||||||
|
<strong>暂无菜单项</strong>
|
||||||
|
<p>添加至少一个菜单项后才能保存。</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
+514
-55
@@ -36,12 +36,37 @@ import SeoSettingsPage from "./SeoSettingsPage";
|
|||||||
import NavigationManager from "./NavigationManager";
|
import NavigationManager from "./NavigationManager";
|
||||||
import AgreementSettingsPage from "./AgreementSettingsPage";
|
import AgreementSettingsPage from "./AgreementSettingsPage";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
|
import { statusLabel } from "./statusLabels";
|
||||||
|
|
||||||
const SITE_WEB = window.location.hostname === "admin.steliro.com" ? "https://site.steliro.com" : "http://localhost:5174";
|
const SITE_WEB =
|
||||||
|
window.location.hostname === "admin.steliro.com"
|
||||||
|
? "https://site.steliro.com"
|
||||||
|
: "http://localhost:5174";
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = "SIT0000000000001";
|
||||||
type Section = "products" | "product-categories" | "NEWS" | "NEWS-categories" | "CASE" | "CASE-categories" | "HELP" | "HELP-categories" | "pages" | "navigation" | "seo-settings" | "decoration" | "custom-code" | "agreements" | "media" | "inquiries" | "inquiry-settings" | "settings";
|
type Section =
|
||||||
|
| "products"
|
||||||
|
| "product-categories"
|
||||||
|
| "NEWS"
|
||||||
|
| "NEWS-categories"
|
||||||
|
| "CASE"
|
||||||
|
| "CASE-categories"
|
||||||
|
| "HELP"
|
||||||
|
| "HELP-categories"
|
||||||
|
| "pages"
|
||||||
|
| "navigation"
|
||||||
|
| "seo-settings"
|
||||||
|
| "decoration"
|
||||||
|
| "custom-code"
|
||||||
|
| "agreements"
|
||||||
|
| "media"
|
||||||
|
| "inquiries"
|
||||||
|
| "inquiry-settings"
|
||||||
|
| "settings";
|
||||||
type EditorialSection = "NEWS" | "CASE" | "HELP";
|
type EditorialSection = "NEWS" | "CASE" | "HELP";
|
||||||
type ContentEditorState = { contentType: EditorialSection; contentCode: string };
|
type ContentEditorState = {
|
||||||
|
contentType: EditorialSection;
|
||||||
|
contentCode: string;
|
||||||
|
};
|
||||||
type Item = {
|
type Item = {
|
||||||
productCode?: string;
|
productCode?: string;
|
||||||
contentCode?: string;
|
contentCode?: string;
|
||||||
@@ -73,7 +98,12 @@ type Item = {
|
|||||||
function formatTime(value?: number): string {
|
function formatTime(value?: number): string {
|
||||||
if (!value) return "--";
|
if (!value) return "--";
|
||||||
return new Intl.DateTimeFormat("zh-CN", {
|
return new Intl.DateTimeFormat("zh-CN", {
|
||||||
year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: false,
|
year: "numeric",
|
||||||
|
month: "2-digit",
|
||||||
|
day: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: false,
|
||||||
}).format(new Date(value));
|
}).format(new Date(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,25 +124,57 @@ const menus = [
|
|||||||
{ key: "inquiries" as Section, label: "询盘", icon: Mail },
|
{ key: "inquiries" as Section, label: "询盘", icon: Mail },
|
||||||
];
|
];
|
||||||
const sectionLabels: Record<Section, string> = {
|
const sectionLabels: Record<Section, string> = {
|
||||||
products: "产品", "product-categories": "产品分类", NEWS: "新闻", "NEWS-categories": "新闻分类",
|
products: "产品",
|
||||||
CASE: "案例", "CASE-categories": "案例分类", HELP: "帮助", "HELP-categories": "帮助分类",
|
"product-categories": "产品分类",
|
||||||
pages: "页面", navigation: "菜单导航", decoration: "店铺装修", "custom-code": "自定义代码", media: "素材中心", inquiries: "询盘", "inquiry-settings": "询盘设置",
|
NEWS: "新闻",
|
||||||
|
"NEWS-categories": "新闻分类",
|
||||||
|
CASE: "案例",
|
||||||
|
"CASE-categories": "案例分类",
|
||||||
|
HELP: "帮助",
|
||||||
|
"HELP-categories": "帮助分类",
|
||||||
|
pages: "页面",
|
||||||
|
navigation: "菜单导航",
|
||||||
|
decoration: "店铺装修",
|
||||||
|
"custom-code": "自定义代码",
|
||||||
|
media: "素材中心",
|
||||||
|
inquiries: "询盘",
|
||||||
|
"inquiry-settings": "询盘设置",
|
||||||
"seo-settings": "页面 SEO",
|
"seo-settings": "页面 SEO",
|
||||||
agreements: "协议设置",
|
agreements: "协议设置",
|
||||||
settings: "系统设置",
|
settings: "系统设置",
|
||||||
};
|
};
|
||||||
const statusLabels: Record<string, string> = { DRAFT: "草稿", PUBLISHED: "已上架", OFFLINE: "已下架" };
|
function App({
|
||||||
|
account,
|
||||||
function App({ account, onAccount, onLogout }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void }) {
|
onAccount,
|
||||||
const contentRoutes: Record<EditorialSection, string> = { NEWS: "news", CASE: "cases", HELP: "help" };
|
onLogout,
|
||||||
|
}: {
|
||||||
|
account: Account;
|
||||||
|
onAccount: (value: Account) => void;
|
||||||
|
onLogout: () => void;
|
||||||
|
}) {
|
||||||
|
const contentRoutes: Record<EditorialSection, string> = {
|
||||||
|
NEWS: "news",
|
||||||
|
CASE: "cases",
|
||||||
|
HELP: "help",
|
||||||
|
};
|
||||||
const resolveContentRoute = (): ContentEditorState | null => {
|
const resolveContentRoute = (): ContentEditorState | null => {
|
||||||
const match = window.location.pathname.match(/^\/(news|cases|help)\/(new|([^/]+)\/edit)$/);
|
const match = window.location.pathname.match(
|
||||||
|
/^\/(news|cases|help)\/(new|([^/]+)\/edit)$/,
|
||||||
|
);
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
const contentType = ({ news: "NEWS", cases: "CASE", help: "HELP" } as const)[match[1] as "news" | "cases" | "help"];
|
const contentType = (
|
||||||
return { contentType, contentCode: match[2] === "new" ? "" : decodeURIComponent(match[3]) };
|
{ news: "NEWS", cases: "CASE", help: "HELP" } as const
|
||||||
|
)[match[1] as "news" | "cases" | "help"];
|
||||||
|
return {
|
||||||
|
contentType,
|
||||||
|
contentCode: match[2] === "new" ? "" : decodeURIComponent(match[3]),
|
||||||
|
};
|
||||||
};
|
};
|
||||||
const initialContentEditor = resolveContentRoute();
|
const initialContentEditor = resolveContentRoute();
|
||||||
const [section, setSection] = useState<Section>(initialContentEditor?.contentType || (window.location.pathname.startsWith("/pages/") ? "pages" : "products"));
|
const [section, setSection] = useState<Section>(
|
||||||
|
initialContentEditor?.contentType ||
|
||||||
|
(window.location.pathname.startsWith("/pages/") ? "pages" : "products"),
|
||||||
|
);
|
||||||
const [items, setItems] = useState<Item[]>([]);
|
const [items, setItems] = useState<Item[]>([]);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
@@ -128,9 +190,14 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
const match = window.location.pathname.match(/^\/pages\/([^/]+)\/edit$/);
|
const match = window.location.pathname.match(/^\/pages\/([^/]+)\/edit$/);
|
||||||
return match ? decodeURIComponent(match[1]) : null;
|
return match ? decodeURIComponent(match[1]) : null;
|
||||||
};
|
};
|
||||||
const [editingProduct, setEditingProduct] = useState<string | null>(resolveProductRoute);
|
const [editingProduct, setEditingProduct] = useState<string | null>(
|
||||||
const [editingContent, setEditingContent] = useState<ContentEditorState | null>(initialContentEditor);
|
resolveProductRoute,
|
||||||
const [editingPage, setEditingPage] = useState<string | null>(resolvePageRoute);
|
);
|
||||||
|
const [editingContent, setEditingContent] =
|
||||||
|
useState<ContentEditorState | null>(initialContentEditor);
|
||||||
|
const [editingPage, setEditingPage] = useState<string | null>(
|
||||||
|
resolvePageRoute,
|
||||||
|
);
|
||||||
const [productMenuOpen, setProductMenuOpen] = useState(true);
|
const [productMenuOpen, setProductMenuOpen] = useState(true);
|
||||||
const [contentMenuOpen, setContentMenuOpen] = useState(true);
|
const [contentMenuOpen, setContentMenuOpen] = useState(true);
|
||||||
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(true);
|
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(true);
|
||||||
@@ -152,8 +219,7 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
const load = async () => {
|
const load = async () => {
|
||||||
try {
|
try {
|
||||||
setError("");
|
setError("");
|
||||||
const data =
|
const data = section.endsWith("-categories")
|
||||||
section.endsWith("-categories")
|
|
||||||
? { items: [] }
|
? { items: [] }
|
||||||
: section === "settings"
|
: section === "settings"
|
||||||
? { items: [] }
|
? { items: [] }
|
||||||
@@ -207,9 +273,14 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
setEditingProduct(null);
|
setEditingProduct(null);
|
||||||
void load();
|
void load();
|
||||||
};
|
};
|
||||||
const openContentEditor = (contentType: EditorialSection, contentCode?: string) => {
|
const openContentEditor = (
|
||||||
|
contentType: EditorialSection,
|
||||||
|
contentCode?: string,
|
||||||
|
) => {
|
||||||
const route = contentRoutes[contentType];
|
const route = contentRoutes[contentType];
|
||||||
const path = contentCode ? `/${route}/${encodeURIComponent(contentCode)}/edit` : `/${route}/new`;
|
const path = contentCode
|
||||||
|
? `/${route}/${encodeURIComponent(contentCode)}/edit`
|
||||||
|
: `/${route}/new`;
|
||||||
window.history.pushState({}, "", path);
|
window.history.pushState({}, "", path);
|
||||||
setEditingContent({ contentType, contentCode: contentCode || "" });
|
setEditingContent({ contentType, contentCode: contentCode || "" });
|
||||||
};
|
};
|
||||||
@@ -218,7 +289,11 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
setEditingContent(null);
|
setEditingContent(null);
|
||||||
};
|
};
|
||||||
const openPageEditor = (pageCode?: string) => {
|
const openPageEditor = (pageCode?: string) => {
|
||||||
window.history.pushState({}, "", pageCode ? `/pages/${encodeURIComponent(pageCode)}/edit` : "/pages/new");
|
window.history.pushState(
|
||||||
|
{},
|
||||||
|
"",
|
||||||
|
pageCode ? `/pages/${encodeURIComponent(pageCode)}/edit` : "/pages/new",
|
||||||
|
);
|
||||||
setEditingPage(pageCode || "");
|
setEditingPage(pageCode || "");
|
||||||
};
|
};
|
||||||
const closePageEditor = () => {
|
const closePageEditor = () => {
|
||||||
@@ -234,22 +309,48 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
try {
|
try {
|
||||||
setError("");
|
setError("");
|
||||||
if (section === "products" && item.productCode)
|
if (section === "products" && item.productCode)
|
||||||
await post("/products/status", { siteCode: SITE, productCode: item.productCode, status });
|
await post("/products/status", {
|
||||||
|
siteCode: SITE,
|
||||||
|
productCode: item.productCode,
|
||||||
|
status,
|
||||||
|
});
|
||||||
else if (["NEWS", "CASE", "HELP"].includes(section) && item.contentCode)
|
else if (["NEWS", "CASE", "HELP"].includes(section) && item.contentCode)
|
||||||
await post("/contents/status", { siteCode: SITE, contentCode: item.contentCode, contentType: section, status });
|
await post("/contents/status", {
|
||||||
|
siteCode: SITE,
|
||||||
|
contentCode: item.contentCode,
|
||||||
|
contentType: section,
|
||||||
|
status,
|
||||||
|
});
|
||||||
await load();
|
await load();
|
||||||
} catch (operationError) { setError(operationError instanceof Error ? operationError.message : "状态更新失败"); }
|
} catch (operationError) {
|
||||||
|
setError(
|
||||||
|
operationError instanceof Error
|
||||||
|
? operationError.message
|
||||||
|
: "状态更新失败",
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const deleteItem = async (item: Item) => {
|
const deleteItem = async (item: Item) => {
|
||||||
if (!window.confirm("删除后该内容将不再展示,确认删除吗?")) return;
|
if (!window.confirm("删除后该内容将不再展示,确认删除吗?")) return;
|
||||||
try {
|
try {
|
||||||
setError("");
|
setError("");
|
||||||
if (section === "products" && item.productCode)
|
if (section === "products" && item.productCode)
|
||||||
await post("/products/delete", { siteCode: SITE, productCode: item.productCode });
|
await post("/products/delete", {
|
||||||
|
siteCode: SITE,
|
||||||
|
productCode: item.productCode,
|
||||||
|
});
|
||||||
else if (["NEWS", "CASE", "HELP"].includes(section) && item.contentCode)
|
else if (["NEWS", "CASE", "HELP"].includes(section) && item.contentCode)
|
||||||
await post("/contents/delete", { siteCode: SITE, contentCode: item.contentCode, contentType: section });
|
await post("/contents/delete", {
|
||||||
|
siteCode: SITE,
|
||||||
|
contentCode: item.contentCode,
|
||||||
|
contentType: section,
|
||||||
|
});
|
||||||
await load();
|
await load();
|
||||||
} catch (operationError) { setError(operationError instanceof Error ? operationError.message : "删除失败"); }
|
} catch (operationError) {
|
||||||
|
setError(
|
||||||
|
operationError instanceof Error ? operationError.message : "删除失败",
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -319,16 +420,129 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
</div>
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
<button className={["products", "product-categories"].includes(section) ? "group-active" : ""} onClick={() => setProductMenuOpen(!productMenuOpen)}><Boxes size={18}/>产品<ChevronDown className={productMenuOpen ? "expanded" : ""} size={16}/></button>
|
<button
|
||||||
{productMenuOpen && <div className="nav-children"><button className={section === "products" ? "active" : ""} onClick={() => navigateSection("products")}>产品管理</button><button className={section === "product-categories" ? "active" : ""} onClick={() => navigateSection("product-categories")}>分类管理</button></div>}
|
className={
|
||||||
|
["products", "product-categories"].includes(section)
|
||||||
|
? "group-active"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
onClick={() => setProductMenuOpen(!productMenuOpen)}
|
||||||
|
>
|
||||||
|
<Boxes size={18} />
|
||||||
|
产品
|
||||||
|
<ChevronDown
|
||||||
|
className={productMenuOpen ? "expanded" : ""}
|
||||||
|
size={16}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
{productMenuOpen && (
|
||||||
|
<div className="nav-children">
|
||||||
|
<button
|
||||||
|
className={section === "products" ? "active" : ""}
|
||||||
|
onClick={() => navigateSection("products")}
|
||||||
|
>
|
||||||
|
产品管理
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={section === "product-categories" ? "active" : ""}
|
||||||
|
onClick={() => navigateSection("product-categories")}
|
||||||
|
>
|
||||||
|
分类管理
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
<button className={["NEWS", "NEWS-categories", "CASE", "CASE-categories", "HELP", "HELP-categories"].includes(section) ? "group-active" : ""} onClick={() => setContentMenuOpen(!contentMenuOpen)}><FolderTree size={18}/>内容<ChevronDown className={contentMenuOpen ? "expanded" : ""} size={16}/></button>
|
<button
|
||||||
{contentMenuOpen && <div className="nav-children content-children"><button className={["NEWS", "NEWS-categories"].includes(section) ? "active" : ""} onClick={() => navigateSection("NEWS")}><Newspaper size={15}/>新闻</button><button className={["CASE", "CASE-categories"].includes(section) ? "active" : ""} onClick={() => navigateSection("CASE")}><PanelsTopLeft size={15}/>案例</button><button className={["HELP", "HELP-categories"].includes(section) ? "active" : ""} onClick={() => navigateSection("HELP")}><HelpCircle size={15}/>帮助</button></div>}
|
className={
|
||||||
|
[
|
||||||
|
"NEWS",
|
||||||
|
"NEWS-categories",
|
||||||
|
"CASE",
|
||||||
|
"CASE-categories",
|
||||||
|
"HELP",
|
||||||
|
"HELP-categories",
|
||||||
|
].includes(section)
|
||||||
|
? "group-active"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
onClick={() => setContentMenuOpen(!contentMenuOpen)}
|
||||||
|
>
|
||||||
|
<FolderTree size={18} />
|
||||||
|
内容
|
||||||
|
<ChevronDown
|
||||||
|
className={contentMenuOpen ? "expanded" : ""}
|
||||||
|
size={16}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
{contentMenuOpen && (
|
||||||
|
<div className="nav-children content-children">
|
||||||
|
<button
|
||||||
|
className={
|
||||||
|
["NEWS", "NEWS-categories"].includes(section)
|
||||||
|
? "active"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
onClick={() => navigateSection("NEWS")}
|
||||||
|
>
|
||||||
|
<Newspaper size={15} />
|
||||||
|
新闻
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={
|
||||||
|
["CASE", "CASE-categories"].includes(section)
|
||||||
|
? "active"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
onClick={() => navigateSection("CASE")}
|
||||||
|
>
|
||||||
|
<PanelsTopLeft size={15} />
|
||||||
|
案例
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={
|
||||||
|
["HELP", "HELP-categories"].includes(section)
|
||||||
|
? "active"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
onClick={() => navigateSection("HELP")}
|
||||||
|
>
|
||||||
|
<HelpCircle size={15} />
|
||||||
|
帮助
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
<button className={frontSiteMenus.some((item) => item.key === section) ? "group-active" : ""} onClick={() => setFrontSiteMenuOpen(!frontSiteMenuOpen)}><Globe2 size={18}/>前台站<ChevronDown className={frontSiteMenuOpen ? "expanded" : ""} size={16}/></button>
|
<button
|
||||||
{frontSiteMenuOpen && <div className="nav-children front-site-children">{frontSiteMenus.map((item) => <button key={item.key} className={section === item.key ? "active" : ""} onClick={() => navigateSection(item.key)}><item.icon size={15}/>{item.label}</button>)}</div>}
|
className={
|
||||||
|
frontSiteMenus.some((item) => item.key === section)
|
||||||
|
? "group-active"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
onClick={() => setFrontSiteMenuOpen(!frontSiteMenuOpen)}
|
||||||
|
>
|
||||||
|
<Globe2 size={18} />
|
||||||
|
前台站
|
||||||
|
<ChevronDown
|
||||||
|
className={frontSiteMenuOpen ? "expanded" : ""}
|
||||||
|
size={16}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
{frontSiteMenuOpen && (
|
||||||
|
<div className="nav-children front-site-children">
|
||||||
|
{frontSiteMenus.map((item) => (
|
||||||
|
<button
|
||||||
|
key={item.key}
|
||||||
|
className={section === item.key ? "active" : ""}
|
||||||
|
onClick={() => navigateSection(item.key)}
|
||||||
|
>
|
||||||
|
<item.icon size={15} />
|
||||||
|
{item.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{menus.map((m) => (
|
{menus.map((m) => (
|
||||||
<button
|
<button
|
||||||
@@ -346,30 +560,114 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
<Users size={18} />
|
<Users size={18} />
|
||||||
CRM 客户
|
CRM 客户
|
||||||
</button>
|
</button>
|
||||||
<button className={section === "inquiry-settings" ? "active" : ""} onClick={() => navigateSection("inquiry-settings")}>
|
<button
|
||||||
|
className={section === "inquiry-settings" ? "active" : ""}
|
||||||
|
onClick={() => navigateSection("inquiry-settings")}
|
||||||
|
>
|
||||||
<Settings size={18} />
|
<Settings size={18} />
|
||||||
询盘设置
|
询盘设置
|
||||||
</button>
|
</button>
|
||||||
<button className={section === "settings" ? "active" : ""} onClick={() => navigateSection("settings")}>
|
<button
|
||||||
|
className={section === "settings" ? "active" : ""}
|
||||||
|
onClick={() => navigateSection("settings")}
|
||||||
|
>
|
||||||
<Settings size={18} />
|
<Settings size={18} />
|
||||||
系统设置
|
系统设置
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
<main>
|
<main>
|
||||||
{section === "settings" ? <SettingsPage account={account} onAccount={onAccount} onLogout={onLogout}/> : section === "seo-settings" ? <SeoSettingsPage/> : section === "agreements" ? <AgreementSettingsPage/> : section === "navigation" ? <NavigationManager/> : section === "decoration" ? <DecorationEditor onBack={() => navigateSection("pages")}/> : section === "custom-code" ? <CustomCodeManager/> : section === "media" ? <MediaCenter/> : editingProduct !== null ? <ProductEditor productCode={editingProduct || undefined} onBack={closeProductEditor} /> : editingContent !== null ? <ContentEditor contentType={editingContent.contentType} contentCode={editingContent.contentCode || undefined} onBack={closeContentEditor} /> : editingPage !== null ? <PageEditor pageCode={editingPage || undefined} onBack={closePageEditor}/> : <>
|
{section === "settings" ? (
|
||||||
{section.endsWith("-categories") ? <CategoryManager contentType={section === "NEWS-categories" ? "NEWS" : section === "CASE-categories" ? "CASE" : section === "HELP-categories" ? "HELP" : undefined}/> : <>
|
<SettingsPage
|
||||||
|
account={account}
|
||||||
|
onAccount={onAccount}
|
||||||
|
onLogout={onLogout}
|
||||||
|
/>
|
||||||
|
) : section === "seo-settings" ? (
|
||||||
|
<SeoSettingsPage />
|
||||||
|
) : section === "agreements" ? (
|
||||||
|
<AgreementSettingsPage />
|
||||||
|
) : section === "navigation" ? (
|
||||||
|
<NavigationManager />
|
||||||
|
) : section === "decoration" ? (
|
||||||
|
<DecorationEditor onBack={() => navigateSection("pages")} />
|
||||||
|
) : section === "custom-code" ? (
|
||||||
|
<CustomCodeManager />
|
||||||
|
) : section === "media" ? (
|
||||||
|
<MediaCenter />
|
||||||
|
) : editingProduct !== null ? (
|
||||||
|
<ProductEditor
|
||||||
|
productCode={editingProduct || undefined}
|
||||||
|
onBack={closeProductEditor}
|
||||||
|
/>
|
||||||
|
) : editingContent !== null ? (
|
||||||
|
<ContentEditor
|
||||||
|
contentType={editingContent.contentType}
|
||||||
|
contentCode={editingContent.contentCode || undefined}
|
||||||
|
onBack={closeContentEditor}
|
||||||
|
/>
|
||||||
|
) : editingPage !== null ? (
|
||||||
|
<PageEditor
|
||||||
|
pageCode={editingPage || undefined}
|
||||||
|
onBack={closePageEditor}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{section.endsWith("-categories") ? (
|
||||||
|
<CategoryManager
|
||||||
|
contentType={
|
||||||
|
section === "NEWS-categories"
|
||||||
|
? "NEWS"
|
||||||
|
: section === "CASE-categories"
|
||||||
|
? "CASE"
|
||||||
|
: section === "HELP-categories"
|
||||||
|
? "HELP"
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<header>
|
<header>
|
||||||
<div>
|
<div>
|
||||||
<h1>{title}管理</h1>
|
<h1>{title}管理</h1>
|
||||||
<p>Local Development Site · 英文站内容</p>
|
<p>Local Development Site · 英文站内容</p>
|
||||||
</div>
|
</div>
|
||||||
{!["inquiries", "inquiry-settings"].includes(section) && <div className="header-actions">
|
{!["inquiries", "inquiry-settings"].includes(section) && (
|
||||||
{["NEWS", "CASE", "HELP"].includes(section) && <button className="secondary" onClick={() => setSection(`${section}-categories` as Section)}><FolderTree size={17}/>管理分类</button>}
|
<div className="header-actions">
|
||||||
<button className="primary" onClick={() => section === "products" ? openProductEditor() : ["NEWS", "CASE", "HELP"].includes(section) ? openContentEditor(section as EditorialSection) : section === "pages" ? openPageEditor() : setOpen(true)}><Plus size={17}/>新建{title}</button>
|
{["NEWS", "CASE", "HELP"].includes(section) && (
|
||||||
</div>}
|
<button
|
||||||
|
className="secondary"
|
||||||
|
onClick={() =>
|
||||||
|
setSection(`${section}-categories` as Section)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FolderTree size={17} />
|
||||||
|
管理分类
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
className="primary"
|
||||||
|
onClick={() =>
|
||||||
|
section === "products"
|
||||||
|
? openProductEditor()
|
||||||
|
: ["NEWS", "CASE", "HELP"].includes(section)
|
||||||
|
? openContentEditor(section as EditorialSection)
|
||||||
|
: section === "pages"
|
||||||
|
? openPageEditor()
|
||||||
|
: setOpen(true)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Plus size={17} />
|
||||||
|
新建{title}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</header>
|
</header>
|
||||||
{section === "inquiry-settings" ? <InquirySettingsPanel/> : <><section className="toolbar">
|
{section === "inquiry-settings" ? (
|
||||||
|
<InquirySettingsPanel />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<section className="toolbar">
|
||||||
<div className="search">
|
<div className="search">
|
||||||
<Search size={17} />
|
<Search size={17} />
|
||||||
<input
|
<input
|
||||||
@@ -384,9 +682,29 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
{error}。请先启动 Admin 后端,并初始化本地站点数据。
|
{error}。请先启动 Admin 后端,并初始化本地站点数据。
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<section className={`table ${section === "inquiries" ? "inquiry-table" : ""}`}>
|
<section
|
||||||
|
className={`table ${section === "inquiries" ? "inquiry-table" : ""}`}
|
||||||
|
>
|
||||||
<div className="thead">
|
<div className="thead">
|
||||||
{section === "inquiries" ? <><span>公司名称</span><span>电子邮箱</span><span>国家 / IP地址</span><span>询盘时间</span><span>询盘来源</span><span>状态</span><span>操作</span></> : <><span>名称</span><span>英文路径</span><span>状态</span><span>发布时间</span><span>操作</span></>}
|
{section === "inquiries" ? (
|
||||||
|
<>
|
||||||
|
<span>公司名称</span>
|
||||||
|
<span>电子邮箱</span>
|
||||||
|
<span>国家 / IP地址</span>
|
||||||
|
<span>询盘时间</span>
|
||||||
|
<span>询盘来源</span>
|
||||||
|
<span>状态</span>
|
||||||
|
<span>操作</span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span>名称</span>
|
||||||
|
<span>英文路径</span>
|
||||||
|
<span>状态</span>
|
||||||
|
<span>发布时间</span>
|
||||||
|
<span>操作</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{filtered.length === 0 && !error ? (
|
{filtered.length === 0 && !error ? (
|
||||||
<div className="empty">
|
<div className="empty">
|
||||||
@@ -398,16 +716,144 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
|
|||||||
<div
|
<div
|
||||||
className="row"
|
className="row"
|
||||||
key={
|
key={
|
||||||
item.productCode || item.contentCode || item.pageCode || item.inquiryCode || index
|
item.productCode ||
|
||||||
|
item.contentCode ||
|
||||||
|
item.pageCode ||
|
||||||
|
item.inquiryCode ||
|
||||||
|
index
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{section === "inquiries" ? <><span><strong>{item.companyName || item.customerName || "--"}</strong><small>{item.customerName || "--"}</small></span><span>{item.customerEmail || "--"}</span><span>{item.countryName || item.countryCode || "未知"}({item.clientIp || "--"})</span><span>{formatTime(item.createTime)}</span><span>{item.productName || item.inquiryTitle || item.sourceType || "网站询盘"}</span><span className={`status ${item.status.toLowerCase()}`}>{item.readStatus === 0 ? "未读" : item.statusLabel || item.status}</span><div className="row-actions"><button className="link">查看</button></div></> : <><span><strong>{item.productName || item.title || item.pageName}</strong><small>{item.model || item.productCode || item.contentCode || item.pageCode}</small></span><code>/{item.slug}</code><span className={`status ${item.status.toLowerCase()}`}>{statusLabels[item.status] || item.status}</span><span>{formatTime(item.publishTime)}</span><div className="row-actions">{["products", "NEWS", "CASE", "HELP"].includes(section) && item.slug && <a className="link" href={`${SITE_WEB}/${section === "products" ? "products" : section === "CASE" ? "cases" : section === "NEWS" ? "news" : "help"}/${encodeURIComponent(item.slug)}`} target="_blank" rel="noreferrer">查看前台</a>}<button className="link" onClick={() => section === "products" && item.productCode ? openProductEditor(item.productCode) : ["NEWS", "CASE", "HELP"].includes(section) && item.contentCode ? openContentEditor(section as EditorialSection, item.contentCode) : section === "pages" && item.pageCode ? openPageEditor(item.pageCode) : undefined}>编辑</button>{["products", "NEWS", "CASE", "HELP"].includes(section) && <><button className="link" onClick={() => void changeItemStatus(item)}>{item.status === "PUBLISHED" ? "下架" : "上架"}</button><button className="link danger" onClick={() => void deleteItem(item)}>删除</button></>}</div></>}
|
{section === "inquiries" ? (
|
||||||
|
<>
|
||||||
|
<span>
|
||||||
|
<strong>
|
||||||
|
{item.companyName ||
|
||||||
|
item.customerName ||
|
||||||
|
"--"}
|
||||||
|
</strong>
|
||||||
|
<small>{item.customerName || "--"}</small>
|
||||||
|
</span>
|
||||||
|
<span>{item.customerEmail || "--"}</span>
|
||||||
|
<span>
|
||||||
|
{item.countryName ||
|
||||||
|
item.countryCode ||
|
||||||
|
"未知"}
|
||||||
|
({item.clientIp || "--"})
|
||||||
|
</span>
|
||||||
|
<span>{formatTime(item.createTime)}</span>
|
||||||
|
<span>
|
||||||
|
{item.productName ||
|
||||||
|
item.inquiryTitle ||
|
||||||
|
item.sourceType ||
|
||||||
|
"网站询盘"}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className={`status ${item.status.toLowerCase()}`}
|
||||||
|
>
|
||||||
|
{item.readStatus === 0
|
||||||
|
? "未读"
|
||||||
|
: item.statusLabel || statusLabel(item.status)}
|
||||||
|
</span>
|
||||||
|
<div className="row-actions">
|
||||||
|
<button className="link">查看</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span>
|
||||||
|
<strong>
|
||||||
|
{item.productName ||
|
||||||
|
item.title ||
|
||||||
|
item.pageName}
|
||||||
|
</strong>
|
||||||
|
<small>
|
||||||
|
{item.model ||
|
||||||
|
item.productCode ||
|
||||||
|
item.contentCode ||
|
||||||
|
item.pageCode}
|
||||||
|
</small>
|
||||||
|
</span>
|
||||||
|
<code>/{item.slug}</code>
|
||||||
|
<span
|
||||||
|
className={`status ${item.status.toLowerCase()}`}
|
||||||
|
>
|
||||||
|
{statusLabel(item.status)}
|
||||||
|
</span>
|
||||||
|
<span>{formatTime(item.publishTime)}</span>
|
||||||
|
<div className="row-actions">
|
||||||
|
{[
|
||||||
|
"products",
|
||||||
|
"NEWS",
|
||||||
|
"CASE",
|
||||||
|
"HELP",
|
||||||
|
].includes(section) &&
|
||||||
|
item.slug && (
|
||||||
|
<a
|
||||||
|
className="link"
|
||||||
|
href={`${SITE_WEB}/${section === "products" ? "products" : section === "CASE" ? "cases" : section === "NEWS" ? "news" : "help"}/${encodeURIComponent(item.slug)}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
查看前台
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
className="link"
|
||||||
|
onClick={() =>
|
||||||
|
section === "products" && item.productCode
|
||||||
|
? openProductEditor(item.productCode)
|
||||||
|
: ["NEWS", "CASE", "HELP"].includes(
|
||||||
|
section,
|
||||||
|
) && item.contentCode
|
||||||
|
? openContentEditor(
|
||||||
|
section as EditorialSection,
|
||||||
|
item.contentCode,
|
||||||
|
)
|
||||||
|
: section === "pages" && item.pageCode
|
||||||
|
? openPageEditor(item.pageCode)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</button>
|
||||||
|
{[
|
||||||
|
"products",
|
||||||
|
"NEWS",
|
||||||
|
"CASE",
|
||||||
|
"HELP",
|
||||||
|
].includes(section) && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
className="link"
|
||||||
|
onClick={() =>
|
||||||
|
void changeItemStatus(item)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{item.status === "PUBLISHED"
|
||||||
|
? "下架"
|
||||||
|
: "上架"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="link danger"
|
||||||
|
onClick={() => void deleteItem(item)}
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
</section></>}
|
</section>
|
||||||
</>}
|
</>
|
||||||
</>}
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</main>
|
</main>
|
||||||
{open && (
|
{open && (
|
||||||
<div className="mask">
|
<div className="mask">
|
||||||
@@ -525,12 +971,25 @@ function RootApp() {
|
|||||||
.then(setAccount)
|
.then(setAccount)
|
||||||
.catch(() => setAccount(null))
|
.catch(() => setAccount(null))
|
||||||
.finally(() => setChecking(false));
|
.finally(() => setChecking(false));
|
||||||
return () => window.removeEventListener("shoplix:unauthorized", unauthorized);
|
return () =>
|
||||||
|
window.removeEventListener("shoplix:unauthorized", unauthorized);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (checking) return <div className="auth-loading"><div className="auth-spinner"/><span>正在验证登录状态</span></div>;
|
if (checking)
|
||||||
if (!account) return <LoginPage onLogin={setAccount}/>;
|
return (
|
||||||
return <App account={account} onAccount={setAccount} onLogout={() => setAccount(null)}/>;
|
<div className="auth-loading">
|
||||||
|
<div className="auth-spinner" />
|
||||||
|
<span>正在验证登录状态</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
if (!account) return <LoginPage onLogin={setAccount} />;
|
||||||
|
return (
|
||||||
|
<App
|
||||||
|
account={account}
|
||||||
|
onAccount={setAccount}
|
||||||
|
onLogout={() => setAccount(null)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
createRoot(document.getElementById("root")!).render(
|
createRoot(document.getElementById("root")!).render(
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/** 管理后台通用状态中文文案。 */
|
||||||
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
|
DRAFT: "草稿",
|
||||||
|
PUBLISHED: "已上架",
|
||||||
|
OFFLINE: "已下架",
|
||||||
|
ENABLED: "已启用",
|
||||||
|
DISABLED: "已停用",
|
||||||
|
ACTIVE: "正常",
|
||||||
|
INACTIVE: "已停用",
|
||||||
|
PENDING: "待处理",
|
||||||
|
PROCESSING: "处理中",
|
||||||
|
SUCCESS: "成功",
|
||||||
|
FAILED: "失败",
|
||||||
|
SENT: "已发送",
|
||||||
|
READ: "已读",
|
||||||
|
UNREAD: "未读",
|
||||||
|
DELETED: "已删除",
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 将接口状态值统一转换为中文,未知状态显示为“未知状态”。 */
|
||||||
|
export function statusLabel(status?: string): string {
|
||||||
|
if (!status) return "未知状态";
|
||||||
|
return STATUS_LABELS[status.toUpperCase()] || "未知状态";
|
||||||
|
}
|
||||||
Reference in new issue
Block a user