diff --git a/web-admin/src/AgreementSettingsPage.tsx b/web-admin/src/AgreementSettingsPage.tsx index 71ff616..2c71c73 100644 --- a/web-admin/src/AgreementSettingsPage.tsx +++ b/web-admin/src/AgreementSettingsPage.tsx @@ -7,13 +7,17 @@ import { apiPost } from "./api"; const SITE = "SIT0000000000001"; type AgreementKey = "COOKIE_POLICY" | "PRIVACY_POLICY" | "TERMS_OF_SERVICE"; -type AgreementTab = { key: AgreementKey; label: string; pageName: string; slug: string }; +type AgreementTab = { key: AgreementKey; label: string; pageName: string; slug: string; seoDescription:string; robots:string }; +type AgreementSeo={title:string;description:string;canonicalUrl:string;robots:string;h1:string}; const tabs: AgreementTab[] = [ - { key: "COOKIE_POLICY", label: "Cookies协议", pageName: "Cookies Policy", slug: "cookie-policy" }, - { key: "PRIVACY_POLICY", label: "隐私协议", pageName: "Privacy Policy", slug: "privacy-policy" }, - { key: "TERMS_OF_SERVICE", label: "服务协议", pageName: "Terms of Use", slug: "terms-of-service" }, + { key: "COOKIE_POLICY", label: "Cookies协议", pageName: "Cookies Policy", slug: "cookie-policy",seoDescription:"Learn how this website uses cookies to improve browsing and website functionality.",robots:"noindex,follow" }, + { key: "PRIVACY_POLICY", label: "隐私协议", pageName: "Privacy Policy", slug: "privacy-policy",seoDescription:"Learn how Shoplix collects, uses and protects personal information.",robots:"index,follow" }, + { key: "TERMS_OF_SERVICE", label: "服务协议", pageName: "Terms of Use", slug: "terms-of-service",seoDescription:"Review the terms and conditions that govern the use of the Shoplix website and services.",robots:"index,follow" }, ]; +/** 创建协议页的基础 SEO 默认值。 */ +function defaultSeo(tab:AgreementTab):AgreementSeo{return{title:`${tab.pageName} | Shoplix`,description:tab.seoDescription,canonicalUrl:`/${tab.slug}`,robots:tab.robots,h1:tab.pageName}} + /** 固定协议页面配置,支持 Cookies、隐私和服务协议独立维护。 */ export default function AgreementSettingsPage() { const [activeKey, setActiveKey] = useState("COOKIE_POLICY"); @@ -22,6 +26,7 @@ export default function AgreementSettingsPage() { const [status, setStatus] = useState("DRAFT"); const [notice, setNotice] = useState(""); const [saving, setSaving] = useState(false); + const [seo,setSeo]=useState(()=>defaultSeo(tabs[0])); const activeTab = useMemo(() => tabs.find((tab) => tab.key === activeKey) || tabs[0], [activeKey]); const editor = useEditor({ extensions: [StarterKit, Link.configure({ openOnClick: false })], content: "

" }); @@ -30,6 +35,7 @@ export default function AgreementSettingsPage() { }, []); useEffect(() => { const code = pageCodes[activeKey]; + setSeo(defaultSeo(activeTab)); if (!code) { setTitle(activeTab.pageName); setStatus("DRAFT"); @@ -40,6 +46,10 @@ export default function AgreementSettingsPage() { setTitle(data.pageName || activeTab.pageName); setStatus(data.status || "DRAFT"); editor?.commands.setContent(data.pageContent || "

"); + return apiPost("/seo/detail",{siteCode:SITE,pageType:"SYSTEM_PAGE",targetCode:code}).catch(()=>undefined); + }).then((seoData)=>{ + if(!seoData)return; + setSeo({title:seoData.title||defaultSeo(activeTab).title,description:seoData.description||defaultSeo(activeTab).description,canonicalUrl:seoData.canonicalUrl||`/${activeTab.slug}`,robots:seoData.robots||activeTab.robots,h1:seoData.h1||activeTab.pageName}); }).catch((error) => setNotice(error instanceof Error ? error.message : "加载失败")); }, [activeKey, pageCodes, editor, activeTab]); @@ -67,7 +77,8 @@ export default function AgreementSettingsPage() { sortNo: 30, status, }); setPageCodes((current) => ({ ...current, [activeKey]: result.pageCode })); - setNotice("协议已保存"); + await apiPost("/seo/save",{siteCode:SITE,pageType:"SYSTEM_PAGE",targetCode:result.pageCode,title:seo.title.trim()||title.trim(),description:seo.description.trim(),keywords:"",h1:seo.h1.trim()||title.trim(),canonicalUrl:seo.canonicalUrl.trim()||`/${activeTab.slug}`,robots:seo.robots,ogTitle:"",ogDescription:"",ogImageUrl:"",structuredData:null,status,headings:[]}); + setNotice("协议与 SEO 已保存"); } catch (error) { setNotice(error instanceof Error ? error.message : "保存失败"); } finally { @@ -82,7 +93,8 @@ export default function AgreementSettingsPage() {

{activeTab.label}

-
{notice &&

{notice}

} + +

SEO 设置