feat(ui): 保时捷语法复刻收尾(ADR-0008/0009/0011/0012/0013) #65
No files matched your search
@@ -63,7 +63,8 @@ export default async function ERPUpgradeV3Page() {
|
||||
testIdPrefix="erp-upgrade-hero"
|
||||
/>
|
||||
|
||||
<ProductValueSection product={data as unknown as Product} />
|
||||
{/* V3 页下方 DetailTrustSection 已渲染同一组 dataProofs,此处关闭避免同组指标重复两遍 */}
|
||||
<ProductValueSection product={data as unknown as Product} showDataProofs={false} />
|
||||
|
||||
<L3EmptyFallback caseStudies={caseStudies} dataProofs={dataProofs} certifications={certifications} />
|
||||
<DetailTrustSection
|
||||
|
||||
@@ -17,9 +17,12 @@ import {
|
||||
import type { Product } from '@/lib/constants/products';
|
||||
import { MetricsBasisNote } from '@/components/ui/metrics-basis-note';
|
||||
import { weakestBasis } from '@/lib/constants/metrics-basis';
|
||||
import { parseMetricValue } from './metric-value';
|
||||
|
||||
interface ProductValueSectionProps {
|
||||
product: Product;
|
||||
/** V3 页同时渲染 DetailTrustSection 的 dataProofs;关闭本块避免同一组指标重复两次。 */
|
||||
showDataProofs?: boolean;
|
||||
}
|
||||
|
||||
const featureIcons: LucideIcon[] = [Zap, Shield, TrendingUp, Cpu];
|
||||
@@ -66,8 +69,8 @@ function MetricCard({
|
||||
const ref = useRef<HTMLDivElement>(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 (
|
||||
<div className="bain-card p-8">
|
||||
@@ -118,7 +123,7 @@ function MetricCard({
|
||||
);
|
||||
}
|
||||
|
||||
export function ProductValueSection({ product }: ProductValueSectionProps) {
|
||||
export function ProductValueSection({ product, showDataProofs = true }: ProductValueSectionProps) {
|
||||
return (
|
||||
<section className="relative bg-bg-primary py-20 sm:py-28 md:py-36 overflow-hidden">
|
||||
<div className="max-w-container mx-auto px-4 sm:px-6 lg:px-10 relative">
|
||||
@@ -246,7 +251,7 @@ export function ProductValueSection({ product }: ProductValueSectionProps) {
|
||||
</div>
|
||||
|
||||
{/* 数据证明 */}
|
||||
{product.dataProofs && product.dataProofs.length > 0 && (
|
||||
{showDataProofs && product.dataProofs && product.dataProofs.length > 0 && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 32 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { CaseStudy, DataProof, Certification } from '@/lib/constants/produc
|
||||
import { MetricsBasisNote } from '@/components/ui/metrics-basis-note';
|
||||
import { weakestBasis } from '@/lib/constants/metrics-basis';
|
||||
import { gateCaseItems } from '@/lib/constants/case-publish-gate';
|
||||
import { parseMetricValue } from './metric-value';
|
||||
|
||||
interface DetailTrustSectionProps {
|
||||
caseStudies?: CaseStudy[];
|
||||
@@ -26,13 +27,13 @@ function AnimatedCounter({ value, duration = 2000 }: { value: string; duration?:
|
||||
useEffect(() => {
|
||||
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)) +
|
||||
|
||||
@@ -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(<ProductValueSection product={rangeProduct} />);
|
||||
// 旧实现 `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(
|
||||
<DetailTrustSection
|
||||
dataProofs={[{ metric: '交付周期', value: '3–6 个月', description: '典型周期' }]}
|
||||
/>
|
||||
);
|
||||
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(<ProductValueSection product={mockProduct} showDataProofs={false} />);
|
||||
expect(screen.queryByText('以可量化的目标约束交付')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('DetailTrustSection', () => {
|
||||
|
||||
Reference in new issue
Block a user