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:
1 parent
e9bd965411
commit
7d1a22a596
23 files changed
+1083
-197
No files matched your search
+15
-22
@@ -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('产品');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
@@ -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,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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}/`);
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user