"use client" import { useState } from "react" import { Card, CardContent, CardDescription, 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 { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Server, Plus, Key, FileText, BarChart3, Settings, Eye, Copy, Trash2, CheckCircle2, XCircle, Clock, Activity, ExternalLink, Code, Shield } from "lucide-react" const apis = [ { id: "1", name: "用户画像查询API", endpoint: "/api/v1/user/portrait", method: "GET", description: "根据用户ID查询完整画像信息", status: "active", callCount: 125680, avgLatency: 45, errorRate: 0.02, }, { id: "2", name: "标签批量查询API", endpoint: "/api/v1/tags/batch", method: "POST", description: "批量查询用户标签", status: "active", callCount: 89420, avgLatency: 120, errorRate: 0.05, }, { id: "3", name: "CLV评分API", endpoint: "/api/v1/clv/score", method: "GET", description: "获取用户CLV评分和预测值", status: "maintenance", callCount: 45230, avgLatency: 85, errorRate: 0.01, }, ] const apiKeys = [ { id: "1", name: "生产环境密钥", key: "sk_prod_****8a9b", created: "2024-01-01", lastUsed: "2024-01-15", status: "active" }, { id: "2", name: "测试环境密钥", key: "sk_test_****3c2d", created: "2024-01-05", lastUsed: "2024-01-14", status: "active" }, ] export default function APIMarketPage() { const [activeTab, setActiveTab] = useState("apis") const [showDocDialog, setShowDocDialog] = useState(false) const [showKeyDialog, setShowKeyDialog] = useState(false) const [showMonitorDialog, setShowMonitorDialog] = useState(false) const [selectedApi, setSelectedApi] = useState(null) const getStatusBadge = (status: string) => { switch (status) { case "active": return 运行中 case "maintenance": return 维护中 case "disabled": return 已停用 default: return 未知 } } return (
{/* 页面标题 */}

API市场

管理和监控数据API服务

{/* 统计卡片 */}

API总数

12

今日调用

45.2K

平均延迟

68ms

成功率

99.8%

{/* 主内容区 */} API列表 API密钥 调用日志 API名称 端点 方法 状态 调用量 延迟 操作 {apis.map((api) => (

{api.name}

{api.description}

{api.endpoint} {api.method} {getStatusBadge(api.status)} {api.callCount.toLocaleString()} {api.avgLatency}ms
))}
API密钥 管理API访问密钥
名称 密钥 创建时间 最后使用 状态 操作 {apiKeys.map((key) => ( {key.name} {key.key} {key.created} {key.lastUsed} 活跃
))}
调用日志 查看API调用历史记录 时间 API 方法 状态码 延迟 IP 2024-01-15 14:30:25 /api/v1/user/portrait GET 200 42ms 192.168.1.*** 2024-01-15 14:30:18 /api/v1/tags/batch POST 200 118ms 192.168.1.*** 2024-01-15 14:30:05 /api/v1/clv/score GET 500 - 192.168.2.***
{/* API文档弹窗 */} {selectedApi?.name} - 接口文档 {selectedApi?.description}
{selectedApi?.method} {selectedApi?.endpoint}
{`{
  "user_id": "string (必填) - 用户唯一标识",
  "fields": "array (可选) - 需要返回的字段列表"
}`}
{`{
  "code": 200,
  "data": {
    "user_id": "U12345",
    "portrait": {
      "basic": { "age": 28, "gender": "M" },
      "tags": ["高价值", "活跃用户"],
      "clv_score": 92
    }
  }
}`}
{/* 监控弹窗 */} {selectedApi?.name} - 性能监控 查看API实时性能指标

今日调用

{selectedApi?.callCount.toLocaleString()}

平均延迟

{selectedApi?.avgLatency}ms

错误率

{((selectedApi?.errorRate || 0) * 100).toFixed(2)}%

调用趋势 (最近24小时)

{Array.from({ length: 24 }).map((_, i) => (
))}
{/* 密钥管理弹窗 */} 创建API密钥 创建新的API访问密钥
) }