diff --git a/src/app/(marketing)/products/erp-upgrade-v3/page.tsx b/src/app/(marketing)/products/erp-upgrade-v3/page.tsx index 1af978ae..a11f7fb3 100644 --- a/src/app/(marketing)/products/erp-upgrade-v3/page.tsx +++ b/src/app/(marketing)/products/erp-upgrade-v3/page.tsx @@ -63,7 +63,8 @@ export default async function ERPUpgradeV3Page() { testIdPrefix="erp-upgrade-hero" /> - + {/* V3 页下方 DetailTrustSection 已渲染同一组 dataProofs,此处关闭避免同组指标重复两遍 */} + (null); const isInView = useInView(ref, { once: true }); - const numericValue = parseFloat(value.replace(/[^0-9.]/g, '')); - const suffix = value.replace(/[0-9.]/g, ''); + const parsed = parseMetricValue(value); + const { numeric: numericValue, prefix, suffix } = parsed; const [displayValue, setDisplayValue] = useState('0'); // 动画必须在 effect 中驱动并在卸载/重跑时取消。历史写法在 render 体内 setState + @@ -75,7 +78,7 @@ function MetricCard({ // 相互竞争且从不取消(Q-6)。 useEffect(() => { if (!isInView) return; - if (isNaN(numericValue)) { + if (numericValue === null) { setDisplayValue(value); return; } @@ -86,15 +89,17 @@ function MetricCard({ const progress = Math.min((currentTime - startTime) / 2000, 1); const easeOutQuart = 1 - Math.pow(1 - progress, 4); setDisplayValue( - Number.isInteger(numericValue) - ? Math.floor(numericValue * easeOutQuart).toString() + suffix - : (numericValue * easeOutQuart).toFixed(1) + suffix, + prefix + + (Number.isInteger(numericValue) + ? Math.floor(numericValue * easeOutQuart).toString() + : (numericValue * easeOutQuart).toFixed(1)) + + suffix, ); if (progress < 1) frame = requestAnimationFrame(animate); }; frame = requestAnimationFrame(animate); return () => cancelAnimationFrame(frame); - }, [isInView, numericValue, suffix, value]); + }, [isInView, numericValue, prefix, suffix, value]); return (
@@ -118,7 +123,7 @@ function MetricCard({ ); } -export function ProductValueSection({ product }: ProductValueSectionProps) { +export function ProductValueSection({ product, showDataProofs = true }: ProductValueSectionProps) { return (
@@ -246,7 +251,7 @@ export function ProductValueSection({ product }: ProductValueSectionProps) {
{/* 数据证明 */} - {product.dataProofs && product.dataProofs.length > 0 && ( + {showDataProofs && product.dataProofs && product.dataProofs.length > 0 && ( { if (!isInView) return; - const numericValue = parseFloat(value.replace(/[^0-9.]/g, '')); - if (isNaN(numericValue)) { + const parsed = parseMetricValue(value); + const numericValue = parsed.numeric; + if (numericValue === null) { setDisplayValue(value); return; } - - const [, prefix = '', suffix = ''] = value.match(/^([^\d.]*)[\d.]+([^\d.]*)$/) ?? []; + const { prefix, suffix } = parsed; const finalText = prefix + (Number.isInteger(numericValue) ? numericValue.toString() : numericValue.toFixed(1)) + diff --git a/src/components/detail/detail.test.tsx b/src/components/detail/detail.test.tsx index f3a815d9..1ac8d014 100644 --- a/src/components/detail/detail.test.tsx +++ b/src/components/detail/detail.test.tsx @@ -314,6 +314,38 @@ describe('ProductValueSection', () => { } }); + // ── DEF-06/07:区间/多数字指标不得被拼成一个数 ── + describe('指标计数动画的取值解析(DEF-06/07)', () => { + it('区间值 `3-6个月` 不被渲染成 `36`', async () => { + const { ProductValueSection } = await import('./detail-product-value'); + const rangeProduct = { + ...mockProduct, + dataProofs: [{ metric: '实施周期', value: '3-6个月', description: '典型交付周期' }], + }; + render(); + // 旧实现 `value.replace(/[^0-9.]/g,'')` ⇒ 36,`-` 与 `个月` 被丢掉 + expect(screen.queryByText('36')).not.toBeInTheDocument(); + expect(screen.getByText(/3-6个月/)).toBeInTheDocument(); + }); + + it('DetailTrustSection 的计数器同样不把 `3–6 个月` 拼成 `36`', async () => { + const { DetailTrustSection } = await import('./detail-trust-section'); + render( + + ); + expect(screen.queryByText('36')).not.toBeInTheDocument(); + expect(screen.getByText(/3–6 个月/)).toBeInTheDocument(); + }); + }); + + it('showDataProofs=false 时整块不渲染(V3 去重)', async () => { + const { ProductValueSection } = await import('./detail-product-value'); + render(); + expect(screen.queryByText('以可量化的目标约束交付')).not.toBeInTheDocument(); + }); + }); describe('DetailTrustSection', () => {