feat(ia): 一级导航改对标双轴(行业 × 能力 + 洞察),并把导航真源从 DB 行反转为代码

依据实测:Bain 一级导航 = Industries · Consulting Services · Digital · Insights · About · Careers,
Porsche = 行业 · 实践 · 洞察 · 职业 · 关于我们 —— **两家的导航里都没有「产品」**。
咨询业按「客户的问题空间 × 本所的能力」组织,不按产品 SKU 组织。本仓此前 7 项里
产品居首,且 案例(case-study 0 行)、新闻动态(2 行) 是挂在骨架上的空渠道。

落地策略是**换标签、不换路由**:行业→既有 /solutions(solution 模型本就是行业),
能力→既有 /services(service 模型的 4 行本就是能力组)。
理由不是省事,而是避免制造重复内容:若新增 /capabilities 与 /services 并行,
同一个 ContentItem 会同时挂在两个 URL 下 —— 那是 canonical 冲突,比不改更糟。
URL 改名 + 308 留给第二批一次性处理。唯一真正新增的面是 /insights:
它聚合 news + methodology + case-study,今天没有任何单一页面做过这件事,故不构成重复。

「轴 = 视图,模型 = 真源」:本轮零新 ContentModel、零 schema、零 seed 权限测试改动。
沿用 solution/service/product 三个 code ⇒ src/lib/seed-permissions.test.ts:50 的
SUPER_ADMIN_ONLY_MODELS 断言保持绿。**这是设计选择的回报,不是没做事。**

最关键的一处:反转导航优先级
  layout.tsx 原为 `(navData?.mainNav) || NAVIGATION_V2` —— **DB 行胜出、代码只兜底**。
  `navigation` 的字段是泛型 json,改导航不需动 schema,听起来省事,实际是:
  只改 navigation.ts 会上线一个**生产静默忽略它**的新导航。
  而 footer 按 megaDropdown 的 key 取栏目 —— 新代码 key 对旧 DB key ⇒ 页脚三栏静默变空。
  我在工作树里真的复现了这个状态:本地 navigation/default 行仍是旧 7 项,
  它**内部完全自洽**(每个 dropdownKey 都找得到面板),所以「自洽即放行」会继续覆盖代码。
  ⇒ 新校验器的标准是「它是不是这套 IA」(必须覆盖 industries/capabilities/insights 三轴),
    而不是「它是不是合法 JSON」。不合格则 fail-closed 到代码 + 把原因 console.warn 出来
    (渲染期不写库:Notification 是后台数据,在 RSC 里写它等于给每次首页渲染挂写副作用)。
  这条有专门用例:「旧 IA 的自洽配置必须被拒」。

顺带修掉两处同族缺陷
- injectStandaloneProducts 原按 `key === 'products'` 匹配;双轴改名后该 key 不存在 ⇒
  独立产品会**静默不再注入**。改为按组 id(STANDALONE_GROUP_ID)找,组 id 比 key 稳定。
- 激活判定原来有**三套**:header 的 8 分支 per-id 阶梯(末尾落回 pathname===`/${item.id}`,
  新 id industries 会拼出一个不存在的路由 ⇒ 行业永不高亮)、mobile-tab-bar 的 per-id
  if 阶梯(改名后每项静默返回 false ⇒ tab bar 照渲染、永不高亮 = 绿但空洞)、footer 自一套。
  现统一为 lib/nav-active.ts,按 segment 切(不被 /solutionship 这类同前缀误点亮)。

撤下两个空渠道入口(含一处我自己计划里的回退,已当场纠正)
- /cases 从一级导航与移动端 tab bar 撤下:case-study 0 行,点进去是空列表。
  路由与模型**保留休眠**,真实授权案例到位当天即可渲染,不必二次迁移。
- 补 { id: 'all-products', href: '/products' } 进能力轴第二层:
  撤「产品」时若不补这一条,/products(sitemap priority 0.9、6 个详情页的上游 hub)
  就变成**没有导航入口的孤儿页** —— 那是回退不是重构。「降级」不等于「消失」,
  已加守卫用例「被退出一级导航的 hub 必须在第二层仍可达」。

/insights 的三处登记(少一处就是「新页面没人扫、门禁仍然绿」的静默覆盖收缩)
- sitemap.ts:新增,priority 0.8;/news 暂留(已索引),第二批 301 归并
- check:headings 的 PAGES 列表:新增(该列表是硬编码路由清单)
- revalidate:新增 INSIGHTS_AFFECTED_MODELS(news/case-study/methodology)
  —— /insights 不在 CONTENT_TYPE_CONFIGS 的任何 listPage 里,通用推导只刷 /news、
  /methodology;少登记这条的后果不是报错,而是后台发了新内容、洞察页仍端出旧 ISR
  快照最长 1 小时,且没有任何门禁会红。已钉 3 正向 + 1 负向(product 变更不得刷
  /insights,否则该断言恒真、失去约束力)+ 1 去重。

删除 NAVIGATION(V1):7 个 href 全是 '/'、全站零生产引用,只被 constants.test.ts 供着 ——
那 4 条用例的作用是让死码看起来「有人在用」。已改写成断言活的 NAVIGATION_V2,
并保留其原有意图(每个目的地互不相同,正是 V1 缺的那条)。

KNOWN-RED: test:visual —— 一级导航 7→4、页脚三栏改标题改取数、移动端 tab bar 换轴,
header/footer 相关基线预期 churn。按计划 #10 在所有代码落地后一次性重捕(需 AUTH-VISUAL)。

待授权(本笔**未**执行,且必须执行才能对用户生效):
  CMS 的 navigation/default 行仍是旧 7 项。本笔的反转校验会让它 fail-closed 到代码,
  所以**新导航会立即在页面上生效**(不再被旧行遮蔽),但后台那一行要改需
  `npm run db:seed`(生产为独立授权动作)。seed.ts:945 直接引用 NAVIGATION_V2,
  重跑即得新行 —— 本地已复跑验证过(库内 mainNav 已是 industries/capabilities/insights)。

门禁实测:type-check EXIT=0 · 全量 jest 146 套件 / 1807 例通过 ·
eslint --quiet 改动文件 0 error · check:grammar 9/9 及其 selftest 9/9 ·
check:token-twins 44/44 · check:contrast 44/44 · check:brand-token 0 违规 ·
e2e nav-keyboard@chromium 6 passed(含 /insights 实测 HTTP 200)
This commit is contained in:
zhangxiang committed 2026-10-16 20:34:34 +08:00
1 parent e9bd965411
commit 7d1a22a596
23 files changed
+1083 -197

No files matched your search

