"use client" import { useState } from "react" import { Database, Plus, Settings, Play, Pause, RotateCcw, Brain, Zap, CheckCircle, AlertCircle } from "lucide-react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Textarea } from "@/components/ui/textarea" import { Switch } from "@/components/ui/switch" interface DataSource { id: string name: string type: string status: "connected" | "disconnected" | "syncing" lastSync: string recordCount: number description: string } interface AIModel { id: string name: string type: string status: "training" | "ready" | "error" accuracy: number lastTrained: string parameters: Record } export default function DataPlatformPage() { const [dataSources, setDataSources] = useState([ { id: "ds_001", name: "微信用户数据库", type: "MySQL", status: "connected", lastSync: "2024-01-15T10:30:00Z", recordCount: 2500000000, description: "存储微信用户基础信息和行为数据", }, { id: "ds_002", name: "流量关键词库", type: "PostgreSQL", status: "connected", lastSync: "2024-01-15T09:45:00Z", recordCount: 150000, description: "搜索引擎关键词和流量数据", }, { id: "ds_003", name: "用户行为日志", type: "MongoDB", status: "syncing", lastSync: "2024-01-15T11:00:00Z", recordCount: 1500000000, description: "用户操作行为和交互记录", }, ]) const [aiModels, setAiModels] = useState([ { id: "model_001", name: "用户价值预测模型", type: "Classification", status: "ready", accuracy: 0.92, lastTrained: "2024-01-14T15:30:00Z", parameters: { algorithm: "RandomForest", features: 25, epochs: 100, learningRate: 0.01, }, }, { id: "model_002", name: "流量趋势分析模型", type: "Regression", status: "training", accuracy: 0.87, lastTrained: "2024-01-15T08:00:00Z", parameters: { algorithm: "LSTM", features: 15, epochs: 200, learningRate: 0.001, }, }, { id: "model_003", name: "用户聚类模型", type: "Clustering", status: "ready", accuracy: 0.89, lastTrained: "2024-01-13T12:00:00Z", parameters: { algorithm: "KMeans", clusters: 8, features: 20, iterations: 300, }, }, ]) const [isAddingDataSource, setIsAddingDataSource] = useState(false) const [isTrainingModel, setIsTrainingModel] = useState(false) const [newDataSource, setNewDataSource] = useState({ name: "", type: "MySQL", host: "", port: "", database: "", username: "", password: "", description: "", }) const [modelTrainingConfig, setModelTrainingConfig] = useState({ modelId: "", algorithm: "RandomForest", features: 25, epochs: 100, learningRate: 0.01, validationSplit: 0.2, autoTune: true, }) // 添加数据源 const handleAddDataSource = async () => { try { const newSource: DataSource = { id: `ds_${Date.now()}`, name: newDataSource.name, type: newDataSource.type, status: "connected", lastSync: new Date().toISOString(), recordCount: 0, description: newDataSource.description, } setDataSources((prev) => [...prev, newSource]) setIsAddingDataSource(false) setNewDataSource({ name: "", type: "MySQL", host: "", port: "", database: "", username: "", password: "", description: "", }) // 模拟数据导入 setTimeout(() => { setDataSources((prev) => prev.map((ds) => ds.id === newSource.id ? { ...ds, recordCount: Math.floor(Math.random() * 1000000) + 10000, status: "connected" as const } : ds, ), ) }, 2000) } catch (error) { console.error("添加数据源失败:", error) } } // 同步数据源 const handleSyncDataSource = (id: string) => { setDataSources((prev) => prev.map((ds) => (ds.id === id ? { ...ds, status: "syncing" as const, lastSync: new Date().toISOString() } : ds)), ) // 模拟同步完成 setTimeout(() => { setDataSources((prev) => prev.map((ds) => ds.id === id ? { ...ds, status: "connected" as const, recordCount: ds.recordCount + Math.floor(Math.random() * 10000), lastSync: new Date().toISOString(), } : ds, ), ) }, 3000) } // 训练AI模型 const handleTrainModel = async () => { if (!modelTrainingConfig.modelId) return setIsTrainingModel(true) // 更新模型状态为训练中 setAiModels((prev) => prev.map((model) => model.id === modelTrainingConfig.modelId ? { ...model, status: "training" as const } : model, ), ) // 模拟训练过程 setTimeout(() => { setAiModels((prev) => prev.map((model) => model.id === modelTrainingConfig.modelId ? { ...model, status: "ready" as const, accuracy: Math.random() * 0.1 + 0.85, lastTrained: new Date().toISOString(), parameters: { algorithm: modelTrainingConfig.algorithm, features: modelTrainingConfig.features, epochs: modelTrainingConfig.epochs, learningRate: modelTrainingConfig.learningRate, }, } : model, ), ) setIsTrainingModel(false) }, 5000) } // 格式化数字 const formatNumber = (num: number): string => { if (num >= 1000000000) { return `${(num / 1000000000).toFixed(1)}B` } if (num >= 1000000) { return `${(num / 1000000).toFixed(1)}M` } if (num >= 1000) { return `${(num / 1000).toFixed(1)}K` } return num.toString() } // 获取状态颜色 const getStatusColor = (status: string) => { switch (status) { case "connected": case "ready": return "text-green-600 bg-green-50 border-green-200" case "syncing": case "training": return "text-yellow-600 bg-yellow-50 border-yellow-200" case "disconnected": case "error": return "text-red-600 bg-red-50 border-red-200" default: return "text-gray-600 bg-gray-50 border-gray-200" } } // 获取状态图标 const getStatusIcon = (status: string) => { switch (status) { case "connected": case "ready": return case "syncing": case "training": return case "disconnected": case "error": return default: return } } return (
{/* 页面标题 */}

数据中台

数据源管理与AI模型训练平台

数据源管理 AI模型 {/* 数据源管理 */}

数据源管理

添加新数据源
setNewDataSource((prev) => ({ ...prev, name: e.target.value }))} placeholder="输入数据源名称" />
setNewDataSource((prev) => ({ ...prev, host: e.target.value }))} placeholder="localhost" />
setNewDataSource((prev) => ({ ...prev, port: e.target.value }))} placeholder="3306" />
setNewDataSource((prev) => ({ ...prev, database: e.target.value }))} placeholder="database_name" />
setNewDataSource((prev) => ({ ...prev, username: e.target.value }))} placeholder="username" />
setNewDataSource((prev) => ({ ...prev, password: e.target.value }))} placeholder="password" />