import { Download } from "lucide-react"; import { Button } from "@/components/ui/button"; import type { Column } from "./DataGrid"; function cellValue(row: T, col: Column): string | number { const raw = row[col.key]; if (col.format) return col.format(raw, row); return (raw as string | number) ?? ""; } /** 按表格列定义导出 xlsx;xlsx 按需加载,避免进入首屏包。 */ export async function exportToXlsx( rows: T[], columns: Column[], filename: string, sheetName = "明细", ): Promise { const { buildJsonSheet, writeWorkbook } = await import("../../../shared/xlsx"); const sheet = buildJsonSheet( rows.map((row) => Object.fromEntries(columns.map((col) => [col.label, cellValue(row, col)])), ), ); writeWorkbook([{ name: sheetName, sheet }], filename); } export function ExportButton({ rows, columns, filename, sheetName, label = "导出", }: { rows: T[]; columns: Column[]; filename: string; sheetName?: string; label?: string; }) { return ( ); }