fix: show fallback ICP number in footer
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -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.
|
||||
</p>
|
||||
{icpNumber && <p className="mt-2">
|
||||
<p className="mt-2">
|
||||
<a
|
||||
href={icpUrl}
|
||||
target="_blank"
|
||||
@@ -45,7 +48,7 @@ export default async function Footer() {
|
||||
>
|
||||
{icpNumber}
|
||||
</a>
|
||||
</p>}
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
|
||||
+3
-5
@@ -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"));
|
||||
});
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user