"use client" import { useState } from "react" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Badge } from "@/components/ui/badge" import { Key, Copy, Eye, EyeOff, Plus, Trash2, CheckCircle } from "lucide-react" interface ApiKeyManagementDialogProps { open: boolean onOpenChange: (open: boolean) => void } const MOCK_KEYS = [ { id: 1, name: "生产环境密钥", key: "sk_live_xxxxxxxxxxxx", created: "2024-12-01", lastUsed: "刚刚", status: "active", }, { id: 2, name: "测试环境密钥", key: "sk_test_xxxxxxxxxxxx", created: "2024-11-15", lastUsed: "3天前", status: "active", }, { id: 3, name: "开发调试密钥", key: "sk_dev_xxxxxxxxxxxx", created: "2024-10-20", lastUsed: "1周前", status: "inactive", }, ] export function ApiKeyManagementDialog({ open, onOpenChange }: ApiKeyManagementDialogProps) { const [keys, setKeys] = useState(MOCK_KEYS) const [showKey, setShowKey] = useState(null) const [newKeyName, setNewKeyName] = useState("") const [showNewKeyForm, setShowNewKeyForm] = useState(false) const [copiedId, setCopiedId] = useState(null) const copyKey = (id: number, key: string) => { navigator.clipboard.writeText(key) setCopiedId(id) setTimeout(() => setCopiedId(null), 2000) } const createKey = () => { if (newKeyName) { setKeys([ ...keys, { id: Date.now(), name: newKeyName, key: `sk_live_${Math.random().toString(36).substr(2, 12)}`, created: new Date().toISOString().split("T")[0], lastUsed: "从未", status: "active", }, ]) setNewKeyName("") setShowNewKeyForm(false) } } const deleteKey = (id: number) => { setKeys(keys.filter((k) => k.id !== id)) } return ( API密钥管理
{showNewKeyForm && (
setNewKeyName(e.target.value)} />
)}
{keys.map((item) => (
{item.name} {item.status === "active" ? "启用" : "停用"}
{showKey === item.id ? item.key : item.key.replace(/./g, "•").slice(0, 20) + "..."}
创建于 {item.created} 最后使用: {item.lastUsed}
))}
) }