From 03ff845485c7ec8d159b2fad78dfa32ca09d8b79 Mon Sep 17 00:00:00 2001 From: logan Date: Thu, 28 May 2026 15:20:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Redis=E5=8D=95=E5=80=BC=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E7=9B=B4=E6=8E=A5=E5=B1=95=E7=A4=BA+JSON=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E6=A0=BC=E5=BC=8F=E5=8C=96+=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. GET/HGET/TTL等单值命令: 直接展示raw值, 不再套table 2. JSON自动检测+格式化(中文正常显示, 2空格缩进) 3. 非JSON值(如false/数字)直接文本展示 4. 代码块右上角悬浮复制按钮(hover显示) 5. 工具栏显示值类型(JSON/String)替代行列数 --- backend/internal/handler/instance_detail.go | 37 +++++++++++------- frontend/src/pages/QueriesPage.tsx | 42 +++++++++++++++++++-- 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/backend/internal/handler/instance_detail.go b/backend/internal/handler/instance_detail.go index b102a90..3eb1c0a 100644 --- a/backend/internal/handler/instance_detail.go +++ b/backend/internal/handler/instance_detail.go @@ -14,6 +14,8 @@ import ( "sql-platform/internal/middleware" "strings" "strconv" + "encoding/json" + "bytes" ) // GET /api/v1/instances/:id/detail/databases @@ -703,24 +705,33 @@ func executeRedisQuery(instance *model.Instance, dbSelect string, command string columns = []string{"field", "value"} } else { // Single value result (GET, HGET, TYPE, TTL, etc.) - // Try to extract key name from command keyName := "" if len(parts) > 1 { keyName = parts[1] } - if keyName != "" { - rows = append(rows, map[string]interface{}{ - "key": keyName, - "value": fmt.Sprintf("%v", v), - }) - columns = []string{"key", "value"} - } else { - rows = append(rows, map[string]interface{}{ - "command": command, - "result": fmt.Sprintf("%v", v), - }) - columns = []string{"command", "result"} + rawValue := fmt.Sprintf("%v", v) + // Try to pretty-format JSON with Chinese characters preserved + var prettyJSON string + var parsed interface{} + if json.Unmarshal([]byte(rawValue), &parsed) == nil { + switch parsed.(type) { + case map[string]interface{}, []interface{}: + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + enc.SetIndent("", " ") + enc.Encode(parsed) + prettyJSON = strings.TrimRight(buf.String(), "\n") + } } + return gin.H{ + "columns": []string{}, + "rows": []interface{}{}, + "total": 0, + "raw_value": prettyJSON != "", + "raw_key": keyName, + "raw_text": rawValue, + }, nil } } diff --git a/frontend/src/pages/QueriesPage.tsx b/frontend/src/pages/QueriesPage.tsx index 5e72cef..e5f8d23 100644 --- a/frontend/src/pages/QueriesPage.tsx +++ b/frontend/src/pages/QueriesPage.tsx @@ -25,6 +25,11 @@ interface QueryResult { rows: Record[]; affected_rows: number; execution_time_ms: number; + cost_ms?: number; + raw_value?: boolean; + raw_key?: string; + raw_text?: string; + error?: string; } interface QueryHistoryItem { @@ -480,9 +485,15 @@ export default function QueriesPage() {
{result.execution_time_ms || result.cost_ms || 0}ms - {result.rows?.length || 0} 行 - {result.columns?.length || 0} 列 - {result.rows && result.rows.length > 0 && ( + {result.raw_text !== undefined ? ( + {result.raw_value ? 'JSON' : typeof result.raw_text === 'string' ? 'String' : 'Value'} + ) : ( + <> + {result.rows?.length || 0} 行 + {result.columns?.length || 0} 列 + + )} + {(result.rows?.length > 0 || result.raw_text !== undefined) && ( <>
- {result.columns && result.columns.length > 0 ? ( + {result.raw_text !== undefined ? ( + /* Raw value display (Redis GET/HGET/TTL etc.) */ +
+ {result.raw_key && ( +
{result.raw_key}
+ )} +
+
{result.raw_value
+                      ? (() => { try { return JSON.stringify(JSON.parse(String(result.raw_text)), null, 2); } catch { return String(result.raw_text); } })()
+                      : String(result.raw_text)
+                    }
+ +
+
+ ) : result.columns && result.columns.length > 0 ? (