feat: Redis单值结果直接展示+JSON中文格式化+悬浮复制
1. GET/HGET/TTL等单值命令: 直接展示raw值, 不再套table 2. JSON自动检测+格式化(中文正常显示, 2空格缩进) 3. 非JSON值(如false/数字)直接文本展示 4. 代码块右上角悬浮复制按钮(hover显示) 5. 工具栏显示值类型(JSON/String)替代行列数
This commit is contained in:
1 parent
18430f3717
commit
03ff845485
2 files changed
+62
-17
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user