"use client" import { useState } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" 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 { Database, Plus, RefreshCw, Settings, Brain, Play } from "lucide-react" import BottomTabs from "@/components/nav/bottom-tabs" interface DataSource { id: string name: string description: string type: string records: string lastSync: string status: "connected" | "disconnected" | "syncing" } interface AIModel { id: string name: string type: string accuracy: string algorithm: string features: number lastTrained: string status: "ready" | "training" | "error" } const mockDataSources: DataSource[] = [ { id: "wechat-db", name: "微信用户数据库", description: "存储微信用户基础信息和行为数据", type: "MySQL", records: "2.5B", lastSync: "2024/1/15 18:30:00", status: "connected", }, { id: "traffic-keywords", name: "流量关键词库", description: "搜索引擎关键词和流量数据", type: "PostgreSQL", records: "150.0K", lastSync: "2024/1/15 17:45:00", status: "connected", }, { id: "user-behavior", name: "用户行为日志", description: "用户操作行为和交互记录", type: "MongoDB", records: "1.5B", lastSync: "2024/1/15 19:00:00", status: "syncing", }, ] const mockAIModels: AIModel[] = [ { id: "user-value-prediction", name: "用户价值预测模型", type: "Classification", accuracy: "92.0%", algorithm: "RandomForest", features: 25, lastTrained: "2024/1/14 23:30:00", status: "ready", }, { id: "traffic-trend-analysis", name: "流量趋势分析模型", type: "Regression", accuracy: "87.0%", algorithm: "LSTM", features: 15, lastTrained: "2024/1/15 16:00:00", status: "training", }, { id: "user-clustering", name: "用户聚类模型", type: "Clustering", accuracy: "89.0%", algorithm: "KMeans", features: 20, lastTrained: "2024/1/13 20:00:00", status: "ready", }, ] export default function DataPlatformPage() { const [activeTab, setActiveTab] = useState("datasource") const [dataSources, setDataSources] = useState(mockDataSources) const [aiModels, setAIModels] = useState(mockAIModels) const [syncing, setSyncing] = useState(null) const [training, setTraining] = useState(null) const [showAddDialog, setShowAddDialog] = useState(false) const [newDataSource, setNewDataSource] = useState({ name: "", description: "", type: "MySQL", host: "", port: "", database: "", username: "", password: "", }) const handleSync = async (sourceId: string) => { setSyncing(sourceId) setTimeout(() => { setSyncing(null) setDataSources((prev) => prev.map((source) => source.id === sourceId ? { ...source, lastSync: new Date().toLocaleString("zh-CN") } : source, ), ) }, 2000) } const handleRetrain = async (modelId: string) => { setTraining(modelId) setTimeout(() => { setTraining(null) setAIModels((prev) => prev.map((model) => model.id === modelId ? { ...model, lastTrained: new Date().toLocaleString("zh-CN") } : model, ), ) }, 3000) } const handleAddDataSource = () => { const newSource: DataSource = { id: `datasource-${Date.now()}`, name: newDataSource.name, description: newDataSource.description, type: newDataSource.type, records: "0", lastSync: "从未同步", status: "disconnected", } setDataSources((prev) => [...prev, newSource]) setNewDataSource({ name: "", description: "", type: "MySQL", host: "", port: "", database: "", username: "", password: "", }) setShowAddDialog(false) } const getStatusBadge = (status: DataSource["status"]) => { switch (status) { case "connected": return Connected case "disconnected": return Disconnected case "syncing": return Syncing default: return Unknown } } const getModelStatusBadge = (status: AIModel["status"]) => { switch (status) { case "ready": return Ready case "training": return Training case "error": return Error default: return Unknown } } return (

数据中台

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

{activeTab === "datasource" ? ( 添加新数据源
setNewDataSource({ ...newDataSource, name: e.target.value })} className="col-span-3" />
setNewDataSource({ ...newDataSource, description: e.target.value })} className="col-span-3" />
setNewDataSource({ ...newDataSource, host: e.target.value })} className="col-span-3" placeholder="localhost" />
setNewDataSource({ ...newDataSource, port: e.target.value })} className="col-span-3" placeholder="3306" />
) : ( )}
数据源管理 AI模型

数据源管理

{dataSources.map((source) => (
{source.name}

{source.description}

类型:{source.type}
记录数:{source.records}
{getStatusBadge(syncing === source.id ? "syncing" : source.status)}
最后同步:{source.lastSync}
))}

AI模型管理

{aiModels.map((model) => (
{model.name}

{model.type} 模型

准确率 {model.accuracy}
算法:{model.algorithm}
特征数:{model.features}
{getModelStatusBadge(training === model.id ? "training" : model.status)}
最后训练:{model.lastTrained}
{model.status === "ready" ? ( ) : model.status === "training" ? ( ) : ( )}
))}
) }