diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 18092e2..f2deb44 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -666,7 +666,7 @@ function App() { void message.warning("没有连接可导出"); return; } - const res = await (window as any).go.app.App.ExportData(connections, [], "connections", "json"); + const res = await (window as any).go.app.App.ExportData(connections, ['id','name','config','includeDatabases','includeRedisDatabases'], "connections", "json"); if (res.success) { void message.success("导出成功"); } else if (res.message !== "Cancelled") { diff --git a/internal/app/methods_file.go b/internal/app/methods_file.go index a68620e..9e5fc1b 100644 --- a/internal/app/methods_file.go +++ b/internal/app/methods_file.go @@ -1601,6 +1601,21 @@ func writeRowsToFile(f *os.File, data []map[string]interface{}, columns []string return writeRowsToHTML(f, data, columns) } + // 如果列名为空但数据不为空,从所有数据行提取所有键 + if len(columns) == 0 && len(data) > 0 { + keySet := make(map[string]bool) + for _, row := range data { + for key := range row { + keySet[key] = true + } + } + // 排序以确保输出一致 + for key := range keySet { + columns = append(columns, key) + } + sort.Strings(columns) + } + var csvWriter *csv.Writer var jsonEncoder *json.Encoder isJsonFirstRow := true