feat(ui): 营销站 UI/UE/UX 治理 P0→P3 收官

复评(impeccable critique)全部 Priority Issues 与 Minor Observations 落地:
- P0 数字口径:MetricsBasisNote 单一真源 + metrics-basis.test fs 防线,接入
  products/solutions/services/home/about;纯渲染端加角注,不动 DB/seed 值
- P1 转化断头路:敬请期待态 + 404 语境出口 + services 空态双出口
- P1 首页并卡:TrustSection 早鸟横幅并入 CasesSection 单张深色共创卡
- P2 CTA 治理:CONSULT_CTA_ALLOWLIST 白名单 + 逐字符扫描器,/contact CTA 全归一
- P3 polish:footer 补 服务/公司列、contact 死三元/空槽/toast、GlobalErrorTracker 幂等日志
- 文档同源:PRODUCT/CONTEXT 动效带统一 180–280ms;DESIGN.md 立 The 10px Floor;
  font-floor.test 守卫禁止再引入 <10px(保留 10/11px 有意 Bain 微标签)

Gates: type-check 0 · jest 1581/132 · lint 0e/126w · contrast 7/7 · headings 10/10
This commit is contained in:
zhangxiang committed 2026-09-20 11:50:58 +08:00
1 parent dcf8ed6f20
commit f8917d4fda
66 files changed
+1448 -1313

No files matched your search

