From a13fcb99643cbf188e1f027e129c44c72133c942 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Tue, 9 Jun 2026 14:20:58 +0800 Subject: [PATCH] feat(redis): add JSON format/compress buttons in raw content view --- .../src/components/redis/RedisValueViewer.vue | 134 +++++++++++++++++- apps/desktop/src/i18n/locales/en.ts | 3 + apps/desktop/src/i18n/locales/zh-CN.ts | 3 + 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src/components/redis/RedisValueViewer.vue b/apps/desktop/src/components/redis/RedisValueViewer.vue index 761af0276d..a654cb0504 100644 --- a/apps/desktop/src/components/redis/RedisValueViewer.vue +++ b/apps/desktop/src/components/redis/RedisValueViewer.vue @@ -15,6 +15,8 @@ import { Loader2, Pencil, WrapText, + IndentIncrease, + IndentDecrease, } from "@lucide/vue"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -289,6 +291,64 @@ function handleStringInput() { } } +function formatJsonText(raw: string): string | null { + try { + const parsed = JSON.parse(raw); + return JSON.stringify(parsed, null, 2); + } catch { + return null; + } +} + +function compressJsonText(raw: string): string | null { + try { + const parsed = JSON.parse(raw); + return JSON.stringify(parsed); + } catch { + return null; + } +} + +function handleFormatStringJson() { + const result = formatJsonText(editValue.value); + if (result != null) { + editValue.value = result; + isEditing.value = true; + } else { + toast(t("redis.jsonFormatError"), 3000); + } +} + +function handleCompressStringJson() { + const result = compressJsonText(editValue.value); + if (result != null) { + editValue.value = result; + isEditing.value = true; + } else { + toast(t("redis.jsonFormatError"), 3000); + } +} + +function handleFormatMemberJson() { + const result = formatJsonText(memberEditValue.value); + if (result != null) { + memberEditValue.value = result; + isEditingMember.value = true; + } else { + toast(t("redis.jsonFormatError"), 3000); + } +} + +function handleCompressMemberJson() { + const result = compressJsonText(memberEditValue.value); + if (result != null) { + memberEditValue.value = result; + isEditingMember.value = true; + } else { + toast(t("redis.jsonFormatError"), 3000); + } +} + async function applyDeleteKey() { await api.redisDeleteKey(props.connectionId, props.db, props.keyRaw); emit("deleted"); @@ -849,6 +909,26 @@ onBeforeUnmount(() => { + +