+20 -5
View File
@@ -9,12 +9,20 @@ import { expectHydrated } from './hydrated';
const NAV_SELECTOR = 'nav[aria-label="主导航"]';
// 2026-10-16:原用例把触发器标签硬编码成「产品」。决策 2 把产品退出一级导航后
// 那个按钮不存在 ⇒ 4 条键盘用例集体判红。改用「行业」(行业轴的下拉面板是 /solutions/*,
// 与导航项自身 href 同前缀,最能顺带验证「查看全部」与面板内容同源)。
// ⚠ 标签与面板 href 前缀必须成对改:只改标签不改 href 断言,
// 「Tab 焦点进入面板链接」那条会退化成断言一个面板里不存在的选择器。
const DROPDOWN_LABEL = '行业';
const PANEL_HREF_PREFIX = '/solutions/';
function productTrigger(page: Page) {
return page.getByRole('navigation', { name: '主导航' }).getByRole('button', { name: '产品', exact: true });
return page.getByRole('navigation', { name: '主导航' }).getByRole('button', { name: DROPDOWN_LABEL, exact: true });
}
function viewAllLink(page: Page) {
return page.getByRole('link', { name: '查看全部产品' });
return page.getByRole('link', { name: `查看全部${DROPDOWN_LABEL}` });
}
async function openWithKeyboard(page: Page) {
@@ -57,6 +65,7 @@ test.describe('主导航下拉的键盘可操作性', { tag: '@a11y' }, () => {
// 焦点顺序实测(chromium + firefox,:3120 生产产物与 dev 目标读数一致):
// 第 1 站「跳转到主要内容」跳转链接,第 2 站 logo「返回首页」,第 3 站才是本触发器。
// (双轴改名后一级导航只剩 4 项,前三站的顺序不变,故 Tab 次数仍为 3)
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
@@ -71,7 +80,7 @@ test.describe('主导航下拉的键盘可操作性', { tag: '@a11y' }, () => {
test.skip(browserName === 'webkit', 'WebKit 本机不响应真实 Tab 键(N-27,见上方注释)');
await openWithKeyboard(page);
await page.keyboard.press('Tab');
await expect(page.locator(`${NAV_SELECTOR} a[href^="/products/"]:focus`)).toHaveCount(1);
await expect(page.locator(`${NAV_SELECTOR} a[href^="${PANEL_HREF_PREFIX}"]:focus`)).toHaveCount(1);
});
test('Escape 关闭面板并把焦点还给触发器', async ({ page }) => {
@@ -98,9 +107,15 @@ test.describe('主导航下拉的键盘可操作性', { tag: '@a11y' }, () => {
// 修法是把导航项自身 href 传进去(props.viewAllHref)。
// 下面这条是它的**浏览器层负对照**:单测已锁住组件契约,但「header 有没有真的把 href 传下来」
// 只有在真实渲染里才看得见 —— 少传一个 prop,单测全绿而线上静默退化。
// 2026-10-16 双轴改名后的预期表。
// ⚠ 这张表是**故意硬编码**的:它同时是「导航标签」「下拉存在」与「查看全部落点」三件事的
// 交叉对账。测试里另有一条 `expect(count).toBe(Object.keys(...).length)`,
// 所以新增一个带下拉的导航项而忘了登记 ⇒ 分母守卫判红,不会"少测一个"静默放行。
// 「产品」不再是下拉项(决策 2:产品退出一级导航),它的矩阵活在能力轴里。
const VIEW_ALL_EXPECTED: Record<string, string> = {
产品: '/products',
解决方案: '/solutions',
行业: '/solutions',
能力: '/services',
洞察: '/insights',
};
test.describe('主导航「查看全部」的目的地', { tag: '@a11y' }, () => {
+6 -3
View File
@@ -36,9 +36,12 @@ async function closeCookieBanner(page: Page) {
/**
* 从桌面主导航的产品下拉菜单中导航到指定链接
*/
async function navigateFromProductDropdown(page: Page, linkText: string) {
// 2026-10-16 改名并泛化:一级导航不再有「产品」(决策 2),/products 的入口降级为
// 能力轴第二层的「产品矩阵总览」。原来的 helper 硬编码 button:has-text("产品"),
// 改名后它会稳定判红 —— 这是**好事**:它证明这条旅程真的在走导航,而不是在假装。
async function navigateFromDropdown(page: Page, dropdownLabel: string, linkText: string) {
const desktopNav = page.locator('[data-testid="desktop-navigation"]').first();
const productDropdown = desktopNav.locator('button:has-text("产品")').first();
const productDropdown = desktopNav.locator(`button:has-text("${dropdownLabel}")`).first();
await expect(productDropdown).toBeVisible({ timeout: 5000 });
await productDropdown.hover();
await page.waitForTimeout(300);
@@ -71,7 +74,7 @@ test.describe('UJ-01: 潜在客户从首页到联系表单的完整旅程', () =
await expect(heroDescription).toBeVisible();
// === Step 2: 通过导航下拉菜单进入产品页面 ===
await navigateFromProductDropdown(page, '查看全部产品');
await navigateFromDropdown(page, '能力', '产品矩阵总览');
// === Step 3: 验证产品页面加载成功 ===
await page.waitForURL(/\/products/, { timeout: 10000 });
+2
View File
@@ -25,6 +25,8 @@ const PAGES = [
{ path: "/services", name: "服务列表" },
{ path: "/services/software", name: "服务详情-软件开发" },
{ path: "/news", name: "新闻列表" },
// 双轴新增的洞察枢纽 —— 不登记就会出现「新页面没人扫,门禁仍然绿」的静默覆盖收缩
{ path: "/insights", name: "洞察枢纽" },
{ path: "/contact", name: "联系我们" },
];
@@ -0,0 +1,59 @@
/**
* 洞察枢纽的两条诚实性约束(都能失败,不是给实现打气):
* 1. 筛选器只列**真的有内容**的分类 —— 本仓此前把 案例(0 行) 挂在一级导航上,
* 这条就是防它在新页面上重演。
* 2. 0 条目必须落在"看得见的空态",而不是渲染一个空网格装作有内容。
*/
import { describe, it, expect, jest } from '@jest/globals';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import InsightsContent, { type InsightEntry } from './insights-content';
jest.mock('@/components/ui/static-link', () => ({
StaticLink: ({ children, href, ...rest }: { children: React.ReactNode; href: string; [k: string]: unknown }) => (
<a href={href} {...rest}>{children}</a>
),
}));
jest.mock('@/components/ui/scroll-reveal', () => ({
ScrollReveal: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
StaggerReveal: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
jest.mock('@/components/ui/cta-button', () => ({
CTAButton: ({ children, href }: { children: React.ReactNode; href: string }) => (
<a href={href}>{children}</a>
),
}));
const METH: InsightEntry = { id: 'm1', kind: 'methodology', title: '四步诊断法', excerpt: '从业务目标出发', date: '', href: '/methodology' };
const WRITING: InsightEntry = { id: 'w1', kind: 'writing', title: '私有化部署', excerpt: '数据主权', date: '2026-08', href: '/news/1' };
describe('洞察筛选器的分母纪律', () => {
it('案例 0 行时,「客户成果」这个 tab 不允许出现', () => {
render(<InsightsContent entries={[METH, WRITING]} />);
expect(screen.queryByRole('tab', { name: '客户成果' })).not.toBeInTheDocument();
expect(screen.getByRole('tab', { name: '方法论' })).toBeInTheDocument();
expect(screen.getByRole('tab', { name: '技术与观点' })).toBeInTheDocument();
});
it('case-study 一旦出数,「客户成果」tab 自动出现(插槽真的能插,不是空话)', () => {
const real: InsightEntry = {
id: 'c1', kind: 'case', title: '某制造企业库存周转', excerpt: '', date: '2026-09',
href: '/cases/x', industry: '制造业',
};
render(<InsightsContent entries={[METH, WRITING, real]} />);
expect(screen.getByRole('tab', { name: '客户成果' })).toBeInTheDocument();
});
it('完全无内容 ⇒ 走空态而不是空网格', () => {
render(<InsightsContent entries={[]} />);
expect(screen.getByTestId('insights-empty')).toBeInTheDocument();
expect(screen.queryAllByTestId(/^insight-card-/)).toHaveLength(0);
});
it('点「方法论」后只留方法论条目(过滤真的生效,不是只改了按钮态)', () => {
render(<InsightsContent entries={[METH, WRITING]} />);
fireEvent.click(screen.getByRole('tab', { name: '方法论' }));
expect(screen.getAllByTestId('insight-card-methodology')).toHaveLength(1);
expect(screen.queryAllByTestId('insight-card-writing')).toHaveLength(0);
});
});
@@ -0,0 +1,177 @@
'use client';
import { useMemo, useState } from 'react';
import { StaticLink } from '@/components/ui/static-link';
import { ScrollReveal } from '@/components/ui/scroll-reveal';
import { CTAButton } from '@/components/ui/cta-button';
import { COMPANY_INFO } from '@/lib/constants';
import { cn } from '@/lib/utils';
import { ArrowRight } from 'lucide-react';
export type InsightKind = 'methodology' | 'case' | 'writing';
export interface InsightEntry {
id: string;
kind: InsightKind;
title: string;
excerpt: string;
/** ISO 或 'YYYY-MM';方法论这类"页面型"条目没有日期,留空 */
date: string;
href: string;
industry?: string;
}
const KIND_LABEL: Record<InsightKind, string> = {
methodology: '方法论',
case: '客户成果',
writing: '技术与观点',
};
/**
* 洞察枢纽 —— 对标 Bain「Our Latest Insights」/ Porsche「In Focus: News & Trends」。
*
* 语法取自实测:零圆角(bain-card 现 --radius-lg = 2px)、近单色、
* 卡片 hover 只改边框与底色(不抬升、不加阴影),成果类数字本轮不出现——
* 因为 case-study 模型是 0 行,任何数字都得编。
*
* 诚实性约束(可失败,见 insights-content.test.tsx):
* 1. 筛选器只列**真的有内容**的 kind。案例 0 行 ⇒ 不给「客户成果」这个 tab,
* 否则就是挂一个点开为空的频道(本仓此前 /cases 正是这样挂在一级导航上的)。
* 2. 0 条目时的空态必须是"看得见的空态",不拿模板文案冒充内容。
*/
export default function InsightsContent({ entries }: { entries: InsightEntry[] }) {
const presentKinds = useMemo(
() => (['methodology', 'case', 'writing'] as InsightKind[]).filter((k) => entries.some((e) => e.kind === k)),
[entries],
);
const [active, setActive] = useState<'all' | InsightKind>('all');
const visible = active === 'all' ? entries : entries.filter((e) => e.kind === active);
return (
<div data-testid="insights-page">
{/* L1 —— 结论式主张,不是口号 */}
<section className="bg-bg-primary border-b border-border-primary" data-testid="hero-section">
<div className="container-x py-16 md:py-24">
<ScrollReveal>
<p className="text-sm font-medium text-brand-ink tracking-wider mb-4">洞察</p>
<h1 className="text-4xl md:text-5xl font-bold text-text-primary leading-tight max-w-4xl">
我们怎么判断、怎么交付、怎么验收
</h1>
<p className="mt-5 text-base md:text-lg text-text-secondary leading-relaxed max-w-3xl">
{COMPANY_INFO.displayName}的公开写作与方法论。凡涉及效果的数字,都会标明它是
<strong className="font-medium text-text-primary">目标口径</strong>、
<strong className="font-medium text-text-primary">团队历史</strong>还是
<strong className="font-medium text-text-primary">已验证结果</strong>。
</p>
</ScrollReveal>
</div>
</section>
{/* 列表 */}
<section className="bg-bg-secondary" data-testid="insights-list">
<div className="container-x py-16 md:py-20">
<div className="flex flex-wrap items-center justify-between gap-4 mb-8">
<h2 className="text-2xl font-bold text-text-primary">全部内容</h2>
{/* 筛选器只列有内容的 kind:这是「不给空频道挂入口」那条约束的实现处 */}
<div className="flex flex-wrap gap-1" role="tablist" aria-label="洞察分类">
<FilterTab label="全部" activeState={active === 'all'} onClick={() => setActive('all')} />
{presentKinds.map((k) => (
<FilterTab
key={k}
label={KIND_LABEL[k]}
activeState={active === k}
onClick={() => setActive(k)}
/>
))}
</div>
</div>
{visible.length === 0 ? (
/* 空态必须是"看得见的空态" —— 不拿模板文案冒充内容 */
<div className="bain-card p-10 text-center" data-testid="insights-empty">
<p className="text-text-secondary leading-relaxed">
这一类目前还没有已发布的内容。
<br />
客户成果要等真实项目获得对外授权后才会出现在这里。
</p>
</div>
) : (
<ul className="grid gap-4 md:grid-cols-2 lg:grid-cols-3 list-none p-0 m-0">
{visible.map((entry) => (
<li key={entry.id}>
<StaticLink
href={entry.href}
className="bain-card block p-6 h-full transition-colors duration-hover hover:border-border-rule"
data-testid={`insight-card-${entry.kind}`}
>
<div className="flex items-center gap-2 mb-3">
<span className="text-xs font-medium text-brand-ink">{KIND_LABEL[entry.kind]}</span>
{entry.industry && (
<span className="text-xs text-text-muted">· {entry.industry}</span>
)}
{entry.date && (
<span className="ml-auto text-xs text-text-muted tabular-nums">{entry.date}</span>
)}
</div>
<h3 className="text-lg font-semibold text-text-primary leading-snug">{entry.title}</h3>
{entry.excerpt && (
<p className="mt-2 text-sm text-text-secondary leading-relaxed">{entry.excerpt}</p>
)}
<span className="mt-4 inline-flex items-center gap-1 text-sm font-medium text-text-primary group-hover:text-brand-ink">
阅读
<ArrowRight className="w-4 h-4" aria-hidden="true" />
</span>
</StaticLink>
</li>
))}
</ul>
)}
</div>
</section>
{/* L4 CTA */}
<section className="bg-bg-primary border-t border-border-primary">
<div className="container-x py-16 text-center">
<h2 className="text-2xl md:text-3xl font-bold text-text-primary">有具体场景想聊?</h2>
<p className="mt-3 text-text-secondary max-w-2xl mx-auto leading-relaxed">
把你的问题带来,我们先给判断,再谈方案。
</p>
<div className="mt-8 flex flex-wrap items-center justify-center gap-4">
<CTAButton href="/contact">预约咨询</CTAButton>
<CTAButton href="/services" variant="secondary">
查看能力组
</CTAButton>
</div>
</div>
</section>
</div>
);
}
function FilterTab({
label,
activeState,
onClick,
}: {
label: string;
activeState: boolean;
onClick: () => void;
}) {
return (
<button
type="button"
role="tab"
aria-selected={activeState}
onClick={onClick}
className={cn(
'px-4 py-2 text-sm font-medium transition-colors duration-hover min-h-[44px]',
activeState
? 'bg-brand text-white'
: 'bg-bg-primary text-text-secondary border border-border-primary hover:text-text-primary',
)}
>
{label}
</button>
);
}
+75
View File
@@ -0,0 +1,75 @@
import { Metadata } from 'next';
import { COMPANY_INFO } from '@/lib/constants';
import { getPublishedItems } from '@/lib/cms/data-server';
import type { NewsItem } from '@/lib/constants/news';
import InsightsContent, { type InsightEntry } from './insights-content';
export const metadata: Metadata = {
title: `洞察 - ${COMPANY_INFO.displayName}`,
description: `${COMPANY_INFO.displayName}的方法论、技术与观点:数字化转型怎么判断、怎么交付、怎么验收。`,
};
// ISR 与 /news 同档;CMS 发布经 /api/cms/revalidate 主动刷新。
// ⚠ 新路由必须同步进 revalidate 的路径表与 check:headings 的 PAGES,
// 否则「全站扫描」的分母会静默变小而门禁仍然绿。
export const revalidate = 3600;
/** 洞察条目 kind:news 分类沿用既有 taxonomy,方法论与案例是另外两路真源 */
async function buildEntries(): Promise<InsightEntry[]> {
const [newsItems, caseItems, methodologyItems] = await Promise.all([
getPublishedItems('news').catch(() => []),
getPublishedItems('case-study').catch(() => []),
getPublishedItems('methodology').catch(() => []),
]);
const news: InsightEntry[] = newsItems.map((item) => {
const data = item.data as unknown as NewsItem;
return {
id: `news-${data.id || item.slug}`,
kind: 'writing' as const,
title: data.title || item.title,
excerpt: data.excerpt || '',
date: data.date || '',
href: `/news/${data.id || item.slug}`,
};
});
// 方法论:/methodology 是一个 4 阶段的页面型模型(1 行),不是逐篇内容
const methodology: InsightEntry[] = methodologyItems.map((item) => {
const data = item.data as { title?: string; description?: string; summary?: string };
return {
id: `methodology-${item.slug}`,
kind: 'methodology' as const,
title: data.title || item.title,
excerpt: data.description || data.summary || '',
date: '',
href: '/methodology',
};
});
/**
* 案例:**当前恒为空数组**,因为 case-study 模型 0 行
* (prisma/seeds/case-studies.ts:11 明示「首批客户共创阶段,暂无对外可验证的客户案例」)。
* 零编造原则下这里不造任何条目;真实授权案例落库的当天,下面的 map 就开始出数,
* 前端不需要再改一行 —— 这就是「留结构化插槽」的实际含义。
*/
const cases: InsightEntry[] = caseItems.map((item) => {
const data = item.data as { title?: string; excerpt?: string; industry?: string; publishedAt?: string };
return {
id: `case-${item.slug}`,
kind: 'case' as const,
title: data.title || item.title,
excerpt: data.excerpt || '',
date: data.publishedAt || '',
industry: data.industry,
href: `/cases/${item.slug}`,
};
});
return [...methodology, ...cases, ...news].sort((a, b) => (b.date || '').localeCompare(a.date || ''));
}
export default async function InsightsPage() {
const entries = await buildEntries();
return <InsightsContent entries={entries} />;
}
+31
View File
@@ -287,3 +287,34 @@ describe('POST /api/cms/revalidate', () => {
expect(body.data.revalidatedPaths).toContain('/products/erp-upgrade');
});
});
// ── 洞察枢纽的失效映射(2026-10-16 双轴改造新增路由)──────────────────────
// /insights 不在 CONTENT_TYPE_CONFIGS 的任何 listPage 里 ⇒ 通用推导只会刷 /news、
// /methodology。少登记这一条的后果不是报错,而是**后台发了新内容、洞察页仍端出旧
// ISR 快照,最长 1 小时,且没有任何门禁会红**。所以正反两向都要钉住。
describe('POST /api/cms/revalidate —— /insights 失效映射', () => {
it.each(['news', 'case-study', 'methodology'])(
'%s 变更必须同时刷 /insights',
async (modelCode) => {
const response = await POST(createMockRequest({ modelCode }));
const body = await response.json();
expect(response.status).toBe(200);
expect(mockRevalidatePath).toHaveBeenCalledWith('/insights');
expect(body.data.revalidatedPaths).toContain('/insights');
},
);
// 负对照:映射不能宽到「什么都刷」——那会让这条断言恒真、失去约束力
it('product 变更不该刷 /insights(洞察轴不读 product 模型)', async () => {
const response = await POST(createMockRequest({ modelCode: 'product', slug: 'erp' }));
expect(response.status).toBe(200);
expect(mockRevalidatePath).not.toHaveBeenCalledWith('/insights');
});
it('同一 modelCode 重复调用只刷一次 /insights(去重仍成立)', async () => {
await POST(createMockRequest({ modelCode: 'news', slug: 'a' }));
const calls = mockRevalidatePath.mock.calls.filter((c) => c[0] === '/insights');
expect(calls).toHaveLength(1);
});
});
+15
View File
@@ -20,6 +20,12 @@ const HOME_AFFECTED_MODELS = new Set([
'news',
]);
// 洞察枢纽 /insights 的数据来自三路真源:news(技术与观点)、case-study(客户成果,当前 0 行)、
// methodology(方法论)。它**不在** CONTENT_TYPE_CONFIGS 的任何 listPage 里 ——
// 通用推导只会刷 /news、/methodology,于是后台发了新内容而 /insights 仍端出旧 ISR 快照,
// 最长 1 小时不可见,且没有任何门禁会红。新路由必须显式登记失效映射。
const INSIGHTS_AFFECTED_MODELS = new Set(['news', 'case-study', 'methodology']);
interface RevalidateRequestBody {
event?: string;
modelCode?: string;
@@ -122,6 +128,15 @@ export async function POST(request: NextRequest) {
revalidatedPaths.push('/products/erp-upgrade');
}
// 洞察枢纽:三个上游模型任一变更都要刷 /insights
if (
INSIGHTS_AFFECTED_MODELS.has(body.modelCode) &&
!revalidatedPaths.includes('/insights')
) {
revalidatePath('/insights');
revalidatedPaths.push('/insights');
}
// 首页相关模型变更时同步刷新 /
if (HOME_AFFECTED_MODELS.has(body.modelCode) && !revalidatedPaths.includes('/')) {
revalidatePath('/');
+14 -17
View File
@@ -16,9 +16,9 @@ import { MotionProvider } from "@/components/ui/motion-provider";
import { BackToTop } from "@/components/ui/back-to-top";
import { ClientLayout } from "@/components/layout/client-layout";
import { getPublishedItems } from "@/lib/cms/data-server";
import { SiteConfigProvider, type SiteConfig, type NavigationItem, type MegaDropdownGroup, type MegaDropdownItem } from "@/lib/site-config";
import { SiteConfigProvider, type SiteConfig, type NavigationItem, type MegaDropdownItem } from "@/lib/site-config";
import { COMPANY_INFO, BRAND_NARRATIVE, type BrandPillar } from "@/lib/constants/company";
import { NAVIGATION_V2, MEGA_DROPDOWN_DATA } from "@/lib/constants/navigation";
import { resolveNavigation, injectStandaloneProducts } from "@/lib/navigation-resolution";
/**
* 拉丁字形使用 Geist(本地 woff2,无网络请求);
@@ -127,21 +127,18 @@ export default async function RootLayout({
};
});
// Build megaDropdown with standalone products dynamically injected
const baseMegaDropdown = (navData?.megaDropdown as Record<string, MegaDropdownGroup[]>) || MEGA_DROPDOWN_DATA;
const megaDropdown: Record<string, MegaDropdownGroup[]> = {};
for (const [key, groups] of Object.entries(baseMegaDropdown)) {
if (key === 'products' && standaloneNavItems.length > 0) {
megaDropdown[key] = groups.map((group) => {
if (group.id === 'standalone-products') {
return { ...group, description: undefined, items: standaloneNavItems };
}
return group;
});
} else {
megaDropdown[key] = groups;
}
// 导航解析:**代码为真源,CMS 仅在完整自洽时覆盖**。
// 原写法是 `(navData?.mainNav as ...) || NAVIGATION_V2` —— DB 行胜出、代码只兜底,
// 于是「只改 navigation.ts 会上线一个生产静默忽略它的新导航」。详见 lib/navigation-resolution.ts。
const nav = resolveNavigation(navData);
if (nav.issues.length > 0) {
// 渲染期不写库(Notification 是后台数据,在 RSC 里写它等于给每次首页渲染挂写副作用),
// 但「为什么没用后台配置」必须可见,否则 fail-closed 会被读成"后台改了没反应"的玄学。
console.warn('[navigation] 退回代码真源:\n ' + nav.issues.join('\n '));
}
// 独立产品按**组 id** 注入(原实现按 key==='products' 匹配,双轴改名后该 key 已不存在,
// 沿用会静默丢失这一组:面板照样渲染,只是少了它)。
const megaDropdown = injectStandaloneProducts(nav.megaDropdown, standaloneNavItems);
const siteConfig: SiteConfig = {
name: (configData?.name as string) || COMPANY_INFO.name,
@@ -160,7 +157,7 @@ export default async function RootLayout({
address: (configData?.address as string) || COMPANY_INFO.address,
icp: (configData?.icp as string) || COMPANY_INFO.icp,
police: (configData?.police as string) || COMPANY_INFO.police,
mainNav: (navData?.mainNav as NavigationItem[]) || NAVIGATION_V2,
mainNav: nav.mainNav as unknown as NavigationItem[],
megaDropdown,
};
+3
View File
@@ -17,6 +17,9 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
// 案例列表页:数据库 case-study 暂无已发布内容,空列表页不收录(页面保留,待产品补数据后恢复)。
// { url: `${BASE_URL}/cases`, lastModified: new Date(), changeFrequency: 'weekly', priority: 0.8 },
{ url: `${BASE_URL}/news`, lastModified: new Date(), changeFrequency: 'daily', priority: 0.7 },
// 洞察枢纽(双轴改造新增):聚合 news + methodology + case-study。
// /news 暂留(已被索引、且 2 条内容仍在贡献长尾),第二批用 301 归并 —— 见计划 §11 待拍 #3。
{ url: `${BASE_URL}/insights`, lastModified: new Date(), changeFrequency: 'daily', priority: 0.8 },
{ url: `${BASE_URL}/team`, lastModified: new Date(), changeFrequency: 'monthly', priority: 0.6 },
{ url: `${BASE_URL}/methodology`, lastModified: new Date(), changeFrequency: 'monthly', priority: 0.6 },
{ url: `${BASE_URL}/contact`, lastModified: new Date(), changeFrequency: 'monthly', priority: 0.7 },
+33 -21
View File
@@ -43,35 +43,40 @@ jest.mock('@/lib/site-config', () => ({
icp: '蜀ICP备XXXXXXXX号',
police: '川公网安备XXXXXXXXXXX号',
megaDropdown: {
products: [
industries: [
{
id: 'group1',
title: '企业套装',
items: [
{ id: 'erp', title: 'ERP 管理系统', description: '财务·采购·销售·库存·生产', href: '/products/erp' },
{ id: 'crm', title: 'CRM 客户管理', description: '线索·商机·合同·服务', href: '/products/crm' },
],
},
],
solutions: [
{
id: 'group1',
title: '行业解决方案',
id: 'industry-solutions',
title: '行业实践',
items: [
{ id: 'manufacturing', title: '制造业', description: '智能制造·MES·质量管控', href: '/solutions/manufacturing' },
{ id: 'retail', title: '零售业', description: '全渠道·会员·精准营销', href: '/solutions/retail' },
],
},
],
services: [
capabilities: [
{
id: 'professional-services',
title: '专业服务',
id: 'capability-groups',
title: '能力组',
items: [
{ id: 'consulting', title: '战略咨询', description: '数字化转型咨询规划', href: '/services/consulting' },
{ id: 'software', title: '企业软件', description: 'ERP/CRM/BI 系统实施', href: '/services/software' },
],
},
{
id: 'enterprise-suite',
title: '产品矩阵',
items: [
{ id: 'erp', title: 'ERP 管理系统', description: '财务·采购·销售·库存·生产', href: '/products/erp' },
{ id: 'crm', title: 'CRM 客户管理', description: '线索·商机·合同·服务', href: '/products/crm' },
],
},
],
insights: [
{
id: 'insight-groups',
title: '洞察',
items: [{ id: 'all', title: '全部洞察', description: '', href: '/insights' }],
},
],
},
}),
@@ -90,6 +95,8 @@ jest.mock('@/lib/constants', () => ({
icp: '蜀ICP备XXXXXXXX号',
police: '川公网安备XXXXXXXXXXX号',
},
MEGA_KEYS: { industries: 'industries', capabilities: 'capabilities', insights: 'insights' },
STANDALONE_GROUP_ID: 'standalone-products',
MEGA_DROPDOWN_DATA: {
products: [
{
@@ -140,12 +147,12 @@ describe('Footer', () => {
it('should render products section', () => {
render(<Footer />);
expect(screen.getByText('产品')).toBeInTheDocument();
expect(screen.getByText('产品矩阵')).toBeInTheDocument();
});
it('should render solutions section', () => {
render(<Footer />);
expect(screen.getByText('解决方案')).toBeInTheDocument();
expect(screen.getByText('行业')).toBeInTheDocument();
});
it('should render contact information section', () => {
@@ -168,7 +175,7 @@ describe('Footer', () => {
it('should render services column from megaDropdown.services (P3 footer)', () => {
render(<Footer />);
expect(screen.getByTestId('card-services')).toBeInTheDocument();
expect(screen.getByText('服务', { exact: true })).toBeInTheDocument();
expect(screen.getByText('能力', { exact: true })).toBeInTheDocument();
expect(screen.getByText('战略咨询')).toBeInTheDocument();
expect(screen.getByText('企业软件')).toBeInTheDocument();
});
@@ -180,8 +187,13 @@ describe('Footer', () => {
expect(screen.getByText('公司', { exact: true })).toBeInTheDocument();
expect(screen.getByText('关于我们').closest('a')).toHaveAttribute('href', '/about');
expect(screen.getByText('方法论').closest('a')).toHaveAttribute('href', '/methodology');
expect(screen.getByText('案例').closest('a')).toHaveAttribute('href', '/cases');
expect(screen.getByText('新闻动态').closest('a')).toHaveAttribute('href', '/news');
// 案例(0 行)与新闻动态(已并入洞察)两个空渠道入口已撤下;换成品牌故事与洞察。
// ⚠ 断言「不存在」必须用 queryByText —— getByText 找不到时直接抛,
// 那会让后面几行根本执行不到,看起来像通过了其实什么都没测。
expect(screen.queryByText('案例')).not.toBeInTheDocument();
expect(screen.queryByText('新闻动态')).not.toBeInTheDocument();
expect(screen.getByText('洞察').closest('a')).toHaveAttribute('href', '/insights');
expect(screen.getByText('品牌故事').closest('a')).toHaveAttribute('href', '/about/brand');
});
it('should render contact details', () => {
+32 -18
View File
@@ -4,28 +4,42 @@ import { StaticLink } from '@/components/ui/static-link';
import Image from 'next/image';
import { Mail, MapPin } from 'lucide-react';
import { useSiteConfig } from '@/lib/site-config';
import { MEGA_KEYS } from '@/lib/constants/navigation';
// 公司栏目为固定信息架构,路由均已验证存在(/about · /methodology · /cases · /news),与 NAVIGATION_V2 对齐。
// 公司栏目为固定信息架构,路由均已验证存在,与 NAVIGATION_V2(行业 × 能力 双轴)对齐。
// ⚠ 2026-10-16 撤掉两个入口:**案例**(case-study 模型 0 行,prisma/seeds/case-studies.ts:11
// 明示「首批客户共创阶段,暂无对外可验证案例」)与**新闻动态**(仅 2 行,已并入「洞察」)。
// 对标两家(Bain Insights / Porsche 洞察)都不挂一个没有内容的频道。
// /cases 路由与 case-study 模型**保留休眠**,真实授权案例到位当天即可渲染,不必二次迁移。
const COMPANY_LINKS: ReadonlyArray<{ id: string; label: string; href: string }> = [
{ id: 'about', label: '关于我们', href: '/about' },
{ id: 'brand', label: '品牌故事', href: '/about/brand' },
{ id: 'methodology', label: '方法论', href: '/methodology' },
{ id: 'cases', label: '案例', href: '/cases' },
{ id: 'news', label: '新闻动态', href: '/news' },
{ id: 'insights', label: '洞察', href: '/insights' },
];
export function Footer() {
const config = useSiteConfig();
const productItems = (config.megaDropdown.products ?? [])
.flatMap(group => group.items)
.filter(item => item.href !== '#');
// ⚠ 这三处 key 必须与 src/lib/constants/navigation.ts 的 MEGA_KEYS 同步。
// 旧写法读 products/solutions/services;双轴改名后那些 key 已不存在,
// 不同步改这里就会让页脚栏目**静默变空** —— 页脚照样渲染,只是没链接。
// data-testid 保持原值(card-products / card-solutions / card-services):
// 它们是测试与视觉基线的锚点,不是用户可见文案,改它们只会无谓放大改动半径。
const capabilityItems = (config.megaDropdown[MEGA_KEYS.capabilities] ?? [])
.filter((group) => group.id === 'capability-groups')
.flatMap((group) => group.items)
.filter((item) => item.href !== '#');
const solutionItems = (config.megaDropdown.solutions ?? [])
.flatMap(group => group.items)
.filter(item => item.href !== '#');
const industryItems = (config.megaDropdown[MEGA_KEYS.industries] ?? [])
.flatMap((group) => group.items)
.filter((item) => item.href !== '#');
const serviceItems = (config.megaDropdown.services ?? [])
.flatMap(group => group.items)
.filter(item => item.href !== '#');
// 产品矩阵:能力轴里「用什么交付」那一组,仍在页脚保留入口(页脚是 sitemap 区,
// 与一级导航「不以产品为轴」是两件事 —— Bain/Porsche 的页脚也都罗列全部资产)
const productItems = (config.megaDropdown[MEGA_KEYS.capabilities] ?? [])
.filter((group) => group.id !== 'capability-groups')
.flatMap((group) => group.items)
.filter((item) => item.href !== '#');
return (
<footer className="bg-dark-bg text-dark-text-primary relative overflow-hidden [&_a]:inline-flex [&_a]:items-center [&_a]:min-h-6" data-testid="footer" role="contentinfo">
@@ -102,7 +116,7 @@ export function Footer() {
</div>
<div data-testid="card-products" className="lg:col-span-2">
<div className="font-semibold text-sm mb-5 text-dark-text-primary tracking-widest uppercase">产品</div>
<div className="font-semibold text-sm mb-5 text-dark-text-primary tracking-widest uppercase">产品矩阵</div>
<ul className="space-y-3 [&_li]:p-0 [&_li]:m-0 [&_li]:static [&_li::before]:hidden">
{productItems.map((item) => (
<li key={item.id}>
@@ -118,9 +132,9 @@ export function Footer() {
</div>
<div data-testid="card-solutions" className="lg:col-span-2">
<div className="font-semibold text-sm mb-5 text-dark-text-primary tracking-widest uppercase">解决方案</div>
<div className="font-semibold text-sm mb-5 text-dark-text-primary tracking-widest uppercase">行业</div>
<ul className="space-y-3 [&_li]:p-0 [&_li]:m-0 [&_li]:static [&_li::before]:hidden">
{solutionItems.map((item) => (
{industryItems.map((item) => (
<li key={item.id}>
<StaticLink
href={item.href}
@@ -133,11 +147,11 @@ export function Footer() {
</ul>
</div>
{serviceItems.length > 0 && (
{capabilityItems.length > 0 && (
<div data-testid="card-services" className="lg:col-span-2">
<div className="font-semibold text-sm mb-5 text-dark-text-primary tracking-widest uppercase">服务</div>
<div className="font-semibold text-sm mb-5 text-dark-text-primary tracking-widest uppercase">能力</div>
<ul className="space-y-3 [&_li]:p-0 [&_li]:m-0 [&_li]:static [&_li::before]:hidden">
{serviceItems.map((item) => (
{capabilityItems.map((item) => (
<li key={item.id}>
<StaticLink
href={item.href}
+8 -21
View File
@@ -8,6 +8,7 @@ import { Menu, X, MessageCircle } from 'lucide-react';
import { AnimatePresence, motion } from 'framer-motion';
import { Button } from '@/components/ui/button';
import { useSiteConfig, type NavigationItem } from '@/lib/site-config';
import { isNavItemActive } from '@/lib/nav-active';
import { MegaDropdown } from '@/components/layout/mega-dropdown';
import { useFocusTrap } from '@/hooks/use-focus-trap';
import { cn } from '@/lib/utils';
@@ -59,27 +60,13 @@ function HeaderContent() {
setIsOpen(false);
}, []);
const isActive = useCallback((item: NavigationItem) => {
if (item.id === 'contact') {
return pathname === '/contact';
}
if (item.id === 'home') {
return pathname === '/';
}
if (item.id === 'products') {
return pathname === '/products' || pathname.startsWith('/products/');
}
if (item.id === 'solutions') {
return pathname === '/solutions' || pathname.startsWith('/solutions/');
}
if (item.id === 'cases') {
return pathname === '/cases' || pathname.startsWith('/cases/');
}
if (item.id === 'services') {
return pathname === '/services' || pathname.startsWith('/services/');
}
return pathname === `/${item.id}`;
}, [pathname]);
// 激活判定唯一实现见 lib/nav-active.ts —— 原来是 8 个分支的 per-id `if` 阶梯,
// 末尾还落回 `pathname === `/${item.id}``:双轴改名后 id 变成 industries/insights,
// 于是「行业」永远点不亮(菜单照常渲染 = 绿但空洞)。
const isActive = useCallback(
(item: NavigationItem) => isNavItemActive(pathname, item.href),
[pathname],
);
return (
<>
+14 -10
View File
@@ -39,9 +39,9 @@ describe('MobileTabBar', () => {
it('should render all tabs', () => {
render(<MobileTabBar />);
expect(screen.getByText('首页')).toBeInTheDocument();
expect(screen.getByText('产品')).toBeInTheDocument();
expect(screen.getByText('方案')).toBeInTheDocument();
expect(screen.getByText('案例')).toBeInTheDocument();
expect(screen.getByText('能力')).toBeInTheDocument();
expect(screen.getByText('行业')).toBeInTheDocument();
expect(screen.getByText('洞察')).toBeInTheDocument();
expect(screen.getByText('联系')).toBeInTheDocument();
});
@@ -76,20 +76,24 @@ describe('MobileTabBar', () => {
it('should have correct href for solutions', () => {
render(<MobileTabBar />);
const solutionsLink = screen.getByText('方案').closest('a');
const solutionsLink = screen.getByText('行业').closest('a');
expect(solutionsLink).toHaveAttribute('href', '/solutions');
});
it('should have correct href for products', () => {
it('能力 tab 落在 /services(本轮换标签不换路由:能力轴读 service 模型)', () => {
render(<MobileTabBar />);
const productsLink = screen.getByText('产品').closest('a');
expect(productsLink).toHaveAttribute('href', '/products');
expect(screen.getByText('能力').closest('a')).toHaveAttribute('href', '/services');
});
it('should have correct href for cases', () => {
it('洞察 tab 落在 /insights,且「案例」常驻位已撤下(case-study 0 行)', () => {
render(<MobileTabBar />);
const casesLink = screen.getByText('案例').closest('a');
expect(casesLink).toHaveAttribute('href', '/cases');
expect(screen.getByText('洞察').closest('a')).toHaveAttribute('href', '/insights');
expect(screen.queryByText('案例')).not.toBeInTheDocument();
});
it('行业 tab 落在 /solutions', () => {
render(<MobileTabBar />);
expect(screen.getByText('行业').closest('a')).toHaveAttribute('href', '/solutions');
});
it('should have correct href for contact', () => {
+13 -24
View File
@@ -5,45 +5,34 @@ import { usePathname } from 'next/navigation';
import { Home, Lightbulb, Package, FolderOpen, User } from 'lucide-react';
import { motion } from 'framer-motion';
import { cn } from '@/lib/utils';
import { isNavItemActive } from '@/lib/nav-active';
// 关于页让位给案例页:转化路径上「看实证」优先于「看介绍」,
// 关于/新闻等仍可通过汉堡抽屉(header)到达。
// 2026-10-16 随一级导航改对标双轴(行业 × 能力 + 洞察),与 header 同源。
// ⚠ 撤掉「案例」tab:case-study 模型 0 行(prisma/seeds/case-studies.ts:11),
// 原来把它放在移动端第五个、也是唯一常驻的转化位上,点开是一个空列表 ——
// 移动端比桌面端更吃「点了没东西」的亏。路由 /cases 保留休眠,出数后回归。
const tabs = [
{ id: 'home', label: '首页', href: '/', icon: Home },
{ id: 'products', label: '产品', href: '/products', icon: Package },
{ id: 'solutions', label: '方案', href: '/solutions', icon: Lightbulb },
{ id: 'cases', label: '案例', href: '/cases', icon: FolderOpen },
{ id: 'industries', label: '行业', href: '/solutions', icon: Lightbulb },
{ id: 'capabilities', label: '能力', href: '/services', icon: Package },
{ id: 'insights', label: '洞察', href: '/insights', icon: FolderOpen },
{ id: 'contact', label: '联系', href: '/contact', icon: User },
];
export function MobileTabBar() {
const pathname = usePathname();
const isActive = (_href: string, id: string) => {
if (id === 'home') {
return pathname === '/';
}
if (id === 'contact') {
return pathname === '/contact';
}
if (id === 'products') {
return pathname === '/products' || pathname.startsWith('/products/');
}
if (id === 'solutions') {
return pathname === '/solutions' || pathname.startsWith('/solutions/');
}
if (id === 'cases') {
return pathname === '/cases' || pathname.startsWith('/cases/');
}
return false;
};
// 原实现是按 id 手写的 5 分支 `if` 阶梯,且 switch 在 **id** 上而不是 href:
// 改名后每一项都静默返回 false ⇒ tab bar 照常渲染、永不高亮(典型「绿但空洞」)。
// 现改用与 header 同一份 lib/nav-active.ts。
const isActive = (href: string) => isNavItemActive(pathname, href);
return (
<nav className="fixed bottom-0 left-0 right-0 z-50 md:hidden bg-bg-primary/95 backdrop-blur-xl border-t border-border-primary" style={{ paddingBottom: 'env(safe-area-inset-bottom, 0px)' }}>
<div className="flex items-center justify-around h-16">
{tabs.map((tab) => {
const Icon = tab.icon;
const active = isActive(tab.href, tab.id);
const active = isActive(tab.href);
return (
<StaticLink
+15 -22
View File
@@ -1,7 +1,7 @@
import { describe, it, expect } from '@jest/globals';
import {
COMPANY_INFO,
NAVIGATION,
NAVIGATION_V2,
STATS,
SERVICES,
PRODUCTS,
@@ -33,33 +33,26 @@ describe('Constants', () => {
});
});
describe('NAVIGATION', () => {
it('should be an array', () => {
expect(Array.isArray(NAVIGATION)).toBe(true);
});
it('should have navigation items', () => {
expect(NAVIGATION.length).toBeGreaterThan(0);
});
it('should have required properties', () => {
NAVIGATION.forEach(item => {
describe('NAVIGATION_V2', () => {
// 原 NAVIGATION(V1) 已删除:7 个 href 全是 '/',全站零生产引用,只被本测试断言
// (qa-tracker DEC-P-2 死码族)。留着测试只会让死码看起来"有人用"。
it('should be a non-empty array of usable destinations', () => {
expect(Array.isArray(NAVIGATION_V2)).toBe(true);
expect(NAVIGATION_V2.length).toBeGreaterThan(0);
NAVIGATION_V2.forEach((item) => {
expect(item).toHaveProperty('id');
expect(item).toHaveProperty('label');
expect(item).toHaveProperty('href');
// V1 的教训就是「看着是导航,点回去全是指向 / 的死链」⇒ 这里强制每个目标各不相同
expect(typeof item.href).toBe('string');
});
expect(new Set(NAVIGATION_V2.map((i) => i.href)).size).toBe(NAVIGATION_V2.length);
});
it('should have home navigation', () => {
const homeNav = NAVIGATION.find(item => item.id === 'home');
expect(homeNav).toBeDefined();
expect(homeNav?.label).toBe('首页');
});
it('should have contact navigation', () => {
const contactNav = NAVIGATION.find(item => item.id === 'contact');
expect(contactNav).toBeDefined();
expect(contactNav?.href).toBe('/contact');
it('一级导航按对标双轴组织,且不含产品入口', () => {
const labels = NAVIGATION_V2.map((i) => i.label);
expect(labels).toEqual(['行业', '能力', '洞察', '关于我们']);
expect(labels).not.toContain('产品');
});
});
+2 -2
View File
@@ -4,10 +4,10 @@ export {
type BrandPillar,
TRUST_SIGNALS,
EARLY_ACCESS,
NAVIGATION,
NAVIGATION_V2,
MEGA_DROPDOWN_DATA,
type NavigationItem,
MEGA_KEYS,
STANDALONE_GROUP_ID,
type NavigationItemV2,
type MegaDropdownItem,
type MegaDropdownData,
+2 -2
View File
@@ -1,7 +1,7 @@
export { COMPANY_INFO, BRAND_NARRATIVE, TRUST_SIGNALS, EARLY_ACCESS } from './company';
export type { BrandPillar } from './company';
export { NAVIGATION, NAVIGATION_V2, MEGA_DROPDOWN_DATA } from './navigation';
export type { NavigationItem, NavigationItemV2, MegaDropdownItem, MegaDropdownGroup, MegaDropdownData } from './navigation';
export { NAVIGATION_V2, MEGA_DROPDOWN_DATA, MEGA_KEYS, STANDALONE_GROUP_ID } from './navigation';
export type { NavigationItemV2, MegaDropdownItem, MegaDropdownGroup, MegaDropdownData } from './navigation';
export { STATS, type StatItem } from './stats';
export { SERVICES } from './services';
export { PRODUCTS, type Product } from './products';
+106 -52
View File
@@ -1,24 +1,37 @@
export interface NavigationItem {
id: string;
label: string;
href: string;
}
export const NAVIGATION: NavigationItem[] = [
{ id: 'home', label: '首页', href: '/' },
{ id: 'services', label: '核心业务', href: '/' },
{ id: 'solutions', label: '解决方案', href: '/' },
{ id: 'products', label: '产品服务', href: '/' },
{ id: 'about', label: '关于我们', href: '/' },
{ id: 'news', label: '新闻动态', href: '/' },
{ id: 'contact', label: '联系', href: '/contact' },
];
/**
* 主导航与 mega 下拉的**代码真源**。
*
* 2026-10-16 改对标双轴。依据是实测而非口味:
* - Bain 一级导航 = Industries · Consulting Services · Digital · Insights · About · Careers
* - Porsche Consulting = 行业 · 实践 · 洞察 · 职业 · 关于我们(+ 联系我们作 CTA)
* **两家的导航里都没有「产品」** —— 咨询业按「客户的问题空间(行业)× 本所的能力」组织,
* 不按产品 SKU 组织。本仓此前 7 项里 产品 居首,且 案例(0 条数据)、新闻动态(2 条) 是空渠道。
*
* 落地策略(本轮刻意保守,可整体回退):
* **换标签、不换路由**。行业→既有的 /solutions(solution 模型本就是行业)、
* 能力→既有的 /services(service 模型的 4 行本就是能力组)。
* 这样做的理由不是偷懒,而是避免制造重复内容:若新增 /capabilities 与 /services 并行,
* 同一个 ContentItem 会同时挂在两个 URL 下 —— 那是 canonical 冲突,比不改更糟。
* URL 改名 + 308 留给第二批一次性处理(须同批动 next.config redirects、@security、
* revalidate 路径表、sitemap、lighthouserc)。
* 唯一真正新增的面是 /insights:它聚合 news + methodology + cases,
* 今天没有任何单一页面做过这件事,因此不构成重复。
*
* 「轴 = 视图,模型 = 真源」不变式(写进 PRD):
* 一条路由可以 READ 或组合多个模型,但**不得 OWN** 另一个模型已持有实体的副本。
* 需要新分组时,表达为既有 item 上的字段或一个 ContentZone,
* 永远不是「装着同样 16 行的新 ContentModel」—— 后者会撞
* src/lib/seed-permissions.test.ts:50 的 SUPER_ADMIN_ONLY_MODELS 断言,
* 且授予只能靠重跑 seed(独立授权动作)。
*/
export interface NavigationItemV2 {
id: string;
label: string;
href: string;
hasDropdown?: boolean;
/** 指向 MEGA_DROPDOWN_DATA 的 key。⚠ 改名必须与 megaDropdown 的 key 同步,
* 否则 resolveNavigation 的校验会判该 CMS/代码配置不完整。 */
dropdownKey?: string;
}
@@ -42,46 +55,38 @@ export interface MegaDropdownData {
[key: string]: MegaDropdownGroup[];
}
/**
* 主导航 4 项 + 常驻 CTA(联系我们不在列表里 —— 它是 header.tsx 的咨询按钮;
* 两家对标也都把联系放在 utility 行 / CTA 位,而不是第六个阅读项)。
*/
export const NAVIGATION_V2: NavigationItemV2[] = [
{ id: 'products', label: '产品', href: '/products', hasDropdown: true, dropdownKey: 'products' },
{ id: 'solutions', label: '解决方案', href: '/solutions', hasDropdown: true, dropdownKey: 'solutions' },
{ id: 'services', label: '服务', href: '/services' },
{ id: 'cases', label: '案例', href: '/cases' },
{ id: 'news', label: '新闻动态', href: '/news' },
{ id: 'industries', label: '行业', href: '/solutions', hasDropdown: true, dropdownKey: 'industries' },
{ id: 'capabilities', label: '能力', href: '/services', hasDropdown: true, dropdownKey: 'capabilities' },
{ id: 'insights', label: '洞察', href: '/insights', hasDropdown: true, dropdownKey: 'insights' },
{ id: 'about', label: '关于我们', href: '/about' },
{ id: 'contact', label: '联系我们', href: '/contact' },
];
/** megaDropdown 的 key —— footer 按这些 key 取栏目,改名必须两侧同步 */
export const MEGA_KEYS = {
industries: 'industries',
capabilities: 'capabilities',
insights: 'insights',
} as const;
/**
* 产品矩阵所在的组 id —— **不要改这个 id**。
* src/app/layout.tsx 的 standalone 覆盖是按 `group.id === 'standalone-products'` 匹配的,
* 改了 id 会让 CMS 的独立产品静默不再注入(面板照样渲染,只是少了那一组)。
*/
export const STANDALONE_GROUP_ID = 'standalone-products';
export const MEGA_DROPDOWN_DATA: MegaDropdownData = {
products: [
{
id: 'enterprise-suite',
title: '企业套装',
description: '核心产品线,互为补充',
items: [
{ id: 'erp', title: 'ERP 管理系统', description: '财务·采购·销售·库存·生产', href: '/products/erp', badge: '旗舰' },
{ id: 'crm', title: 'CRM 客户管理', description: '线索·商机·合同·服务', href: '/products/crm', badge: '旗舰' },
{ id: 'bi', title: 'BI 数据平台', description: '报表·仪表盘·预测·决策', href: '/products/bi' },
{ id: 'cms', title: 'CMS 内容平台', description: '建站·运营·分发·分析', href: '/products/cms' },
{ id: 'sds', title: 'SDS 供应链决策', description: '预测·补货·库存·协同', href: '/products/sds' },
{ id: 'oa', title: 'OA 协同办公', description: '审批·公文·协作·知识', href: '/products/oa' },
],
highlight: true,
},
{
id: 'standalone-products',
title: '专业产品',
description: '专业领域独立产品线',
items: [
{ id: 'novavis', title: '睿视 NovaVis', description: '面向执法机关的离线智能数据分析与资金关系图谱平台', href: 'https://novavis.p.novalon.cn', badge: '内测中' },
],
},
],
solutions: [
/* 行业轴 —— 读 solution 模型(6 行已带 industry / painPoints / suiteCombination) */
industries: [
{
id: 'industry-solutions',
title: '行业解决方案',
description: '基于企业套装的行业实践',
title: '行业实践',
description: '按行业问题空间组织的落地方案',
items: [
{ id: 'manufacturing', title: '制造业', description: '智能制造·MES·质量管控', href: '/solutions/manufacturing' },
{ id: 'retail', title: '贸易零售', description: '全渠道·会员·精准营销', href: '/solutions/retail' },
@@ -93,11 +98,13 @@ export const MEGA_DROPDOWN_DATA: MegaDropdownData = {
highlight: true,
},
],
services: [
/* 能力轴 —— 读 service 模型;产品矩阵作为「用什么交付」内嵌于此,不再独占一级导航 */
capabilities: [
{
id: 'professional-services',
title: '专业服务',
description: '全流程技术支持',
id: 'capability-groups',
title: '能力组',
description: '从判断到运营的四种陪跑方式',
items: [
{ id: 'consulting', title: '战略咨询', description: '数字化转型咨询规划', href: '/services/consulting' },
{ id: 'software', title: '企业软件', description: 'ERP/CRM/BI 系统实施', href: '/services/software' },
@@ -106,5 +113,52 @@ export const MEGA_DROPDOWN_DATA: MegaDropdownData = {
],
highlight: true,
},
{
id: 'enterprise-suite',
title: '产品矩阵',
description: '能力交付所依托的自研套件',
items: [
/**
* ⚠ 这一条不是可选项,是 /products 这个 hub 的**唯一导航入口**。
* 决策 2 把「产品」从一级导航撤下,但 /products 仍在 sitemap(priority 0.9)、
* 仍是 6 个产品详情页的上游。若只撤导航而不补这一条,就等于把最高价值的 hub
* 变成孤儿页 —— 那是回退,不是重构。
* 所以「产品不占一级导航」的正确落法是:**降级为能力轴的第二层**,而不是消失。
*/
{ id: 'all-products', title: '产品矩阵总览', description: '六款自研套件的组合与定位', href: '/products' },
{ id: 'erp', title: 'ERP 管理系统', description: '财务·采购·销售·库存·生产', href: '/products/erp', badge: '旗舰' },
{ id: 'crm', title: 'CRM 客户管理', description: '线索·商机·合同·服务', href: '/products/crm', badge: '旗舰' },
{ id: 'bi', title: 'BI 数据平台', description: '报表·仪表盘·预测·决策', href: '/products/bi' },
{ id: 'cms', title: 'CMS 内容平台', description: '建站·运营·分发·分析', href: '/products/cms' },
{ id: 'sds', title: 'SDS 供应链决策', description: '预测·补货·库存·协同', href: '/products/sds' },
{ id: 'oa', title: 'OA 协同办公', description: '审批·公文·协作·知识', href: '/products/oa' },
],
},
{
id: STANDALONE_GROUP_ID,
title: '专业产品',
description: '专业领域独立产品线',
items: [
{ id: 'novavis', title: '睿视 NovaVis', description: '面向执法机关的离线智能数据分析与资金关系图谱平台', href: 'https://novavis.p.novalon.cn', badge: '内测中' },
],
},
],
/* 洞察轴 —— 聚合 news + methodology + cases。
案例条目**故意不列**:case-study 模型当前 0 行(prisma/seeds/case-studies.ts:11 明示
「首批客户共创阶段,暂无对外可验证案例」)。零编造原则下不放一个指向空列表的入口,
等真实授权到位再加 —— 这是个有意的留白,不是漏配。 */
insights: [
{
id: 'insight-groups',
title: '洞察',
description: '方法论、观点与公开写作',
items: [
{ id: 'all', title: '全部洞察', description: '按时间倒序的公开内容', href: '/insights' },
{ id: 'methodology', title: '方法论', description: '四阶段交付与验收标准', href: '/methodology' },
{ id: 'writing', title: '技术与观点', description: '数字化转型的公开写作', href: '/news' },
],
highlight: true,
},
],
};
+50
View File
@@ -0,0 +1,50 @@
import { describe, it, expect } from '@jest/globals';
import { isNavItemActive } from './nav-active';
/**
* 这套判定替掉的是 mobile-tab-bar.tsx 原来的 per-id `if` 阶梯 —— 它 switch 在 **id** 上,
* IA 改名后 id 变了就会对每一项静默返回 false(tab bar 照渲染、永不高亮 = 绿但空洞)。
* 所以下面的用例一律按 href 断言,并且刻意覆盖「改名后仍然对」这一维。
*/
describe('isNavItemActive', () => {
it('列表页点亮自己与其子路由', () => {
expect(isNavItemActive('/solutions', '/solutions')).toBe(true);
expect(isNavItemActive('/solutions/manufacturing', '/solutions')).toBe(true);
});
it('按 segment 切,不被同前缀的无关路由误点亮', () => {
// 裸 startsWith('/solutions') 会把 /solutionship 也算进来 —— 这是抽公共实现要防的
expect(isNavItemActive('/solutionship', '/solutions')).toBe(false);
});
it('首页与联系页只精确匹配(否则任何路径都会点亮「首页」)', () => {
expect(isNavItemActive('/', '/')).toBe(true);
expect(isNavItemActive('/about', '/')).toBe(false);
expect(isNavItemActive('/contact', '/contact')).toBe(true);
expect(isNavItemActive('/contact/thanks', '/contact')).toBe(false);
});
it('尾斜杠归一化', () => {
expect(isNavItemActive('/solutions/', '/solutions')).toBe(true);
expect(isNavItemActive('/solutions/manufacturing/', '/solutions')).toBe(true);
});
it('忽略 query 与 hash(洞察页靠 ?kind= 分流,不能因此丢掉高亮)', () => {
expect(isNavItemActive('/insights?kind=methodology', '/insights')).toBe(true);
expect(isNavItemActive('/insights#top', '/insights')).toBe(true);
});
it('外链不参与「当前页」高亮', () => {
expect(isNavItemActive('/products/erp', 'https://novavis.p.novalon.cn')).toBe(false);
});
it('改名后仍成立:能力轴无论叫 services 还是 capabilities,判定同构', () => {
expect(isNavItemActive('/services/consulting', '/services')).toBe(true);
expect(isNavItemActive('/capabilities/consulting', '/capabilities')).toBe(true);
});
it('空值不抛异常、不判亮', () => {
expect(isNavItemActive('', '/solutions')).toBe(false);
expect(isNavItemActive('/solutions', '')).toBe(false);
});
});
+37
View File
@@ -0,0 +1,37 @@
/**
* 导航激活判定的**唯一实现**。
*
* 为什么要抽出来:此前全站有三套激活语法 ——
* 1. header.tsx 内联的 `isActive(item)`(宽松前缀)
* 2. mobile-tab-bar.tsx 手写的 per-id `if` 阶梯(switch 在 **id** 上而不是 href)
* 3. footer 自己另有一套
* 第 2 套在 IA 改名时尤其危险:id 一变(products→capabilities…),阶梯对每一项
* 都静默返回 `false` ⇒ tab bar 照常渲染、只是永不高亮。那是典型的「绿但空洞」:
* 页面没坏、门禁没红,唯独功能悄悄没了。
*/
/** 首页只精确匹配,否则任何路径都会把「首页」点亮 */
const EXACT_ROOTS = new Set<string>(['/', '/contact']);
/**
* 前缀匹配并归一化尾斜杠:`/solutions` 点亮 `/solutions` 与 `/solutions/manufacturing`,
* 但**不**点亮 `/solutionship` 这类同前缀的无关路由(因此按 path segment 切,而不是 startsWith 裸串)。
*/
export function isNavItemActive(pathname: string, href: string): boolean {
if (!href || !pathname) return false;
// 外链(如独立产品站)不参与"当前页"高亮
if (href.startsWith('http')) return false;
const normalize = (p: string) => (p.length > 1 ? p.replace(/\/+$/, '') : p);
const target = normalize(href);
// split() 的下标在 noUncheckedIndexedAccess 下是 `string | undefined` ⇒ 显式兜回原串,
// 不用 `!`(那等于把「真的没 query」与「类型没收窄」混成一谈)
const withoutQuery = pathname.split('?')[0] ?? pathname;
const current = normalize(withoutQuery.split('#')[0] ?? withoutQuery);
if (EXACT_ROOTS.has(target)) return current === target;
if (target === '') return current === '/';
return current === target || current.startsWith(`${target}/`);
}
+192
View File
@@ -0,0 +1,192 @@
import { describe, it, expect } from '@jest/globals';
import {
resolveNavigation,
injectStandaloneProducts,
} from './navigation-resolution';
import { NAVIGATION_V2, MEGA_DROPDOWN_DATA, type MegaDropdownData, type MegaDropdownGroup } from './constants/navigation';
/** 索引签名 + noUncheckedIndexedAccess ⇒ 直接下标会拿到 `T | undefined`。
* 统一走这两个小助手,断言里就不必到处贴 `!`(也避免把「真的没配」与「类型没收窄」混成一谈)。 */
const groupOf = (mega: MegaDropdownData, key: string, groupId: string): MegaDropdownGroup => {
const found = (mega[key] ?? []).find((g) => g.id === groupId);
if (!found) throw new Error(`找不到 ${key} / ${groupId}`);
return found;
};
const firstItemOf = (mega: MegaDropdownData, key: string, groupId: string) => groupOf(mega, key, groupId).items[0];
const validGroup = {
id: 'g1',
title: '组一',
items: [{ id: 'a', title: '甲', description: 'd', href: '/solutions/manufacturing' }],
};
const validCms = {
mainNav: [{ id: 'industries', label: '行业', href: '/solutions', hasDropdown: true, dropdownKey: 'industries' }],
// 三轴 key 必须齐 —— footer 按 key 取栏目,缺一轴就静默空栏
megaDropdown: {
industries: [validGroup],
capabilities: [validGroup],
insights: [validGroup],
},
};
describe('resolveNavigation —— 代码为真源,CMS 仅在自洽时覆盖', () => {
it('后台没配那一行 ⇒ 用代码,且不报问题(这是新装环境的正常态)', () => {
const r = resolveNavigation(null);
expect(r.source).toBe('code');
expect(r.mainNav).toBe(NAVIGATION_V2);
expect(r.issues).toEqual([]);
});
it('CMS 配置完整且自洽 ⇒ 采用 CMS(不能因为"改成代码优先"就把后台能力废掉)', () => {
const r = resolveNavigation(validCms);
expect(r.source).toBe('cms');
expect(r.mainNav).toHaveLength(1);
expect(r.mainNav[0]?.label).toBe('行业');
expect(r.issues).toEqual([]);
});
/**
* 本轮最关键的一条:生产库里那一行仍是**旧 IA**(products/solutions/services 三个 key、
* 7 项主导航),它内部完全自洽 —— 每个 dropdownKey 都找得到自己的面板。
* 若只验"JSON 自洽",它会继续覆盖代码;而 footer 已改读 industries/capabilities/insights,
* 那三个 key 在旧行里不存在 ⇒ 页脚三栏**静默变空**(页脚照常渲染、门禁照常绿)。
* 所以判定标准必须是「它是不是这套 IA」。
*/
it('旧 IA 的自洽配置必须被拒(这条锁的是生产升级瞬间页脚空栏的事故)', () => {
const legacyRow = {
mainNav: [
{ id: 'products', label: '产品', href: '/products', hasDropdown: true, dropdownKey: 'products' },
{ id: 'solutions', label: '解决方案', href: '/solutions', hasDropdown: true, dropdownKey: 'solutions' },
{ id: 'services', label: '服务', href: '/services' },
],
megaDropdown: {
products: [{ id: 'enterprise-suite', title: '企业套装', items: [{ id: 'erp', title: 'ERP', description: '', href: '/products/erp' }] }],
solutions: [{ id: 'industry-solutions', title: '行业解决方案', items: [{ id: 'm', title: '制造业', description: '', href: '/solutions/manufacturing' }] }],
services: [{ id: 'professional-services', title: '专业服务', items: [{ id: 'c', title: '战略咨询', description: '', href: '/services/consulting' }] }],
},
};
// 前提:这份旧配置自身是自洽的(否则测不到"自洽但不对"这一维)
expect(resolveNavigation(legacyRow).source).toBe('code');
expect(resolveNavigation(legacyRow).issues.join('\n')).toMatch(/缺少 industries 轴面板/);
});
it('有 hasDropdown 却没有对应面板 ⇒ 退回代码(渲染一个点开没内容的按钮是不可接受的)', () => {
const r = resolveNavigation({
mainNav: [{ id: 'x', label: '洞察', href: '/insights', hasDropdown: true, dropdownKey: 'insights' }],
megaDropdown: { other: [validGroup] },
});
expect(r.source).toBe('code');
// 关键:不能只是退回,还必须说清「为什么没用你的配置」
expect(r.issues.join('\n')).toMatch(/dropdownKey「insights」.*没有对应面板/);
});
it('mainNav 空数组 ⇒ 退回代码并报问题', () => {
const r = resolveNavigation({ mainNav: [], megaDropdown: { industries: [validGroup], capabilities: [validGroup], insights: [validGroup] } });
expect(r.source).toBe('code');
expect(r.issues.join('\n')).toMatch(/mainNav 缺失或为空/);
});
it('条目 href 既非站内绝对路径也非 https ⇒ 判不合格(防把 /# 或 javascript: 放进导航)', () => {
const r = resolveNavigation({
mainNav: [{ id: 'x', label: '甲', href: 'javascript:alert(1)' }],
megaDropdown: { industries: [validGroup], capabilities: [validGroup], insights: [validGroup] },
});
expect(r.source).toBe('code');
expect(r.issues.join('\n')).toMatch(/href 不可用/);
});
it('面板里某个 item 缺 href ⇒ 整份配置不合格,退回代码', () => {
const r = resolveNavigation({
mainNav: [{ id: 'i', label: '行业', href: '/solutions', hasDropdown: true, dropdownKey: 'industries' }],
megaDropdown: { industries: [{ id: 'g', title: '组', items: [{ id: 'a', title: '甲', description: '' }] }] },
});
expect(r.source).toBe('code');
expect(r.issues.join('\n')).toMatch(/href 不可用/);
});
it('非对象载荷(字符串/数组)⇒ 退回代码,不抛异常', () => {
expect(resolveNavigation('oops' as unknown).source).toBe('code');
expect(resolveNavigation([] as unknown).source).toBe('code');
});
});
describe('injectStandaloneProducts —— 按组 id 找,不按导航 key 找', () => {
const standalone = [{ id: 'novavis', title: '睿视 NovaVis', description: '', href: 'https://novavis.p.novalon.cn', badge: '内测中' }];
it('独立产品挂在改名后的 capabilities key 下也必须被注入', () => {
// 原实现按 `key === 'products'` 匹配。双轴改名后那个 key 已不存在
// ⇒ 若沿用旧写法,独立产品会**静默不再注入**:面板照常渲染,只是少了那一组。
const out = injectStandaloneProducts({ capabilities: [{ id: 'standalone-products', title: '专业产品', items: [] }] }, standalone);
expect(firstItemOf(out, 'capabilities', 'standalone-products')?.id).toBe('novavis');
});
it('注入时清掉组描述(CMS 给的占位文案不该覆盖注入结果)', () => {
const out = injectStandaloneProducts({ capabilities: [{ id: 'standalone-products', title: '专业产品', description: '旧文案', items: [] }] }, standalone);
expect(groupOf(out, 'capabilities', 'standalone-products').description).toBeUndefined();
});
it('CMS 里没有独立产品 ⇒ 原样返回,不凭空造组', () => {
const mega = { capabilities: [{ id: 'other', title: '别组', items: [] }] };
expect(injectStandaloneProducts(mega, [])).toBe(mega);
expect(groupOf(injectStandaloneProducts(mega, standalone), 'capabilities', 'other').items).toHaveLength(0);
});
it('代码真源必须自带 standalone-products 组,否则注入永远落空(守卫配置本身)', () => {
const ids = Object.values(MEGA_DROPDOWN_DATA).flat().map((g) => g.id);
expect(ids).toContain('standalone-products');
});
});
describe('代码真源自身的完整性(导航骨架不能靠运行时才发现是坏的)', () => {
it('每个 hasDropdown 的导航项都能在 megaDropdown 里找到面板', () => {
for (const item of NAVIGATION_V2) {
if (!item.hasDropdown) continue;
// ⚠ jest 的 expect() 不接受第二个「说明文案」参数(那是 Playwright 的签名,串工具会直接抛
// "Expect takes at most one argument")⇒ 要把可读信息放进断言对象本身。
const groups = MEGA_DROPDOWN_DATA[item.dropdownKey ?? ''];
expect({ label: item.label, dropdownKey: item.dropdownKey, hasPanel: Array.isArray(groups) && groups.length > 0 })
.toEqual({ label: item.label, dropdownKey: item.dropdownKey, hasPanel: true });
}
});
it('NAVIGATION_V2 自身必须能通过自己写下的校验器(自己先是个合法 CMS 载荷)', () => {
const r = resolveNavigation({ mainNav: NAVIGATION_V2, megaDropdown: MEGA_DROPDOWN_DATA });
expect(r.issues).toEqual([]);
expect(r.source).toBe('cms');
});
it('双轴到位:产品不在一级导航里,行业与能力都在', () => {
const labels = NAVIGATION_V2.map((n) => n.label);
expect(labels).not.toContain('产品');
expect(labels).toEqual(['行业', '能力', '洞察', '关于我们']);
// 联系不在导航列表里 —— 它是 header 的常驻 CTA(两家对标同此)
expect(labels).not.toContain('联系我们');
});
it('一级导航里没有指向空渠道的入口(案例 0 行、新闻仅 2 行时不该挂在骨架上)', () => {
const hrefs = NAVIGATION_V2.map((n) => n.href);
expect(hrefs).not.toContain('/cases');
expect(hrefs).not.toContain('/news');
});
/**
* 「降级」不等于「消失」。决策 2 把产品退出**一级导航**,但 /products 仍在 sitemap
* (priority 0.9)且是 6 个产品详情页的上游 hub —— 只撤导航而不补第二层入口,
* 等于把最高价值的 hub 变成孤儿页,那是回退。这条守卫就是防下一次「顺手删掉」。
*/
it('被退出一级导航的 hub 必须在第二层仍可达(/products 不许变孤儿)', () => {
const allMegaHrefs = Object.values(MEGA_DROPDOWN_DATA).flatMap((groups) => groups.flatMap((g) => g.items.map((i) => i.href)));
const navHrefs = NAVIGATION_V2.map((n) => n.href);
for (const hub of ['/products', '/services', '/solutions']) {
expect({ hub, reachable: navHrefs.includes(hub) || allMegaHrefs.includes(hub) }).toEqual({ hub, reachable: true });
}
// 且 /products 确实只活在第二层(不在一级导航里)
expect(navHrefs).not.toContain('/products');
});
it('行业轴与能力轴的条目必须落在各自既有的路由前缀下(换标签不换路由)', () => {
expect(groupOf(MEGA_DROPDOWN_DATA, 'industries', 'industry-solutions').items.every((i) => i.href.startsWith('/solutions/'))).toBe(true);
expect(groupOf(MEGA_DROPDOWN_DATA, 'capabilities', 'capability-groups').items.every((i) => i.href.startsWith('/services/'))).toBe(true);
});
});
+177
View File
@@ -0,0 +1,177 @@
/**
* 导航解析:把「CMS 行优先、代码只兜底」反转为「**代码为真源,CMS 仅在通过校验时覆盖**」。
*
* 为什么必须反转(2026-10-16 实测确认,非推测):
* src/app/layout.tsx 原写法是
* mainNav: (navData?.mainNav as NavigationItem[]) || NAVIGATION_V2
* baseMegaDropdown = (navData?.megaDropdown as ...) || MEGA_DROPDOWN_DATA
* 即 **DB 里的 navigation/default 行胜出,代码只是它为空时的兜底**。
* `navigation` 模型的字段是泛型 json(prisma/seed.ts:529-530),改导航结构不需要动 schema ——
* 听起来是好消息,实际是最坏的消息:只改 navigation.ts 会上线一个**生产静默忽略它**的新导航,
* 因为 prod 那一行仍持着旧的 7 项。而 footer 是按 megaDropdown 的 key 取栏目的,
* 新代码 key 对旧 DB key ⇒ 页脚栏目静默变空(渲染着、但没内容 = 典型假绿)。
*
* 这里采取「fail closed 到代码」而不是「fail open 到半截 CMS 配置」:
* 导航是全站的骨架入口,一个指向不存在路由的导航项比"退回代码定义的导航"糟糕得多。
* 同时保留 CMS 的可编辑性 —— 只要那一行**完整且自洽**,它照样覆盖代码。
*
* issues 只在服务端 console.warn 输出(渲染期不写库:Notification 表是后台数据,
* 在 RSC 里写它等于让每次首页渲染都可能产生写副作用)。
*/
import {
NAVIGATION_V2,
MEGA_DROPDOWN_DATA,
STANDALONE_GROUP_ID,
MEGA_KEYS,
type NavigationItemV2,
type MegaDropdownGroup,
type MegaDropdownData,
} from './constants/navigation';
export interface NavigationResolution {
mainNav: NavigationItemV2[];
megaDropdown: MegaDropdownData;
/** 'cms' = 采用了后台那一行;'code' = 校验未通过或后台未配置,退回代码真源 */
source: 'cms' | 'code';
/** 校验发现的问题;source==='code' 且后台确有数据时,这里就是"为什么没采用"的答案 */
issues: string[];
}
/** footer.tsx 与 header 的面板都按这三个 key 取数 ⇒ 缺任何一个就不算「这套 IA」 */
const REQUIRED_MEGA_KEYS: readonly string[] = [MEGA_KEYS.industries, MEGA_KEYS.capabilities, MEGA_KEYS.insights];
const isPlainObject = (v: unknown): v is Record<string, unknown> =>
typeof v === 'object' && v !== null && !Array.isArray(v);
/** 同一站点绝对路径,或 https 外链(NovaVis 独立站就是外链) */
function isUsableHref(href: unknown): href is string {
return typeof href === 'string' && (href.startsWith('/') || href.startsWith('https://'));
}
function validateGroup(group: unknown, where: string, issues: string[]): group is MegaDropdownGroup {
if (!isPlainObject(group)) { issues.push(`${where} 不是对象`); return false; }
let ok = true;
if (typeof group.id !== 'string' || !group.id) { issues.push(`${where} 缺 id`); ok = false; }
if (typeof group.title !== 'string' || !group.title) { issues.push(`${where} 缺 title`); ok = false; }
if (!Array.isArray(group.items)) { issues.push(`${where} 的 items 不是数组`); return false; }
group.items.forEach((item, i) => {
if (!isPlainObject(item)) { issues.push(`${where}.items[${i}] 不是对象`); ok = false; return; }
if (typeof item.title !== 'string' || !item.title) issues.push(`${where}.items[${i}] 缺 title`);
if (!isUsableHref(item.href)) { issues.push(`${where}.items[${i}] href 不可用(既非 /开头 也非 https://)`); ok = false; }
});
return ok;
}
function validateMega(mega: unknown, issues: string[]): mega is MegaDropdownData {
if (!isPlainObject(mega)) { issues.push('megaDropdown 不是对象'); return false; }
let ok = true;
for (const [key, groups] of Object.entries(mega)) {
if (!Array.isArray(groups) || groups.length === 0) { issues.push(`megaDropdown.${key} 不是非空数组`); ok = false; continue; }
groups.forEach((g, i) => { if (!validateGroup(g, `megaDropdown.${key}[${i}]`, issues)) ok = false; });
}
return ok;
}
/**
* 校验入口。cmsData 允许为 undefined/null(后台根本没配那一行)⇒ 静默用代码。
* 有数据但不合格 ⇒ 用代码 + 把 issues 报出来("我为什么没用你配的东西"必须可见)。
*/
export function resolveNavigation(cmsData: unknown): NavigationResolution {
const fallback = (): NavigationResolution => ({
mainNav: NAVIGATION_V2,
megaDropdown: MEGA_DROPDOWN_DATA,
source: 'code',
issues: [],
});
// 显式两值比较:eslint 的 eqeqeq 不允许 `== null`,而这里要的就是 null 与 undefined 两者
if (cmsData === null || cmsData === undefined) return fallback();
if (!isPlainObject(cmsData)) {
return { ...fallback(), issues: ['navigation 数据不是对象,已退回代码真源'] };
}
const issues: string[] = [];
const rawNav = cmsData.mainNav;
const rawMega = cmsData.megaDropdown;
if (!Array.isArray(rawNav) || rawNav.length === 0) {
issues.push('mainNav 缺失或为空数组');
} else {
rawNav.forEach((item, i) => {
if (!isPlainObject(item)) { issues.push(`mainNav[${i}] 不是对象`); return; }
if (typeof item.label !== 'string' || !item.label) issues.push(`mainNav[${i}] 缺 label`);
if (!isUsableHref(item.href)) issues.push(`mainNav[${i}] href 不可用`);
// 「有下拉但没有对应面板」是最常见的一半配置:渲染出一个点开没内容的按钮
if (item.hasDropdown) {
const key = typeof item.dropdownKey === 'string' ? item.dropdownKey : '';
if (!key) {
issues.push(`mainNav[${i}](${item.label}) 有 hasDropdown 但缺 dropdownKey`);
} else {
const panel = isPlainObject(rawMega) ? (rawMega as MegaDropdownData)[key] : undefined;
if (!Array.isArray(panel) || panel.length === 0) {
issues.push(`mainNav[${i}](${item.label}) 的 dropdownKey「${key}」在 megaDropdown 里没有对应面板`);
}
}
}
});
}
if (!validateMega(rawMega, issues)) {
if (!issues.some((s) => s.startsWith('megaDropdown'))) issues.push('megaDropdown 校验未通过');
}
/**
* 契约校验(不只是 JSON 自洽):CMS 那一行必须**覆盖应用消费的三个轴 key**。
*
* 为什么这比"自洽"重要,且是本轮实测出来的真实风险:
* 生产库里的 navigation/default 仍是旧 IA(products/solutions/services 三个 key,
* 7 项主导航)。它内部完全自洽 —— 每个 dropdownKey 都能找到自己的面板 ——
* 于是"自洽即放行"会让它继续覆盖代码。而 footer.tsx 改读 industries/capabilities/insights
* 之后,那三个 key 在旧行里不存在 ⇒ **页脚三栏静默变空**:页脚照常渲染、门禁照常绿,
* 只有用户看见空白栏目。这正是本文件开头要避免的那类假绿,只不过这次是数据侧。
*
* 所以判定标准是「它是不是这套 IA」,而不是「它是不是合法 JSON」。
*/
if (isPlainObject(rawMega)) {
for (const key of REQUIRED_MEGA_KEYS) {
const panel = (rawMega as MegaDropdownData)[key];
if (!Array.isArray(panel) || panel.length === 0) {
issues.push(`缺少 ${key} 轴面板(当前 megaDropdown 的 key = [${Object.keys(rawMega).join(', ')}])`);
}
}
}
if (issues.length > 0) {
return { ...fallback(), issues: [`CMS 导航配置不合格,已退回代码真源(${issues.length} 项)`, ...issues] };
}
return {
mainNav: rawNav as NavigationItemV2[],
megaDropdown: rawMega as MegaDropdownData,
source: 'cms',
issues: [],
};
}
/**
* 把 CMS 里的独立产品注入到「产品矩阵」所在组。
*
* ⚠ 原实现按 **`key === 'products'`** 匹配,双轴改名后那个 key 已不存在 ⇒
* 独立产品会静默不再注入。这里改为按**组 id**(STANDALONE_GROUP_ID)在所有 key 里找,
* 组 id 比 key 稳定得多,也不依赖导航轴叫什么名字。
*/
export function injectStandaloneProducts(
mega: MegaDropdownData,
items: MegaDropdownData[string][number]['items'],
): MegaDropdownData {
if (items.length === 0) return mega;
const out: MegaDropdownData = {};
for (const [key, groups] of Object.entries(mega)) {
out[key] = groups.map((group) =>
group.id === STANDALONE_GROUP_ID
? { ...group, description: undefined, items }
: group,
);
}
return out;
}