+15 -1
View File
@@ -108,10 +108,24 @@ export const TRUST_SIGNALS = [
value: '共创',
label: '首批客户共创',
desc: '与早期客户共同打磨产品,成果可验证',
source: '如实标注',
source: '公司公开声明',
},
] as const;
/**
* TRUST_SIGNALS.source 的历史占位值消毒:CMS pageCopy.trustSignals 在 seed 时
* 快照了旧常量(如内部批注「如实标注」外泄给用户),渲染入口做精确串替换。
* 根治方式是 admin 更新数据,此处是最后一道防线。
*/
const STALE_TRUST_SOURCES: Record<string, string> = {
'如实标注': '公司公开声明',
};
export function canonicalTrustSource(source?: string | null): string | undefined {
if (!source) return undefined;
return STALE_TRUST_SOURCES[source.trim()] ?? source;
}
/**
* 首批客户共创状态(无真实 quote 时的如实标注)。
* 有真实客户 quote / 共创伙伴后,可在 `src/components/content/testimonials.tsx` 启用 Testimonial 区块替换本标签。
+106
View File
@@ -0,0 +1,106 @@
/**
* CTA 文案机械防线(2026-09-19 critique P1):
* 预约动作全站统一「预约咨询」(DESIGN.md),任何生产源码字面量出现历史变体即失败。
* 扫描范围:src/app + src/components 的 .ts/.tsx(排除测试文件与 _archive 归档)。
*/
import { readdirSync, readFileSync, statSync } from 'fs';
import { join } from 'path';
import { CTA_LABELS, canonicalCtaLabel, CONSULT_CTA_ALLOWLIST } from './cta-labels';
import { canonicalTrustSource } from './company';
const FORBIDDEN_CTA_VARIANTS = /预约演示|预约体验|预约免费咨询|立即咨询|咨询专家/;
const SOURCE_ROOTS = ['src/app', 'src/components'];
function collectSourceFiles(dir: string, acc: string[] = []): string[] {
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
if (entry === '_archive') continue;
const stat = statSync(full);
if (stat.isDirectory()) {
collectSourceFiles(full, acc);
} else if (/\.(ts|tsx)$/.test(entry) && !/\.test\.tsx?$/.test(entry)) {
acc.push(full);
}
}
return acc;
}
describe('CTA 文案单一真源防线', () => {
it('CTA_LABELS.consult 固定为「预约咨询」', () => {
expect(CTA_LABELS.consult).toBe('预约咨询');
});
it('生产源码中不存在预约动作历史变体', () => {
const violations: string[] = [];
for (const root of SOURCE_ROOTS) {
for (const file of collectSourceFiles(root)) {
const lines = readFileSync(file, 'utf-8').split('\n');
lines.forEach((line, i) => {
if (FORBIDDEN_CTA_VARIANTS.test(line)) {
violations.push(`${file}:${i + 1}`);
}
});
}
}
expect(violations).toEqual([]);
});
});
describe('CMS 旧值渲染入口消毒', () => {
it('canonicalCtaLabel 精确匹配历史变体时归一为「预约咨询」', () => {
expect(canonicalCtaLabel('预约免费咨询')).toBe(CTA_LABELS.consult);
expect(canonicalCtaLabel('聊聊您的需求')).toBe(CTA_LABELS.consult);
expect(canonicalCtaLabel(' 预约演示 ')).toBe(CTA_LABELS.consult);
});
it('canonicalCtaLabel 放行正常/长文案与空值', () => {
expect(canonicalCtaLabel('成为首批共创客户')).toBe('成为首批共创客户');
expect(canonicalCtaLabel('让我们聊聊您的需求,看看能做什么')).toBe('让我们聊聊您的需求,看看能做什么');
expect(canonicalCtaLabel(undefined)).toBeUndefined();
expect(canonicalCtaLabel('')).toBeUndefined();
});
it('canonicalTrustSource 修复「如实标注」批注外泄', () => {
expect(canonicalTrustSource('如实标注')).toBe('公司公开声明');
expect(canonicalTrustSource('产品规格')).toBe('产品规格');
expect(canonicalTrustSource(undefined)).toBeUndefined();
});
});
describe('/contact 预约 CTA 白名单强制(复评 P2)', () => {
// 逐字符扫描:定位 href="/contact",跳过开始标签(正确处理 onClick={() => ...} 里的 `=>`),
// 取「开始标签结束 `>`」与「首个 `<`」之间的文本子节点作为按钮文案。
const HREF = 'href="/contact"';
function scan(text: string, file: string, violations: string[]) {
let from = 0;
let idx: number;
while ((idx = text.indexOf(HREF, from)) !== -1) {
from = idx + HREF.length;
// 找到闭合开始标签的 `>`(前一个字符不是 `=`,以跳过箭头函数 `=>`)
let j = from;
while (j < text.length && !(text[j] === '>' && text[j - 1] !== '=')) j++;
if (j >= text.length) break;
let k = j + 1;
while (k < text.length && text[k] !== '<') k++;
const raw = text.slice(j + 1, k).trim();
if (raw.startsWith('{')) continue; // 表达式文案,运行时收敛
const label = raw.replace(/\s+/g, '');
if (!label) continue; // 图标优先子节点或自闭合
if (!CONSULT_CTA_ALLOWLIST.has(label)) {
const line = text.slice(0, idx).split('\n').length;
violations.push(`${file}:${line} → 「${label}」`);
}
}
}
it('href="/contact" 的 CTA 字面文案必须等于规范值或在白名单内', () => {
const violations: string[] = [];
for (const root of SOURCE_ROOTS) {
for (const file of collectSourceFiles(root)) {
scan(readFileSync(file, 'utf-8'), file, violations);
}
}
expect(violations).toEqual([]);
});
});
+51
View File
@@ -0,0 +1,51 @@
/**
* CTA_LABELS — 全站「预约动作」按钮文案单一真源。
*
* DESIGN.md 约束:CTA 文案不得自由发挥,预约动作全站统一「预约咨询」。
* 2026-09-19 critique P1:预约动作曾并存「预约免费咨询 / 预约体验 / 预约演示 /
* 聊聊您的需求」等变体,机械防线见同目录 cta-labels.test.ts。
*/
export const CTA_LABELS = {
consult: '预约咨询',
} as const;
/**
* CMS pageCopy 里可能仍存有历史预约按钮变体(seed 先于常量修正写入库)。
* 仅做「整串精确匹配」替换——长文案/正文句子不受影响。
* 根治方式是 admin 更新数据,此处是渲染入口的最后一道防线。
*/
const STALE_CONSULT_VARIANTS = new Set([
'预约演示',
'预约体验',
'预约免费咨询',
'立即咨询',
'咨询专家',
'聊聊您的需求',
]);
export function canonicalCtaLabel(label?: string | null): string | undefined {
if (!label) return undefined;
return STALE_CONSULT_VARIANTS.has(label.trim()) ? CTA_LABELS.consult : label;
}
/**
* /contact 预约意图 CTA 的白名单(复评 P2:咨询词汇漂移)。
*
* 除规范「预约咨询」外,仅允许下列「语义不同」的按钮保留自有文案——它们不是通用预约,
* 强改成「预约咨询」反而失真:
* - 「获取上线通知」:内测产品订阅发布提醒,非咨询。
* - 「免费诊断咨询」/「预约免费诊断」:ERP 升级页的窄口径限时 offer。
* - 「联系我们的技术团队」:错误恢复页的技术支持出口,语境不同。
* - 「了解共创合作」:内测产品页早期共创说明卡的内联次级链接,非通用预约。
* 其余任何 href="/contact" 的 CTA 文案都必须等于 CTA_LABELS.consult。
* 机械防线见同目录 cta-labels.test.ts。
*/
export const CONSULT_CTA_ALLOWLIST: ReadonlySet<string> = new Set([
CTA_LABELS.consult,
'获取上线通知',
'免费诊断咨询',
'预约免费诊断',
'联系我们的技术团队',
'了解共创合作',
]);
+74
View File
@@ -0,0 +1,74 @@
/**
* 字号下限机械防线(2026-09-19 复评 P3 · 微字号离坡):
* 用户裁定 10/11px 大写 tracking 微标签属有意的 Bain 账本风格,全部原样保留、不做视觉改动;
* 本防线仅禁止「再引入」绝对像素 <10px 的字号,防止未来漂移。
* 扫描范围:src/app + src/components 的 .ts/.tsx/.css(排除测试文件与 _archive 归档)。
* 说明:只匹配明确的 px 字面量(`text-[Npx]` / `font-size: Npx`),不解析 rem——
* 因 html 根为 18px,rem→px 换算存在歧义,纳入会造成误报/漏报。px 是 detect 计数与漂移的主因。
*/
import { readdirSync, readFileSync, statSync, existsSync } from 'fs';
import { join } from 'path';
const SOURCE_ROOTS = ['src/app', 'src/components'];
const FONT_FLOOR_PX = 10;
const PATTERNS: RegExp[] = [
/text-\[(\d+(?:\.\d+)?)px\]/g,
/font-size:\s*(\d+(?:\.\d+)?)px/g,
];
/** 返回该文本内所有 <10px 字号字面量(`行号: 命中串`)。抽出为纯函数以便单元测试其活性。 */
export function findSubTenPxLines(text: string): string[] {
const hits: string[] = [];
text.split('\n').forEach((line, i) => {
for (const re of PATTERNS) {
re.lastIndex = 0;
for (const m of line.matchAll(re)) {
const px = Number.parseFloat(m[1] ?? '');
if (Number.isFinite(px) && px < FONT_FLOOR_PX) hits.push(`${i + 1}: ${m[0]}`);
}
}
});
return hits;
}
function collectSourceFiles(dir: string, acc: string[] = []): string[] {
if (!existsSync(dir)) return acc;
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
if (entry === '_archive') continue;
const stat = statSync(full);
if (stat.isDirectory()) {
collectSourceFiles(full, acc);
} else if (/\.(ts|tsx|css)$/.test(entry) && !/\.test\.tsx?$/.test(entry)) {
acc.push(full);
}
}
return acc;
}
describe('字号下限防线(禁止再引入 <10px)', () => {
it('检测器能命中 <10px 字面量,且放行 10/11px 有意下限(防匹配零的假绿)', () => {
expect(findSubTenPxLines('className="text-[9px]"')).toHaveLength(1);
expect(findSubTenPxLines('base { font-size: 8px; }')).toHaveLength(1);
expect(findSubTenPxLines('text-[10px] text-[11px] font-size: 12px')).toHaveLength(0);
});
it('检测器确实覆盖仓库现存的 10/11px 微标签(证明模式在真实源码中匹配而非空转)', () => {
const files = SOURCE_ROOTS.flatMap((root) => collectSourceFiles(root));
const tenOrEleven = files.some((f) =>
/text-\[1[01]px\]/.test(readFileSync(f, 'utf-8')),
);
expect(tenOrEleven).toBe(true);
});
it('生产源码不得存在 <10px 字号字面量', () => {
const violations: string[] = [];
for (const file of SOURCE_ROOTS.flatMap((root) => collectSourceFiles(root))) {
for (const hit of findSubTenPxLines(readFileSync(file, 'utf-8'))) {
violations.push(`${file}:${hit}`);
}
}
expect(violations).toEqual([]);
});
});
+65
View File
@@ -0,0 +1,65 @@
/**
* 结果型数字口径机械防线(2026-09-19 critique P0):
* 「目标口径,非既成结果」必须来自 METRICS_BASIS_NOTE 单一真源;
* 且每个呈现结果型数字的营销页必须接入 MetricsBasisNote。
* 扫描范围:src/app + src/components 的 .ts/.tsx(排除测试文件与 _archive 归档)。
*/
import { readdirSync, readFileSync, statSync } from 'fs';
import { join } from 'path';
import { METRICS_BASIS_NOTE } from './metrics-basis';
const SOURCE_ROOTS = ['src/app', 'src/components'];
/** 呈现结果型数字、必须接入口径角注的页面/组件源文件。 */
const REQUIRED_ANNOTATED_SOURCES = [
'src/app/(marketing)/products/products-content-v3.tsx',
'src/app/(marketing)/solutions/solutions-content-v3.tsx',
'src/app/(marketing)/services/services-content-v3.tsx',
'src/app/(marketing)/home-content-v15.tsx',
];
function collectSourceFiles(dir: string, acc: string[] = []): string[] {
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
if (entry === '_archive') continue;
const stat = statSync(full);
if (stat.isDirectory()) {
collectSourceFiles(full, acc);
} else if (/\.(ts|tsx)$/.test(entry) && !/\.test\.tsx?$/.test(entry)) {
acc.push(full);
}
}
return acc;
}
describe('结果型数字口径角注防线', () => {
it('METRICS_BASIS_NOTE 固定为「目标口径,非既成结果」', () => {
expect(METRICS_BASIS_NOTE).toBe('目标口径,非既成结果');
});
it('生产源码不得硬编码口径角注字面量(必须引用单一真源)', () => {
const violations: string[] = [];
for (const root of SOURCE_ROOTS) {
for (const file of collectSourceFiles(root)) {
if (file.endsWith('lib/constants/metrics-basis.ts')) continue;
const lines = readFileSync(file, 'utf-8').split('\n');
lines.forEach((line, i) => {
if (line.includes(METRICS_BASIS_NOTE)) {
violations.push(`${file}:${i + 1}`);
}
});
}
}
expect(violations).toEqual([]);
});
it('结果型数字页面均接入 MetricsBasisNote', () => {
for (const file of REQUIRED_ANNOTATED_SOURCES) {
const src = readFileSync(file, 'utf-8');
expect({ file, used: src.includes('<MetricsBasisNote') }).toEqual({
file,
used: true,
});
}
});
});
+9
View File
@@ -0,0 +1,9 @@
/**
* METRICS_BASIS_NOTE — 全站「结果型数字」口径角注单一真源。
*
* 2026-09-19 critique P0:solutions / services / home / about 把「30% 库存周转提升」
* 「99.9% 可用性」这类目标值/能力值以既成结果口吻呈现,缺出处即构成误导。
* 与 CTA_LABELS 同属渲染入口的诚实性防线:数字保留,但强制附口径说明。
* 根治方式是补充真实案例数据或 admin 修正内容,此处为最后一道防线。
*/
export const METRICS_BASIS_NOTE = '目标口径,非既成结果';