"use client";
import { Card, CardContent } from "@/components/ui/card";
import { cn } from "@/lib/utils";
import {
TrendingUp,
TrendingDown,
Minus,
AlertCircle,
CheckCircle,
XCircle,
HelpCircle,
} from "lucide-react";
import { HealthLevel, HEALTH_LEVEL_CONFIG } from "@/types/dashboard-health";
import { getTrendStyle, getCompetitorStatus } from "@/lib/dashboard-health";
interface OverviewCardProps {
className?: string;
children: React.ReactNode;
}
function OverviewCard({ className, children }: OverviewCardProps) {
return (
{children}
);
}
// 综合评分卡片
interface HealthScoreCardProps {
score: number;
healthLevel?: HealthLevel;
}
export function HealthScoreCard({ score, healthLevel }: HealthScoreCardProps) {
const level =
healthLevel ??
(score >= 80
? "excellent"
: score >= 60
? "good"
: score >= 40
? "pass"
: "danger");
const config = HEALTH_LEVEL_CONFIG[level];
const LevelIcon = {
excellent: CheckCircle,
good: HelpCircle,
pass: AlertCircle,
danger: XCircle,
}[level];
return (
{/* 标签 */}
综合评分
/100
{/* 大数字 */}
{score.toFixed(0)}
{/* 健康等级标签 */}
{config.label}
);
}
// 竞品地位卡片
interface CompetitorStatusCardProps {
ahead: number;
behind: number;
}
export function CompetitorStatusCard({
ahead,
behind,
}: CompetitorStatusCardProps) {
const status = getCompetitorStatus(ahead, behind);
const statusIcon =
status.status === "leading" ? (
) : status.status === "trailing" ? (
) : (
);
return (
竞品地位
{statusIcon}
{ahead > 0
? `领先${ahead}竞品`
: behind > 0
? `落后${behind}竞品`
: status.label}
{ahead > 0 && behind > 0 && (
领先{ahead}个
落后{behind}个
)}
);
}
// 趋势卡片
interface TrendCardProps {
change: number;
label?: string;
}
export function TrendCard({ change, label = "较上周" }: TrendCardProps) {
const trend = getTrendStyle(change);
const TrendIcon =
trend.icon === "up"
? TrendingUp
: trend.icon === "down"
? TrendingDown
: Minus;
return (
);
}
// 监控平台卡片
interface MonitorPlatformCardProps {
monitored: number;
total: number;
}
export function MonitorPlatformCard({
monitored,
total,
}: MonitorPlatformCardProps) {
const progress = total > 0 ? (monitored / total) * 100 : 0;
const isFull = monitored === total;
return (
监控平台
{isFull ? "全部监控" : "部分监控"}
{monitored}
/{total}
{/* 进度条 */}
平台监控中
);
}
// 概览卡片组
interface OverviewCardsProps {
score: number;
healthLevel?: HealthLevel;
ahead: number;
behind: number;
change: number;
monitored: number;
total: number;
}
export function OverviewCards({
score,
healthLevel,
ahead,
behind,
change,
monitored,
total,
}: OverviewCardsProps) {
return (
);
}