'use client'; import { useState } from 'react'; import { X, Download, FileJson, Check, Copy } from 'lucide-react'; import { toast } from 'react-hot-toast'; import { DynamicConfiguration } from '@/types'; interface ConfigurationExportModalProps { isOpen: boolean; onClose: () => void; configs: DynamicConfiguration[]; } export default function ConfigurationExportModal({ isOpen, onClose, configs, }: ConfigurationExportModalProps) { const [copied, setCopied] = useState(false); if (!isOpen) return null; const exportPayload = configs.map((c) => ({ config_key: c.config_key, config_value: c.config_value, description: c.description, type: c.type, })); const jsonString = JSON.stringify(exportPayload, null, 2); const handleDownload = () => { if (configs.length === 0) { toast.error('没有可导出的配置数据'); return; } const blob = new Blob([jsonString], { type: 'application/json;charset=utf-8;' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = `configurations_backup_${new Date().toISOString().slice(0, 10)}.json`; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url); toast.success(`成功导出 ${configs.length} 项系统配置`); onClose(); }; const handleCopy = async () => { if (configs.length === 0) { toast.error('没有可复制的数据'); return; } try { await navigator.clipboard.writeText(jsonString); setCopied(true); toast.success('已复制 JSON 到剪贴板'); setTimeout(() => setCopied(false), 2000); } catch { toast.error('复制失败'); } }; return (
将当前全部配置导出为标准 JSON 备份文件
{jsonString}