From f372b20a68255539ade0e1de8f17ef2ca2651f6b Mon Sep 17 00:00:00 2001 From: ljyf5593 Date: Thu, 5 Mar 2026 12:01:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD=E7=94=9F=E6=88=90=E7=A9=BA?= =?UTF-8?q?JSON=E6=95=B0=E7=BB=84=E7=9A=84=E9=97=AE=E9=A2=98=20(#169)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: liujie <469282686@qq.com> --- frontend/src/App.tsx | 2 +- internal/app/methods_file.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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