"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 { Input } from "@/components/ui/input" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Label } from "@/components/ui/label" import { Database, Plus, Search, RefreshCw, Settings, Trash2, PlayCircle, PauseCircle, CheckCircle2, AlertCircle, Clock, FileText, Server, Globe, Webhook, MoreVertical, Eye, Edit, Activity, } from "lucide-react" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" // 第二部分:数据接入 - 数据源管理 export default function DataSourcesPage() { const [activeTab, setActiveTab] = useState("all") const [searchQuery, setSearchQuery] = useState("") const [showAddDialog, setShowAddDialog] = useState(false) const [showSettingsDialog, setShowSettingsDialog] = useState(false) const [showLogsDialog, setShowLogsDialog] = useState(false) const [selectedSource, setSelectedSource] = useState(null) const [newSourceType, setNewSourceType] = useState("") // 数据源列表 const dataSources = [ { id: "1", name: "存客宝-MySQL主库", type: "mysql", status: "connected", host: "10.88.182.62:3305", database: "cunke_prod", lastSync: "2分钟前", recordCount: 12584567, syncFrequency: "实时", tables: 45, }, { id: "2", name: "触客宝-行为数据", type: "mysql", status: "connected", host: "10.88.182.63:3306", database: "chuke_behavior", lastSync: "5分钟前", recordCount: 89234156, syncFrequency: "5分钟", tables: 28, }, { id: "3", name: "数智员工-API接口", type: "api", status: "connected", endpoint: "https://api.shuzhi.com/v1", lastSync: "1分钟前", recordCount: 4567890, syncFrequency: "实时", apiCalls: 125680, }, { id: "4", name: "外部征信数据", type: "api", status: "warning", endpoint: "https://credit.external.com/api", lastSync: "30分钟前", recordCount: 234567, syncFrequency: "每小时", apiCalls: 8956, }, { id: "5", name: "Webhook-实时事件", type: "webhook", status: "connected", webhookUrl: "/api/webhook/events", lastSync: "实时", recordCount: 567890, syncFrequency: "实时", events: 45678, }, { id: "6", name: "腾讯云MySQL", type: "mysql", status: "disconnected", host: "56b4c23f6853c.gz.cdb.myqcloud.com:14413", database: "analytics_db", lastSync: "2小时前", recordCount: 0, syncFrequency: "停止", tables: 0, }, ] const getStatusBadge = (status: string) => { switch (status) { case "connected": return 已连接 case "warning": return 警告 case "disconnected": return 已断开 default: return 未知 } } const getTypeIcon = (type: string) => { switch (type) { case "mysql": return case "api": return case "webhook": return default: return } } const filteredSources = dataSources.filter((source) => { if (activeTab !== "all" && source.type !== activeTab) return false if (searchQuery && !source.name.toLowerCase().includes(searchQuery.toLowerCase())) return false return true }) const handleOpenSettings = (source: any) => { setSelectedSource(source) setShowSettingsDialog(true) } const handleOpenLogs = (source: any) => { setSelectedSource(source) setShowLogsDialog(true) } return (
{/* 顶部标题 */}

数据源管理

统一管理所有数据接入源,支持MySQL、API、Webhook等多种接入方式

{/* 统计卡片 */}

数据源总数

{dataSources.length}

已连接

{dataSources.filter((s) => s.status === "connected").length}

总记录数

107.2M

今日同步

2.3M

{/* 搜索和筛选 */}
setSearchQuery(e.target.value)} className="pl-9 bg-white" />
全部 MySQL API Webhook
{/* 数据源列表 */}
{filteredSources.map((source) => (
{getTypeIcon(source.type)}

{source.name}

{getStatusBadge(source.status)}

{source.type === "mysql" ? source.host : source.type === "api" ? source.endpoint : source.webhookUrl}

{source.lastSync} {source.recordCount.toLocaleString()} 条记录 同步频率: {source.syncFrequency}
handleOpenSettings(source)}> 设置 handleOpenLogs(source)}> 查看日志 立即同步 数据预览 删除
))}
{/* 添加数据源弹窗 */} 添加数据源 选择数据源类型并配置连接参数
{[ { type: "mysql", label: "MySQL数据库", icon: Database, desc: "连接MySQL/MariaDB数据库" }, { type: "api", label: "REST API", icon: Globe, desc: "通过API接口获取数据" }, { type: "webhook", label: "Webhook", icon: Webhook, desc: "接收实时推送数据" }, ].map((item) => ( ))}
{newSourceType === "mysql" && (
)} {newSourceType === "api" && (
)} {newSourceType === "webhook" && (
https://your-domain.com
)}
{/* 设置弹窗 */} 数据源设置 - {selectedSource?.name} 连接配置 同步设置 字段映射

配置源表字段与目标字段的映射关系

字段映射配置将在下个版本支持

{/* 日志弹窗 */} 同步日志 - {selectedSource?.name}
{[ { time: "2026-01-31 14:32:45", level: "info", message: "同步任务开始执行" }, { time: "2026-01-31 14:32:46", level: "info", message: "连接数据库成功" }, { time: "2026-01-31 14:32:47", level: "info", message: "开始读取增量数据,起始时间: 2026-01-31 14:27:45" }, { time: "2026-01-31 14:32:50", level: "info", message: "读取到 1,256 条新记录" }, { time: "2026-01-31 14:32:52", level: "info", message: "数据写入目标表完成" }, { time: "2026-01-31 14:32:53", level: "success", message: "同步任务完成,耗时 8秒" }, { time: "2026-01-31 14:27:45", level: "info", message: "同步任务开始执行" }, { time: "2026-01-31 14:27:46", level: "info", message: "连接数据库成功" }, { time: "2026-01-31 14:27:48", level: "warning", message: "检测到 3 条数据格式异常,已跳过" }, { time: "2026-01-31 14:27:50", level: "info", message: "读取到 2,134 条新记录" }, { time: "2026-01-31 14:27:53", level: "success", message: "同步任务完成,耗时 8秒" }, ].map((log, index) => (
{log.time} {log.level.toUpperCase()} {log.message}
))}
) }