import * as React from "react" import { useState } from "react" import Link from "next/link" import { toast } from "sonner" import { Copy, Eye, EyeOff, Trash2, ExternalLink, Edit } from "lucide-react" import { Button } from "@/components/ui/button" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" import { MerchantDialog } from "@/components/common/merchant/merchant-dialog" import { TestModeToggle } from "@/components/common/merchant/merchant-test" import { DistributeDialog } from "@/components/common/merchant/merchant-distribute" import { formatDateTime } from "@/lib/utils" import { type UpdateAPIKeyRequest, type MerchantAPIKey } from "@/lib/services" interface MerchantInfoProps { /** API Key */ apiKey: MerchantAPIKey /** 更新回调 */ onUpdate?: (updatedKey: MerchantAPIKey) => void /** 删除回调 */ onDelete: (id: string) => void /** 更新 API Key */ updateAPIKey?: (id: string, data: UpdateAPIKeyRequest) => Promise } /** * 集市中心应用信息组件 * 显示集市中心应用的凭证信息(Client ID 和 Secret) */ export function MerchantInfo({ apiKey, onUpdate, onDelete, updateAPIKey }: MerchantInfoProps) { const [showClientId, setShowClientId] = useState(false) const [showClientSecret, setShowClientSecret] = useState(false) /* 复制到剪贴板 */ const copyToClipboard = async (text: string, label: string) => { try { await navigator.clipboard.writeText(text) toast.success(`${ label } 已复制`) } catch { try { const textArea = document.createElement('textarea') textArea.value = text textArea.style.position = 'fixed' textArea.style.opacity = '0' document.body.appendChild(textArea) textArea.select() const successful = document.execCommand('copy') document.body.removeChild(textArea) if (successful) { toast.success(`${ label } 已复制`) } else { toast.error('复制失败') } } catch { toast.error('复制失败') } } } const maskText = (text: string, showLength: number = 8) => { if (text.length <= showLength * 2) return text return `${ text.substring(0, showLength) }${ '•'.repeat(20) }${ text.substring(text.length - showLength) }` } return (

应用信息

{apiKey.app_name}

{apiKey.test_mode && ( 测试 )}
{apiKey.app_description && (

{apiKey.app_description}

)}

{formatDateTime(apiKey.created_at)}

{apiKey.app_homepage_url}
{apiKey.redirect_uri && (
{apiKey.redirect_uri}
)}
{apiKey.notify_url}

API 配置

客户端标识
{showClientId ? apiKey.client_id : maskText(apiKey.client_id, 8)}
客户端密钥
{showClientSecret ? apiKey.client_secret : '•'.repeat(40)}

应用管理

{ }} onUpdate={onUpdate} updateAPIKey={updateAPIKey} trigger={ } /> 确认删除应用 确定要删除应用 “{apiKey.app_name}” 吗? 此操作将永久删除该应用的所有凭证和配置,且无法恢复。 使用此应用凭证的所有集成将立即失效。 取消 onDelete(apiKey.id)} className="bg-destructive hover:bg-destructive/90" > 确认删除
) }