// 用例导出面板:格式切换 + 导出下载 'use client'; import { useState } from 'react'; import type { ExportFormat } from '@/lib/types'; import { exportTestCases } from '@/lib/api'; interface ExportPanelProps { tcSetId: string; } const EXPORT_FORMATS: { key: ExportFormat; label: string; description: string }[] = [ { key: 'yaml', label: 'YAML', description: '自动化测试可解析的结构化用例' }, { key: 'csv', label: 'CSV 表格', description: '适合 Excel 查看与评审归档' }, { key: 'xmind', label: 'XMind', description: '思维导图,便于评审展示' }, ]; export default function ExportPanel({ tcSetId }: ExportPanelProps) { const [activeFormat, setActiveFormat] = useState('yaml'); const [exporting, setExporting] = useState(false); const handleExport = async () => { setExporting(true); try { const blob = await exportTestCases(tcSetId, activeFormat); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `testcases.${activeFormat === 'csv' ? 'csv' : activeFormat === 'yaml' ? 'yaml' : 'xmind'}`; a.click(); URL.revokeObjectURL(url); } catch (err) { console.error('Export failed:', err); } finally { setExporting(false); } }; return (

导出测试用例

{/* 格式切换标签 */}
{EXPORT_FORMATS.map((fmt) => ( ))}
{/* 导出按钮 */}
); }