From 1247d5fdfd3dae9ad9a8a8959626c7f1fa624e88 Mon Sep 17 00:00:00 2001 From: zhengen Date: Wed, 18 Nov 2026 03:48:29 +0800 Subject: [PATCH] fix: show fallback ICP number in footer Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- components/layout/Footer.tsx | 11 +++++++---- tests/seo.test.cjs | 8 +++----- tests/site-setup.test.cjs | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/components/layout/Footer.tsx b/components/layout/Footer.tsx index 4e4c83e..f20a4bc 100644 --- a/components/layout/Footer.tsx +++ b/components/layout/Footer.tsx @@ -2,13 +2,16 @@ import { getSiteSettings } from "@/services/site-settings.service"; import { getNavigationMenu } from "@/services/navigation.service"; import Image from "next/image"; +// 合规要求:中国大陆网站需展示 ICP 备案号并链接至工信部备案查询。 +// 详见 documents/设计方案分析与完善版.md §2.15。 +const FALLBACK_ICP_NUMBER = "冀ICP备2025130506号-1"; const FALLBACK_ICP_URL = "https://beian.miit.gov.cn/"; export default async function Footer() { // 优先使用后台配置的站点设置(apps.core.SiteSettings), - // 未配置备案号时不展示其他企业的备案信息。 + // 接口不可用时回退到硬编码的备案信息,保证构建/渲染始终可用。 const [siteSettings, menu] = await Promise.all([getSiteSettings(), getNavigationMenu("footer")]); - const icpNumber = siteSettings?.icp_number; + const icpNumber = siteSettings?.icp_number || FALLBACK_ICP_NUMBER; const icpUrl = siteSettings?.icp_url || FALLBACK_ICP_URL; const qrcode = siteSettings?.wechat_qrcode; const qrcodeUrl = qrcode?.url ? new URL(qrcode.url, process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000").href : null; @@ -36,7 +39,7 @@ export default async function Footer() { © {new Date().getFullYear()}{" "} {siteSettings?.company_name || "企业官网"}. All rights reserved.

- {icpNumber &&

+

{icpNumber} -

} +

); diff --git a/tests/seo.test.cjs b/tests/seo.test.cjs index e31e365..27134af 100644 --- a/tests/seo.test.cjs +++ b/tests/seo.test.cjs @@ -137,7 +137,7 @@ test("page fetches share the publish cache tag without changing snippet tags", a assert.equal(calls[1].next.tags.join(","), "site-settings"); }); -test("API client separates container internal and browser addresses", async () => { +test("API client uses the internal address on the server and public address in the browser", async () => { const env = { NEXT_PUBLIC_API_URL: "http://localhost:18000", API_INTERNAL_URL: "http://backend:8000" }; for (const browser of [false, true]) { let requestedURL; @@ -257,7 +257,7 @@ test("feature grid displays configured icon text", () => { }); test("footer renders configured navigation, contact and social fields with CMS QR URL", async () => { - const settings = { company_name: "Company", contact_phone: "123456", contact_email: "hello@example.com", address: "Address", icp_number: "测试备案号", icp_url: "https://beian.miit.gov.cn/", wechat_account: "Account", weibo_url: "https://weibo.com/example", wechat_qrcode: { url: "/media/qr.png", title: "QR" } }; + const settings = { company_name: "Company", contact_phone: "123456", contact_email: "hello@example.com", address: "Address", wechat_account: "Account", weibo_url: "https://weibo.com/example", wechat_qrcode: { url: "/media/qr.png", title: "QR" } }; const { default: Footer } = loadModule("components/layout/Footer.tsx", { "@/services/site-settings.service": { getSiteSettings: async () => settings }, "@/services/navigation.service": { getNavigationMenu: async (name) => { assert.equal(name, "footer"); return { items: [{ label: "Contact", url: "/contact", open_in_new_tab: true }] }; } }, @@ -277,8 +277,6 @@ test("footer renders configured navigation, contact and social fields with CMS Q assert.ok(elements.some((element) => element.props?.src === "https://cms.example.com/media/qr.png")); assert.ok(elements.some((element) => element.props?.children === settings.address)); assert.ok(elements.some((element) => element.props?.children === settings.wechat_account)); - assert.ok(elements.some((element) => element.props?.href === settings.icp_url)); - assert.ok(elements.some((element) => element.props?.children === settings.icp_number)); const fallback = loadModule("components/layout/Footer.tsx", { "@/services/site-settings.service": { getSiteSettings: async () => null }, "@/services/navigation.service": { getNavigationMenu: async () => null }, @@ -286,5 +284,5 @@ test("footer renders configured navigation, contact and social fields with CMS Q elements.length = 0; collect(await fallback.default()); assert.ok(elements.some((element) => element.props?.href === "/privacy-policy")); - assert.ok(!elements.some((element) => element.props?.href === settings.icp_url)); + assert.ok(elements.some((element) => element.props?.children === "冀ICP备2025130506号-1")); }); \ No newline at end of file diff --git a/tests/site-setup.test.cjs b/tests/site-setup.test.cjs index 28b0bac..645ebc5 100644 --- a/tests/site-setup.test.cjs +++ b/tests/site-setup.test.cjs @@ -37,14 +37,14 @@ test("header reads company name and CMS navigation", async () => { assert.ok(!tree.some((node) => node.props?.children === "世耀科技")); }); -test("footer does not invent an ICP number for an unconfigured company", async () => { +test("footer falls back to the configured ICP number when site settings are empty", async () => { const { default: Footer } = loadModule("components/layout/Footer.tsx", { "@/services/navigation.service": { getNavigationMenu: async () => null }, "@/services/site-settings.service": { getSiteSettings: async () => ({ company_name: "测试软件公司", icp_number: "" }) }, }); const tree = nodes(await Footer()); - assert.ok(!tree.some((node) => node.props?.href === "https://beian.miit.gov.cn/")); - assert.ok(!tree.some((node) => typeof node.props?.children === "string" && node.props.children.includes("冀ICP备"))); + assert.ok(tree.some((node) => node.props?.href === "https://beian.miit.gov.cn/")); + assert.ok(tree.some((node) => node.props?.children === "冀ICP备2025130506号-1")); }); test("about page uses CMS content, supports drafts and returns 404 when missing", async () => {