bug修复

This commit is contained in:
张锐 committed 2026-11-24 14:49:58 +08:00
1 parent 529c255e5b
commit 3893b25848
9 files changed
+2548 -247

No files matched your search

+568 -109
View File
@@ -36,12 +36,37 @@ import SeoSettingsPage from "./SeoSettingsPage";
import NavigationManager from "./NavigationManager";
import AgreementSettingsPage from "./AgreementSettingsPage";
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";
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 ContentEditorState = { contentType: EditorialSection; contentCode: string };
type ContentEditorState = {
contentType: EditorialSection;
contentCode: string;
};
type Item = {
productCode?: string;
contentCode?: string;
@@ -73,7 +98,12 @@ type Item = {
function formatTime(value?: number): string {
if (!value) return "--";
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));
}
@@ -94,25 +124,57 @@ const menus = [
{ key: "inquiries" as Section, label: "询盘", icon: Mail },
];
const sectionLabels: Record<Section, string> = {
products: "产品", "product-categories": "产品分类", NEWS: "新闻", "NEWS-categories": "新闻分类",
CASE: "案例", "CASE-categories": "案例分类", HELP: "帮助", "HELP-categories": "帮助分类",
pages: "页面", navigation: "菜单导航", decoration: "店铺装修", "custom-code": "自定义代码", media: "素材中心", inquiries: "询盘", "inquiry-settings": "询盘设置",
products: "产品",
"product-categories": "产品分类",
NEWS: "新闻",
"NEWS-categories": "新闻分类",
CASE: "案例",
"CASE-categories": "案例分类",
HELP: "帮助",
"HELP-categories": "帮助分类",
pages: "页面",
navigation: "菜单导航",
decoration: "店铺装修",
"custom-code": "自定义代码",
media: "素材中心",
inquiries: "询盘",
"inquiry-settings": "询盘设置",
"seo-settings": "页面 SEO",
agreements: "协议设置",
settings: "系统设置",
};
const statusLabels: Record<string, string> = { DRAFT: "草稿", PUBLISHED: "已上架", OFFLINE: "已下架" };
function App({ account, onAccount, onLogout }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void }) {
const contentRoutes: Record<EditorialSection, string> = { NEWS: "news", CASE: "cases", HELP: "help" };
function App({
account,
onAccount,
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 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;
const contentType = ({ news: "NEWS", cases: "CASE", help: "HELP" } as const)[match[1] as "news" | "cases" | "help"];
return { contentType, contentCode: match[2] === "new" ? "" : decodeURIComponent(match[3]) };
const contentType = (
{ 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 [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 [error, setError] = 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$/);
return match ? decodeURIComponent(match[1]) : null;
};
const [editingProduct, setEditingProduct] = useState<string | null>(resolveProductRoute);
const [editingContent, setEditingContent] = useState<ContentEditorState | null>(initialContentEditor);
const [editingPage, setEditingPage] = useState<string | null>(resolvePageRoute);
const [editingProduct, setEditingProduct] = useState<string | null>(
resolveProductRoute,
);
const [editingContent, setEditingContent] =
useState<ContentEditorState | null>(initialContentEditor);
const [editingPage, setEditingPage] = useState<string | null>(
resolvePageRoute,
);
const [productMenuOpen, setProductMenuOpen] = useState(true);
const [contentMenuOpen, setContentMenuOpen] = useState(true);
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(true);
@@ -152,29 +219,28 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
const load = async () => {
try {
setError("");
const data =
section.endsWith("-categories")
? { items: [] }
: section === "settings"
const data = section.endsWith("-categories")
? { items: [] }
: section === "settings"
? { items: [] }
: section === "navigation"
? { items: [] }
: section === "agreements"
? { items: [] }
: section === "products"
? await post("/products/list", { siteCode: SITE })
: section === "pages"
? await post("/pages/list", { siteCode: SITE })
: section === "decoration"
? { items: [] }
: section === "agreements"
? { items: [] }
: section === "inquiries"
? await post("/inquiries/list", { siteCode: SITE })
: section === "inquiry-settings"
? { items: [] }
: await post("/contents/list", {
siteCode: SITE,
contentType: section,
});
: section === "products"
? await post("/products/list", { siteCode: SITE })
: section === "pages"
? await post("/pages/list", { siteCode: SITE })
: section === "decoration"
? { items: [] }
: section === "inquiries"
? await post("/inquiries/list", { siteCode: SITE })
: section === "inquiry-settings"
? { items: [] }
: await post("/contents/list", {
siteCode: SITE,
contentType: section,
});
setItems(data.items || []);
} catch (e) {
setError(e instanceof Error ? e.message : "加载失败");
@@ -207,9 +273,14 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
setEditingProduct(null);
void load();
};
const openContentEditor = (contentType: EditorialSection, contentCode?: string) => {
const openContentEditor = (
contentType: EditorialSection,
contentCode?: string,
) => {
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);
setEditingContent({ contentType, contentCode: contentCode || "" });
};
@@ -218,7 +289,11 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
setEditingContent(null);
};
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 || "");
};
const closePageEditor = () => {
@@ -234,22 +309,48 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
try {
setError("");
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)
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();
} catch (operationError) { setError(operationError instanceof Error ? operationError.message : "状态更新失败"); }
} catch (operationError) {
setError(
operationError instanceof Error
? operationError.message
: "状态更新失败",
);
}
};
const deleteItem = async (item: Item) => {
if (!window.confirm("删除后该内容将不再展示,确认删除吗?")) return;
try {
setError("");
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)
await post("/contents/delete", { siteCode: SITE, contentCode: item.contentCode, contentType: section });
await post("/contents/delete", {
siteCode: SITE,
contentCode: item.contentCode,
contentType: section,
});
await load();
} catch (operationError) { setError(operationError instanceof Error ? operationError.message : "删除失败"); }
} catch (operationError) {
setError(
operationError instanceof Error ? operationError.message : "删除失败",
);
}
};
const save = async () => {
try {
@@ -319,16 +420,129 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
</div>
<nav>
<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>
{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>}
<button
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 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>
{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>}
<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>
{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 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>
{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>}
<button
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>
{menus.map((m) => (
<button
@@ -346,68 +560,300 @@ function App({ account, onAccount, onLogout }: { account: Account; onAccount: (v
<Users size={18} />
CRM 客户
</button>
<button className={section === "inquiry-settings" ? "active" : ""} onClick={() => navigateSection("inquiry-settings")}>
<button
className={section === "inquiry-settings" ? "active" : ""}
onClick={() => navigateSection("inquiry-settings")}
>
<Settings size={18} />
询盘设置
</button>
<button className={section === "settings" ? "active" : ""} onClick={() => navigateSection("settings")}>
<button
className={section === "settings" ? "active" : ""}
onClick={() => navigateSection("settings")}
>
<Settings size={18} />
系统设置
</button>
</div>
</aside>
<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.endsWith("-categories") ? <CategoryManager contentType={section === "NEWS-categories" ? "NEWS" : section === "CASE-categories" ? "CASE" : section === "HELP-categories" ? "HELP" : undefined}/> : <>
<header>
<div>
<h1>{title}管理</h1>
<p>Local Development Site · 英文站内容</p>
</div>
{!["inquiries", "inquiry-settings"].includes(section) && <div className="header-actions">
{["NEWS", "CASE", "HELP"].includes(section) && <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>
{section === "inquiry-settings" ? <InquirySettingsPanel/> : <><section className="toolbar">
<div className="search">
<Search size={17} />
<input
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder={`搜索${title}名称或路径`}
/>
</div>
</section>
{error && (
<div className="notice">
{error}。请先启动 Admin 后端,并初始化本地站点数据。
</div>
)}
<section className={`table ${section === "inquiries" ? "inquiry-table" : ""}`}>
<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></>}
</div>
{filtered.length === 0 && !error ? (
<div className="empty">
<strong>暂无{title}数据</strong>
<p>点击右上角新建按钮录入第一条内容。</p>
</div>
) : (
filtered.map((item, index) => (
<div
className="row"
key={
item.productCode || item.contentCode || item.pageCode || item.inquiryCode || index
{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.endsWith("-categories") ? (
<CategoryManager
contentType={
section === "NEWS-categories"
? "NEWS"
: section === "CASE-categories"
? "CASE"
: section === "HELP-categories"
? "HELP"
: undefined
}
>
{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></>}
</div>
))
)}
</section></>}
</>}
</>}
/>
) : (
<>
<header>
<div>
<h1>{title}管理</h1>
<p>Local Development Site · 英文站内容</p>
</div>
{!["inquiries", "inquiry-settings"].includes(section) && (
<div className="header-actions">
{["NEWS", "CASE", "HELP"].includes(section) && (
<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>
{section === "inquiry-settings" ? (
<InquirySettingsPanel />
) : (
<>
<section className="toolbar">
<div className="search">
<Search size={17} />
<input
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder={`搜索${title}名称或路径`}
/>
</div>
</section>
{error && (
<div className="notice">
{error}。请先启动 Admin 后端,并初始化本地站点数据。
</div>
)}
<section
className={`table ${section === "inquiries" ? "inquiry-table" : ""}`}
>
<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>
</>
)}
</div>
{filtered.length === 0 && !error ? (
<div className="empty">
<strong>暂无{title}数据</strong>
<p>点击右上角新建按钮录入第一条内容。</p>
</div>
) : (
filtered.map((item, index) => (
<div
className="row"
key={
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 || 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>
))
)}
</section>
</>
)}
</>
)}
</>
)}
</main>
{open && (
<div className="mask">
@@ -525,12 +971,25 @@ function RootApp() {
.then(setAccount)
.catch(() => setAccount(null))
.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 (!account) return <LoginPage onLogin={setAccount}/>;
return <App account={account} onAccount={setAccount} onLogout={() => setAccount(null)}/>;
if (checking)
return (
<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(