"use client" import { useState } from "react" import { Boxes, Plus, Search, Play, Settings, CheckCircle, Clock, AlertTriangle, GitBranch, BarChart3, Cpu, TrendingUp, } from "lucide-react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { UploadModelDialog } from "@/components/dialogs/upload-model-dialog" interface Model { id: string name: string type: "preset" | "custom" category: "clv" | "rfm" | "churn" | "fraud" | "segment" version: string status: "online" | "training" | "testing" | "offline" accuracy: number precision: number recall: number f1Score: number lastTrained: string inputFeatures: string[] outputFormat: string updateFrequency: string description: string } const MOCK_MODELS: Model[] = [ { id: "1", name: "CLV预测模型", type: "preset", category: "clv", version: "v2.3.1", status: "online", accuracy: 87.5, precision: 85.2, recall: 89.1, f1Score: 87.1, lastTrained: "2025-12-10", inputFeatures: ["历史消费金额", "消费频次", "注册时长", "活跃度"], outputFormat: "CLV分数 (0-100)", updateFrequency: "每周", description: "基于用户历史行为预测客户终身价值", }, { id: "2", name: "RFM评分模型", type: "preset", category: "rfm", version: "v1.5.0", status: "online", accuracy: 92.3, precision: 91.5, recall: 93.2, f1Score: 92.3, lastTrained: "2025-12-11", inputFeatures: ["最近消费时间", "消费频率", "消费金额"], outputFormat: "R/F/M各维度评分 (0-100)", updateFrequency: "每天", description: "基于RFM模型的用户价值分层", }, { id: "3", name: "流失预警模型", type: "preset", category: "churn", version: "v3.1.2", status: "online", accuracy: 85.8, precision: 87.3, recall: 84.2, f1Score: 85.7, lastTrained: "2025-12-09", inputFeatures: ["活跃度变化", "消费趋势", "投诉记录", "登录频次"], outputFormat: "流失概率 (0-1)", updateFrequency: "每天", description: "预测用户未来30天流失概率", }, { id: "4", name: "欺诈检测模型", type: "preset", category: "fraud", version: "v2.0.0", status: "online", accuracy: 96.2, precision: 94.8, recall: 97.5, f1Score: 96.1, lastTrained: "2025-12-08", inputFeatures: ["交易金额", "交易频率", "设备信息", "地理位置"], outputFormat: "欺诈风险等级 (低/中/高)", updateFrequency: "实时", description: "实时检测可疑交易行为", }, { id: "5", name: "用户分群模型", type: "custom", category: "segment", version: "v1.0.0", status: "training", accuracy: 78.5, precision: 76.2, recall: 80.1, f1Score: 78.1, lastTrained: "2025-12-12", inputFeatures: ["消费行为", "浏览偏好", "互动记录", "人口属性"], outputFormat: "用户群体标签", updateFrequency: "每周", description: "基于多维特征的用户自动分群", }, ] const CATEGORY_CONFIG = { clv: { label: "CLV模型", color: "bg-blue-100 text-blue-700" }, rfm: { label: "RFM模型", color: "bg-green-100 text-green-700" }, churn: { label: "流失预警", color: "bg-orange-100 text-orange-700" }, fraud: { label: "欺诈检测", color: "bg-red-100 text-red-700" }, segment: { label: "用户分群", color: "bg-purple-100 text-purple-700" }, } const STATUS_CONFIG = { online: { label: "已上线", color: "bg-green-100 text-green-700", icon: CheckCircle }, training: { label: "训练中", color: "bg-blue-100 text-blue-700", icon: Cpu }, testing: { label: "测试中", color: "bg-yellow-100 text-yellow-700", icon: Clock }, offline: { label: "已下线", color: "bg-gray-100 text-gray-700", icon: AlertTriangle }, } export default function ModelManagementPage() { const [models, setModels] = useState(MOCK_MODELS) const [searchQuery, setSearchQuery] = useState("") const [selectedModel, setSelectedModel] = useState(null) const [showUploadDialog, setShowUploadDialog] = useState(false) const stats = { total: models.length, online: models.filter((m) => m.status === "online").length, avgAccuracy: (models.reduce((sum, m) => sum + m.accuracy, 0) / models.length).toFixed(1), presetModels: models.filter((m) => m.type === "preset").length, } return (
{/* Header */}

模型管理

管理价值评估算法模型

{/* Stats */}
总模型数
{stats.total}
已上线
{stats.online}
平均准确率
{stats.avgAccuracy}%
预置模型
{stats.presetModels}
{/* Search */}
setSearchQuery(e.target.value)} className="pl-10 bg-white/60" />
{/* Model List */}
{models .filter((m) => m.name.toLowerCase().includes(searchQuery.toLowerCase())) .map((model) => { const StatusIcon = STATUS_CONFIG[model.status].icon return ( setSelectedModel(model)} >

{model.name}

{CATEGORY_CONFIG[model.category].label}

{model.description}

{STATUS_CONFIG[model.status].label}
{model.accuracy}%
准确率
{model.precision}%
精确率
{model.recall}%
召回率
{model.f1Score}%
F1分数
版本: {model.version} 更新: {model.updateFrequency}
) })}
{/* Model Detail Panel */} {selectedModel && ( 模型详情: {selectedModel.name}

输入特征

{selectedModel.inputFeatures.map((feature, i) => (
{feature}
))}

输出格式

{selectedModel.outputFormat}

模型指标

准确率 {selectedModel.accuracy}%
精确率 {selectedModel.precision}%
召回率 {selectedModel.recall}%
)}
) }