feat(home): 首页 v17 复刻保时捷咨询的构图语法(签名件 + 编辑舞台 + 行业切换)
对标对象:Porsche Consulting 首页(2026-11-03 live 实测,1600×900 / 390×844)。
只换视觉语法与构图,文案、数据真源、空态判据、basis 口径一字未改。
逐段
- Hero 删黑底块 + 6px 红竖条 + 右侧蓝图叠卡 → 全幅影像 + 居中声明 + 软版斜线纹。
实测首屏就是「居中大字压在全幅影像上」,无框无容器底;三段压暗是可读性,
不是滤镜。**不接 IMAGE_RATIOS.HERO_WIDE**:2.31:1 在 390 宽下只有 169px 高,
装不下 56px 声明,移动端保留 min-h(偏差记进组件注释)。
- 账本 数字 500 → 700(实测成果数字 40/700;v16 的 500 是 Bain 的读数)。
红仍不进入数字 —— 红是结论电压,不许被数据条稀释。
- 洞察 改 teaser 语法:图 + 24/700 + 18/400 + 24×3px 红短线,灰底出血带托住三张。
- 行业 IndustryGridBlock(3×2 卡片)→ IndustryTabs(黑带 + 横向标签 + 预览 + 双 V)。
**不伪装成 role=tab**:对标的这排是 <a>,点击就跳转;标成 tab 会让读屏
期待「选一个面板」。改用 nav + 6 个真链接 + aria-live 预览。
- 能力 CapabilitiesAccordion → StoryStage:4×100vh + sticky 舞台,滚动切换 4 屏
(01/04 计数 → 断言 → 正文 → 方图 + 斜线纹 + 双 V)。
内容真源仍是 services 4 行,零新文案。
- 接缝 白↔黑两处交界各压一块斜线纹(上半压白、下半压黑)—— 对标用纹理接缝代替渐变。
- 空带 洞察后、CTA 前各一条 --spacer-band。
- CTA 灰带 + 字重分裂声明(64/700 → 64/400)+ 右斜线纹 + 向右双 V。
无障碍与动效(本片的硬约束)
- 舞台**单一 DOM,不复制内容**:4 屏恒在 <ol> 里,服务端首帧一定是 data-mode="flow"
(4 屏纵向堆叠、全部可见),挂载后才在 (min-width:768px) 且无「减少动效」时切 pinned。
沿用 2026-10-20 白屏那轮的教训:首帧必须与 SSR 一致,不许有元素停在 opacity:0。
- pinned 下非活动屏 visibility:hidden(移出 tab 序)+ aria-hidden,否则键盘会 tab 进
看不见的按钮。
- 动画只是增强:切换由滚动进度驱动,交叉淡出走 --transition-normal(280ms);
对标原物那条 6s infinite 脉冲不移植(CONTEXT.md:81 禁循环装饰动画)。
两处根因修复(都在本树实测,非猜测)
- **body 的 overflow-x: hidden 会吃掉 position: sticky**:hidden 把 body 变成非滚动的
滚动容器,sticky 相对最近的滚动祖先定位,祖先不滚动就永不吸附。实测 stickyTop 恒等于
-scrollY(等于没吸附)、改成 clip(computed `clip visible`)后 stickyTop = 0。
这是编辑舞台能成立的前提,不是样式偏好。
- **globals 的 `ul, ol { color: var(--color-text-secondary) }` 会污染结构件列表**:
黑底舞台上的 01/04 变成 #3A352E 灰。新增 .list-plain 一并摘掉正文列表的「文气」
(color / line-height / margin / padding / ::before 菱形),结构件继承所在区块的色与节奏。
其它
- 首页测试 v16 → v17:19 条断言按新结构改写,锚点 id 全保留(hero-section / hero-cta /
home-ledger* / home-industries / home-capabilities / home-insights / home-cta-button)。
账本那条 font-medium 改 font-bold 并写明是实测更正;accordion 的 aria-expanded 两条
换成舞台的 ol/li + 活动屏断言。
- page.test.tsx 与 metrics-basis.test.ts 的 v16 路径同步改到 v17(惰性 mock 的坑)。
- R15 由 21 下调到 20:v16 删除时带走一处装饰阴影,按「只降不升」同批下调。
验证(生产产物,node dist/standalone/server.js)
- check:grammar 19/19 EXIT=0(含 R18 0/0、R19 21/21);check:motion / check:accents EXIT=0
- check:a11y EXIT=0(contrast 44/44、headings 11/11 页通过)
- type-check EXIT=0、jest 156 套件 / 1854 例全通过
- e2e(E2E_TARGET=production):uj-11 7/7、p2-functional 48/48、nav-dropdown+p6 13/13
- 双视口截图对账:1600×900 十段 + 390×844 五段,逐段与实测读数核对
⚠ 视觉基线(132 张)尚未重采,需 AUTH-1 单独授权;在此之前 test:visual 会红属预期。
This commit is contained in:
1 parent
163e2c5ed8
commit
9f8d780a3b
12 files changed
+1073
-717
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { IndustryTabs } from './industry-tabs';
|
||||
|
||||
jest.mock('@/components/ui/static-link', () => ({
|
||||
StaticLink: ({ children, href, ...rest }: { children: React.ReactNode; href: string; [k: string]: unknown }) => (
|
||||
<a href={href} {...rest}>{children}</a>
|
||||
),
|
||||
}));
|
||||
|
||||
/**
|
||||
* 行业切换的三条判据:
|
||||
* ① 6 个入口**恒在**(CMS 缺行也不减入口),且都落在既有 /solutions/{slug};
|
||||
* ② 它**不是** tab —— 是 6 个真链接 + aria-live 预览。标成 role="tab" 会让读屏
|
||||
* 期待「选一个面板」,而实际行为是「离开本页」;
|
||||
* ③ 预览只消费传入的 solution 行,缺行时不编造痛点。
|
||||
*/
|
||||
describe('IndustryTabs', () => {
|
||||
const solutions = [
|
||||
{ id: 'manufacturing', title: '制造业', painPoints: ['库存不透明', '排产靠经验'] },
|
||||
{ id: 'retail', title: '贸易零售', painPoints: ['多渠道割裂'] },
|
||||
];
|
||||
|
||||
it('6 个行业入口恒在,链接落在既有 /solutions/{slug}', () => {
|
||||
const { container } = render(<IndustryTabs solutions={solutions} />);
|
||||
const links = [...container.querySelectorAll('nav a')].map((a) => a.getAttribute('href'));
|
||||
expect(links).toEqual([
|
||||
'/solutions/manufacturing',
|
||||
'/solutions/retail',
|
||||
'/solutions/education',
|
||||
'/solutions/healthcare',
|
||||
'/solutions/finance',
|
||||
'/solutions/logistics',
|
||||
]);
|
||||
});
|
||||
|
||||
it('不伪装成 tab:没有 role=tab,用 aria-current 标当前预览项', () => {
|
||||
const { container } = render(<IndustryTabs solutions={solutions} />);
|
||||
expect(container.querySelector('[role="tab"]')).toBeNull();
|
||||
expect(container.querySelector('[role="tablist"]')).toBeNull();
|
||||
const current = container.querySelectorAll('nav a[aria-current="true"]');
|
||||
expect(current).toHaveLength(1);
|
||||
expect(current[0]!.textContent).toBe('制造业');
|
||||
});
|
||||
|
||||
it('focus 切到第二个行业,预览区(aria-live)随之更新', () => {
|
||||
const { container } = render(<IndustryTabs solutions={solutions} />);
|
||||
const linked = container.querySelector('nav a[href="/solutions/retail"]') as HTMLElement;
|
||||
fireEvent.focus(linked);
|
||||
const live = container.querySelector('[aria-live="polite"]')!;
|
||||
expect(live.textContent).toContain('贸易零售');
|
||||
expect(live.textContent).toContain('多渠道割裂');
|
||||
expect(linked).toHaveAttribute('aria-current', 'true');
|
||||
});
|
||||
|
||||
it('缺数据时仍渲染 6 个入口,但不编造痛点', () => {
|
||||
const { container } = render(<IndustryTabs solutions={[]} />);
|
||||
expect(container.querySelectorAll('nav a')).toHaveLength(6);
|
||||
expect(container.textContent).not.toContain('库存不透明');
|
||||
// 兜底文案明确说「待补充」,而不是拿一句假痛点顶上
|
||||
expect(container.querySelector('[aria-live="polite"]')!.textContent).toContain('待补充');
|
||||
});
|
||||
|
||||
it('活动项的 1px 红下划线只在当前项上', () => {
|
||||
const { container } = render(<IndustryTabs solutions={solutions} />);
|
||||
const active = container.querySelector('nav a[aria-current="true"]')!;
|
||||
expect(active.className).toContain('border-brand');
|
||||
const others = [...container.querySelectorAll('nav a')].filter((a) => a !== active);
|
||||
for (const a of others) {
|
||||
expect(a.className).toContain('border-transparent');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,158 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import Image from 'next/image';
|
||||
import { DoubleChevron } from '@/components/ui/double-chevron';
|
||||
import { HatchField } from '@/components/ui/hatch-field';
|
||||
import { StaticLink } from '@/components/ui/static-link';
|
||||
import { IMAGE_RATIOS, aspectStyle } from '@/lib/constants/image-ratios';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
/**
|
||||
* 行业切换(Industry Tabs)—— 对标首页「赋能我们的客户 / Our Industry Expertise」段。
|
||||
*
|
||||
* 实测(2026-11-03):白底 40/700 标题 → **整幅黑带** → 横向 6~9 个行业标签
|
||||
* (active 项带 1px 品牌红下划线)→ 左侧方图(后叠斜线纹,比例 1.42:1)→
|
||||
* 右侧 32/700 标题 + 18/400 正文 + `›` 文字链 → 黑带右下双 V。
|
||||
*
|
||||
* 一个刻意的取舍:**不伪装成 `role="tab"`**。
|
||||
* 对标的这排是 `<a>`,点击就跳转;把它们标成 tab 会让读屏期待「选一个面板」,
|
||||
* 而实际行为是「离开本页」。所以这里用
|
||||
* `<nav aria-label="行业">` + 6 个真链接(`aria-current` 标当前预览项)
|
||||
* + 下方 `aria-live="polite"` 的预览区
|
||||
* 预览随 hover/focus 切换,点击仍走 `/solutions/{slug}`。
|
||||
*
|
||||
* 数据:6 个行业入口来自常量(即使 CMS 缺行也保留入口,**不编造痛点**);
|
||||
* 痛点文案只来自传进来的 solution 行,没有就整行不渲染。
|
||||
*/
|
||||
|
||||
export interface IndustryTabItem {
|
||||
slug: string;
|
||||
name: string;
|
||||
image: string;
|
||||
}
|
||||
|
||||
export interface IndustryTabRow {
|
||||
id?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
painPoints?: unknown[];
|
||||
}
|
||||
|
||||
const INDUSTRY_ITEMS: IndustryTabItem[] = [
|
||||
{ slug: 'manufacturing', name: '制造业', image: '/images/home/industry-manufacturing.webp' },
|
||||
{ slug: 'retail', name: '贸易零售', image: '/images/home/industry-retail.webp' },
|
||||
{ slug: 'education', name: '教育培训', image: '/images/home/industry-education.webp' },
|
||||
{ slug: 'healthcare', name: '医疗健康', image: '/images/home/industry-healthcare.webp' },
|
||||
{ slug: 'finance', name: '金融服务', image: '/images/home/industry-finance.webp' },
|
||||
{ slug: 'logistics', name: '物流运输', image: '/images/home/industry-logistics.webp' },
|
||||
];
|
||||
|
||||
export function IndustryTabs({ solutions }: { solutions?: IndustryTabRow[] }) {
|
||||
const bySlug = new Map((solutions ?? []).map((s) => [String(s.id ?? ''), s]));
|
||||
const [activeSlug, setActiveSlug] = useState(INDUSTRY_ITEMS[0]!.slug);
|
||||
const active = INDUSTRY_ITEMS.find((i) => i.slug === activeSlug) ?? INDUSTRY_ITEMS[0]!;
|
||||
const row = bySlug.get(active.slug);
|
||||
const painPoints = Array.isArray(row?.painPoints) ? row.painPoints.slice(0, 3).map(String) : [];
|
||||
|
||||
return (
|
||||
<section
|
||||
data-testid="home-industries"
|
||||
aria-labelledby="industry-tabs-heading"
|
||||
className="bg-bg-primary"
|
||||
>
|
||||
<div className="container-x pb-4 pt-16 md:pt-24">
|
||||
<h2
|
||||
id="industry-tabs-heading"
|
||||
className="max-w-3xl text-3xl font-bold leading-[1.05] tracking-tight text-text-primary sm:text-4xl md:text-[2.5rem]"
|
||||
>
|
||||
按行业的问题空间,不是按我们的产品线
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
{/* 接缝:白底标题区 → 黑带。对标在这一交界上压了一条斜线纹(实测 s8 patch 上方
|
||||
那条),它一半在灰白底、一半在黑带 —— 所以用负下边距跨接,而不是各画一半。 */}
|
||||
{/* 黑带:标签行 + 预览。黑底是「注意力区」,实测该段整幅为 #000 */}
|
||||
<div className="relative mt-10 bg-[#0B0A08] text-white">
|
||||
{/* 接缝块挂在黑带**内部顶端**、向上跨出 40px:
|
||||
上半压白底标题区、下半压黑带 —— 这才是标对的接缝手法(纹理桥接而非渐变)。 */}
|
||||
<div aria-hidden="true" className="container-x absolute -top-10 left-0 right-0">
|
||||
<HatchField className="ml-auto h-20 w-[34%]" />
|
||||
</div>
|
||||
<div className="container-x relative py-12 md:py-16">
|
||||
<nav aria-label="行业">
|
||||
<ul className="list-plain flex list-none flex-wrap gap-x-8 gap-y-3 border-b border-white/15 p-0 pb-4">
|
||||
{INDUSTRY_ITEMS.map((item) => {
|
||||
const isActive = item.slug === active.slug;
|
||||
return (
|
||||
<li key={item.slug} className="list-none">
|
||||
<StaticLink
|
||||
href={`/solutions/${item.slug}`}
|
||||
aria-current={isActive ? 'true' : undefined}
|
||||
onMouseEnter={() => setActiveSlug(item.slug)}
|
||||
onFocus={() => setActiveSlug(item.slug)}
|
||||
className={cn(
|
||||
'inline-block min-h-11 border-b-2 pb-2 text-base transition-colors duration-hover md:text-lg',
|
||||
isActive
|
||||
? 'border-brand font-bold text-white'
|
||||
: 'border-transparent text-white/70 hover:text-white',
|
||||
)}
|
||||
>
|
||||
{item.name}
|
||||
</StaticLink>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div aria-live="polite" className="mt-10 grid items-center gap-10 md:grid-cols-12 md:gap-12">
|
||||
<div className="relative md:col-span-6">
|
||||
<HatchField className="absolute -left-4 -top-6 h-32 w-32 md:h-40 md:w-40" />
|
||||
<div className="relative overflow-hidden" style={aspectStyle(IMAGE_RATIOS.TILE)}>
|
||||
<Image
|
||||
src={active.image}
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
fill
|
||||
sizes="(min-width: 768px) 50vw, 100vw"
|
||||
className="object-cover"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="md:col-span-6">
|
||||
<h3 className="text-2xl font-bold leading-tight text-white md:text-[2rem]">{active.name}</h3>
|
||||
{painPoints.length > 0 ? (
|
||||
<ul className="list-plain mt-5 list-none space-y-2 p-0">
|
||||
{painPoints.map((p) => (
|
||||
<li key={p} className="text-base leading-relaxed text-white/75">
|
||||
{p}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p className="mt-5 text-base leading-relaxed text-white/75">
|
||||
{String(row?.description ?? '该行业的问题清单待补充。')}
|
||||
</p>
|
||||
)}
|
||||
<StaticLink
|
||||
href={`/solutions/${active.slug}`}
|
||||
className="group mt-8 inline-flex min-h-11 items-center gap-2 text-sm font-medium text-white transition-colors duration-hover hover:text-brand"
|
||||
>
|
||||
<span aria-hidden="true" className="text-brand">›</span>
|
||||
查看该行业解决方案
|
||||
</StaticLink>
|
||||
</div>
|
||||
|
||||
<DoubleChevron
|
||||
direction="right"
|
||||
size="sm"
|
||||
className="pointer-events-none absolute bottom-6 right-4 hidden md:block"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { StoryStage } from './story-stage';
|
||||
|
||||
/**
|
||||
* 编辑舞台的判据锁三件事 —— 每一条都对应一个「做错了但看起来没问题」的失败形态:
|
||||
* ① 内容必须在 JS 未就绪时就可读(服务端首帧 = flow,4 屏全在 DOM,不是被 JS 渲染出来的);
|
||||
* ② 非活动屏在 pinned 下要被移出 tab 序(只写 opacity:0 会让键盘 tab 进看不见的按钮上);
|
||||
* ③ 计数器与序列表必须在,且计数器是装饰(aria-hidden),读屏听到的是列表本身。
|
||||
*/
|
||||
const slides = [
|
||||
{ id: 'consulting', title: '战略咨询', description: '把问题定义清楚', highlights: ['业务诊断', '蓝图'] },
|
||||
{ id: 'software', title: '企业软件', description: '把方案落成系统', highlights: ['架构'] },
|
||||
{ id: 'operations', title: '运营陪跑', description: '把节奏留在现场' },
|
||||
{ id: 'data', title: '数据治理', description: '把口径统一起来' },
|
||||
];
|
||||
|
||||
const renderStage = (props: Partial<React.ComponentProps<typeof StoryStage>> = {}) =>
|
||||
render(<StoryStage slides={slides} label="能力" heading="四种陪跑方式" {...props} />);
|
||||
|
||||
describe('StoryStage', () => {
|
||||
it('首帧是 flow:4 屏全部在 DOM 里,且没有任何一屏被判为不可见', () => {
|
||||
const { container } = renderStage();
|
||||
const section = screen.getByTestId('home-capabilities');
|
||||
// SSR 与客户端首帧必须一致 —— 2026-10-20 白屏那轮的教训
|
||||
expect(section).toHaveAttribute('data-mode', 'flow');
|
||||
expect(screen.getByTestId('home-capabilities')).toHaveAttribute('data-slide-count', '4');
|
||||
|
||||
const items = container.querySelectorAll('ol > li');
|
||||
expect(items).toHaveLength(4);
|
||||
for (const li of items) {
|
||||
expect(li).toHaveAttribute('data-active', 'true');
|
||||
expect(li).not.toHaveAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
|
||||
it('内容是语义列表:ol > li,标题是 h3,段标题是 h2(不为字形降级标题层级)', () => {
|
||||
const { container } = renderStage();
|
||||
expect(container.querySelector('ol')).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { level: 2 }).textContent).toBe('四种陪跑方式');
|
||||
const h3s = screen.getAllByRole('heading', { level: 3 }).map((h) => h.textContent);
|
||||
expect(h3s).toEqual(['战略咨询', '企业软件', '运营陪跑', '数据治理']);
|
||||
});
|
||||
|
||||
it('每屏都落到 /services/{id},链接不是「只在活动屏才渲染」', () => {
|
||||
const { container } = renderStage();
|
||||
const hrefs = [...container.querySelectorAll('a')].map((a) => a.getAttribute('href'));
|
||||
expect(hrefs).toEqual(slides.map((s) => `/services/${s.id}`));
|
||||
});
|
||||
|
||||
it('计数器是装饰(aria-hidden),斜杠是图形不是文字,读屏拿到的是列表本身', () => {
|
||||
renderStage();
|
||||
const counters = screen.getAllByTestId('story-counter');
|
||||
expect(counters).toHaveLength(4);
|
||||
for (const c of counters) {
|
||||
expect(c).toHaveAttribute('aria-hidden', 'true');
|
||||
// 「/」是 SlashMark 图形,不是文本节点 —— 所以 textContent 是 0104 而不是 01 / 04
|
||||
expect(c.querySelector('svg')).not.toBeNull();
|
||||
expect(c.textContent).toMatch(/^0[1-4]04$/);
|
||||
}
|
||||
});
|
||||
|
||||
it('没有 service 行时整段不渲染(不端出一个空舞台)', () => {
|
||||
const { container } = render(<StoryStage slides={[]} label="能力" heading="四种陪跑方式" />);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it('最多 4 屏:多于 4 条时截断,避免舞台高度失控', () => {
|
||||
const many = [...slides, { id: 'extra', title: '第五条', description: 'x' }];
|
||||
const { container } = renderStage({ slides: many });
|
||||
expect(container.querySelectorAll('ol > li')).toHaveLength(4);
|
||||
expect(screen.queryByText('第五条')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,197 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useMotionValueEvent, useScroll } from 'framer-motion';
|
||||
import Image from 'next/image';
|
||||
import { DoubleChevron } from '@/components/ui/double-chevron';
|
||||
import { HatchField } from '@/components/ui/hatch-field';
|
||||
import { SlashDivider } from '@/components/ui/slash-mark';
|
||||
import { StaticLink } from '@/components/ui/static-link';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
/**
|
||||
* 编辑舞台(Story Stage)—— 对标最核心的那一段交互。
|
||||
*
|
||||
* 实测(2026-11-03,Porsche Consulting 中国站首页):一个 `4 × 100vh` 高的
|
||||
* `section[data-module="scrollTeasers"]`,内层 `position: sticky; height: 100vh` 的
|
||||
* 「舞台」;滚动进度切换 4 屏,每屏 = 计数器 `01 / 04`(32/700 + 斜杠符)→ 断言标题
|
||||
* → 正文 → 实心红按钮 → 1:1 方图(后叠斜线纹)→ 右下双 V。整段黑底。
|
||||
*
|
||||
* 本实现的三条硬约束(不是风格偏好,是不满足就判不合格):
|
||||
*
|
||||
* 1. **单一 DOM,绝不复制内容**。移动端与「减少动效」都落 `data-mode="flow"`:
|
||||
* 4 屏纵向堆叠、全部可见、无 sticky。服务端首帧**一定**是 flow ——
|
||||
* 2026-10-20 生产白屏那轮的教训:首帧必须与 SSR 一致,不许有元素停在 opacity:0。
|
||||
* 挂载后只在 `(min-width:768px) and (prefers-reduced-motion:no-preference)` 时切 pinned。
|
||||
* 2. **动画只是增强**。4 屏始终在 `<ol>` 里,读屏与键盘拿到的是完整内容;
|
||||
* pinned 下非活动屏 `visibility:hidden`(移出 tab 序)+ `aria-hidden`,
|
||||
* 否则键盘会 tab 进看不见的按钮。
|
||||
* 3. **不做循环动画**。切换只由滚动进度驱动,交叉淡出走 `--transition-normal`(280ms);
|
||||
* 对标原物那条 6s infinite 的脉冲属于 CONTEXT.md:81 明令禁止的循环装饰,不移植。
|
||||
*
|
||||
* 内容真源是 CMS 的 `service` 行:title→h3、description→正文、highlights→要点、
|
||||
* id→`/services/{id}`。图片是氛围图(无人、无可读文字、无标识),不承担事实主张。
|
||||
*/
|
||||
|
||||
export interface StoryStageSlide {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
highlights?: string[];
|
||||
}
|
||||
|
||||
/** 方图取已入库的 6 张 1:1 氛围图,按下标轮转;不新造内容模型 */
|
||||
const STAGE_IMAGES = [
|
||||
'/images/rail/rail-cost.webp',
|
||||
'/images/rail/rail-transformation.webp',
|
||||
'/images/rail/rail-organization.webp',
|
||||
'/images/rail/rail-process.webp',
|
||||
'/images/rail/rail-technology.webp',
|
||||
'/images/rail/rail-supply-chain.webp',
|
||||
] as const;
|
||||
|
||||
/** 与设计契约一致:≤4 屏。多于 4 屏时舞台高度会过长,滚动一屏要跨越的像素数失去意义 */
|
||||
const MAX_SLIDES = 4;
|
||||
|
||||
export function StoryStage({
|
||||
slides,
|
||||
heading,
|
||||
label,
|
||||
testId = 'home-capabilities',
|
||||
}: {
|
||||
slides: StoryStageSlide[];
|
||||
heading: string;
|
||||
label: string;
|
||||
testId?: string;
|
||||
}) {
|
||||
const trackRef = useRef<HTMLDivElement>(null);
|
||||
const [active, setActive] = useState(0);
|
||||
/** 首帧恒为 flow(与 SSR 一致),挂载后按媒体查询切换 —— 见约束 1 */
|
||||
const [mode, setMode] = useState<'flow' | 'pinned'>('flow');
|
||||
|
||||
const items = slides.slice(0, MAX_SLIDES);
|
||||
|
||||
useEffect(() => {
|
||||
const mq = window.matchMedia('(min-width: 768px) and (prefers-reduced-motion: no-preference)');
|
||||
const sync = () => setMode(mq.matches ? 'pinned' : 'flow');
|
||||
sync();
|
||||
mq.addEventListener('change', sync);
|
||||
return () => mq.removeEventListener('change', sync);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* 没有 slides 时组件会提前 return,ref 便不会挂载 —— 而 `useScroll({target})`
|
||||
* 在 ref 未 hydrate 时会直接抛 invariant("Target ref is defined but not hydrated")。
|
||||
* 所以空列表退化为不传 target(走页面滚动,读到的值也不会被消费),
|
||||
* 而不是把 hook 放进条件分支(那会破坏 hooks 顺序)。
|
||||
*/
|
||||
const { scrollYProgress } = useScroll(
|
||||
items.length > 0 ? { target: trackRef, offset: ['start start', 'end end'] } : undefined,
|
||||
);
|
||||
useMotionValueEvent(scrollYProgress, 'change', (v) => {
|
||||
if (mode !== 'pinned' || items.length === 0) return;
|
||||
const next = Math.min(items.length - 1, Math.max(0, Math.floor(v * items.length)));
|
||||
setActive((prev) => (prev === next ? prev : next));
|
||||
});
|
||||
|
||||
if (items.length === 0) return null;
|
||||
|
||||
return (
|
||||
<section
|
||||
data-testid={testId}
|
||||
data-mode={mode}
|
||||
data-slide-count={items.length}
|
||||
aria-labelledby="story-stage-heading"
|
||||
className="story-stage relative bg-[#0B0A08] text-white"
|
||||
>
|
||||
<div ref={trackRef} className="story-stage__track" style={{ ['--stage-count' as string]: items.length }}>
|
||||
<div className="story-stage__sticky">
|
||||
<div className="container-x w-full py-16 md:py-0">
|
||||
<div className="flex items-center gap-3">
|
||||
<span aria-hidden="true" className="h-px w-10 bg-brand" />
|
||||
<span className="text-[13px] font-medium tracking-[0.15em] text-white/70">{label}</span>
|
||||
</div>
|
||||
<h2
|
||||
id="story-stage-heading"
|
||||
className="mt-5 max-w-3xl text-3xl font-bold leading-[1.05] tracking-tight text-white sm:text-4xl md:text-5xl"
|
||||
>
|
||||
{heading}
|
||||
</h2>
|
||||
|
||||
<ol className="list-plain story-stage__slides mt-12 list-none p-0 md:mt-10">
|
||||
{items.map((s, i) => {
|
||||
const isActive = mode === 'flow' || i === active;
|
||||
return (
|
||||
<li
|
||||
key={s.id}
|
||||
data-active={isActive ? 'true' : 'false'}
|
||||
aria-hidden={isActive ? undefined : true}
|
||||
className={cn(
|
||||
'story-stage__slide grid items-center gap-10 md:grid-cols-12 md:gap-12',
|
||||
i > 0 && 'mt-16 md:mt-0',
|
||||
)}
|
||||
>
|
||||
{/* 计数器:01 / 04(32/700),斜杠走原语,整块 aria-hidden —— 读屏听到的是序列表本身 */}
|
||||
<div
|
||||
aria-hidden="true"
|
||||
data-testid="story-counter"
|
||||
className="flex items-center gap-3 text-3xl font-bold leading-none tabular-nums md:col-span-1 md:flex-col md:gap-2"
|
||||
>
|
||||
<span>{String(i + 1).padStart(2, '0')}</span>
|
||||
<SlashDivider />
|
||||
<span className="text-white/50">{String(items.length).padStart(2, '0')}</span>
|
||||
</div>
|
||||
|
||||
<div className="md:col-span-5">
|
||||
<h3 className="text-2xl font-bold leading-tight text-white md:text-4xl">{s.title}</h3>
|
||||
<p className="mt-5 max-w-xl text-base leading-relaxed text-white/75">{s.description}</p>
|
||||
{(s.highlights?.length ?? 0) > 0 && (
|
||||
<ul className="list-plain mt-6 flex flex-wrap gap-x-6 gap-y-2 p-0 text-sm text-white/60">
|
||||
{s.highlights!.map((h) => (
|
||||
<li key={h} className="list-none">
|
||||
{h}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<StaticLink
|
||||
href={`/services/${s.id}`}
|
||||
className="group mt-8 inline-flex min-h-11 items-center gap-2 text-sm font-medium text-white transition-colors duration-hover hover:text-brand"
|
||||
>
|
||||
了解这一能力
|
||||
<span aria-hidden="true" className="transition-transform duration-hover group-hover:translate-x-1">
|
||||
›
|
||||
</span>
|
||||
</StaticLink>
|
||||
</div>
|
||||
|
||||
<div className="relative md:col-span-6">
|
||||
{/* 方图 + 后叠斜线纹 + 右下双 V:三件的位置关系是实测的构图,不是装饰堆叠 */}
|
||||
<HatchField className="absolute -left-4 -top-6 hidden h-40 w-40 md:block" />
|
||||
<div className="relative aspect-square overflow-hidden bg-[#141210]">
|
||||
<Image
|
||||
src={STAGE_IMAGES[i % STAGE_IMAGES.length] ?? STAGE_IMAGES[0]}
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
fill
|
||||
sizes="(min-width: 768px) 48vw, 100vw"
|
||||
className="object-cover"
|
||||
loading={i === 0 ? 'eager' : 'lazy'}
|
||||
/>
|
||||
</div>
|
||||
<DoubleChevron
|
||||
direction="down"
|
||||
size="sm"
|
||||
className="absolute -bottom-8 right-0 hidden md:block"
|
||||
/>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user