"use client"; import { useEffect, useState } from "react"; import { RefreshCcw } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { opsApi } from "@/lib/ops-api"; type FunnelStep = { label: string; count: number; pct_of_prev?: number }; export function AnalyticsPageClient() { const [loading, setLoading] = useState(true); const [funnel, setFunnel] = useState([]); const [days, setDays] = useState(30); const load = async () => { setLoading(true); try { const data = await opsApi.funnel(days); const steps = (data as unknown as { steps?: FunnelStep[] }).steps ?? []; setFunnel(steps); } catch { /* */ } setLoading(false); }; useEffect(() => { void load(); }, [days]); const maxCount = Math.max(...funnel.map((s) => s.count), 1); if (loading) return
加载中...
; return (

转化分析

{[7, 14, 30].map((d) => ( ))}
用户转化漏斗
{funnel.map((step, i) => { const pct = (step.count / maxCount) * 100; const prevPct = step.pct_of_prev != null ? `${step.pct_of_prev}%` : "—"; return (
{step.label} {step.count} 转化 {prevPct}
); })} {funnel.length === 0 && (

暂无数据

)}
); }