mirror of
https://github.com/rustfs/console.git
synced 2026-10-31 03:52:11 +08:00
fix: json-editor format error rustfs/rustfs#1282
This commit is contained in:
+35
-19
@@ -1,39 +1,55 @@
|
||||
<script setup>
|
||||
<script setup lang="ts">
|
||||
import JsonEditorVue from 'json-editor-vue'
|
||||
import 'vanilla-jsoneditor/themes/jse-theme-dark.css'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { Button } from '@/components/ui/button'
|
||||
// import { createAjvValidator } from 'svelte-jsoneditor'
|
||||
|
||||
// const validator = createAjvValidator({ schema, schemaDefinitions })
|
||||
const { t } = useI18n()
|
||||
const message = useMessage()
|
||||
const attrs = useAttrs()
|
||||
const model = defineModel()
|
||||
|
||||
watch(
|
||||
model,
|
||||
newValue => {
|
||||
if (typeof newValue !== 'string') return
|
||||
const trimmed = newValue.trim()
|
||||
if (!trimmed) return
|
||||
try {
|
||||
const formatted = JSON.stringify(JSON.parse(trimmed), null, 2)
|
||||
if (formatted !== newValue) {
|
||||
model.value = formatted
|
||||
}
|
||||
} catch {
|
||||
// Swallow parse errors so the editor stays usable while typing
|
||||
const formatJson = () => {
|
||||
if (typeof model.value !== 'string') {
|
||||
message.error(t('Invalid JSON format'))
|
||||
return
|
||||
}
|
||||
|
||||
const trimmed = model.value.trim()
|
||||
if (!trimmed) {
|
||||
message.warning(t('JSON content is empty'))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed)
|
||||
const formatted = JSON.stringify(parsed, null, 2)
|
||||
if (formatted !== model.value) {
|
||||
model.value = formatted
|
||||
message.success(t('JSON formatted successfully'))
|
||||
} else {
|
||||
message.info(t('JSON is already formatted'))
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
} catch (error) {
|
||||
message.error(t('Invalid JSON format'))
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- :validator="validator" 验证器 -->
|
||||
<div class="w-full">
|
||||
<div class="w-full space-y-2 relative">
|
||||
<div class="flex justify-end absolute top-1 right-1 z-30">
|
||||
<Button variant="outline" size="sm" @click="formatJson">
|
||||
<Icon name="ri:code-s-slash-line" class="size-4" />
|
||||
<!-- <span>{{ t('Format') }}</span> -->
|
||||
</Button>
|
||||
</div>
|
||||
<JsonEditorVue
|
||||
v-bind="attrs"
|
||||
mode="text"
|
||||
:mode="'text' as any"
|
||||
v-model="model"
|
||||
:mainMenuBar="false"
|
||||
selection="TextSelection"
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "Benachrichtigungskonfiguration abrufen fehlgeschlagen",
|
||||
"empty is indicates permanent validity": "Leer bedeutet dauerhafte Gültigkeit",
|
||||
"Create user groups to organize permissions": "Benutzergruppen erstellen, um Berechtigungen zu organisieren",
|
||||
"Filter From This Page": "Von dieser Seite filtern"
|
||||
"Filter From This Page": "Von dieser Seite filtern",
|
||||
"Invalid JSON format": "Ungültiges JSON-Format",
|
||||
"JSON content is empty": "JSON-Inhalt ist leer",
|
||||
"JSON formatted successfully": "JSON erfolgreich formatiert",
|
||||
"JSON is already formatted": "JSON ist bereits formatiert"
|
||||
}
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "Get Notification Config Failed",
|
||||
"empty is indicates permanent validity": "empty is indicates permanent validity",
|
||||
"Create user groups to organize permissions": "Create user groups to organize permissions",
|
||||
"Filter From This Page": "Filter From This Page"
|
||||
"Filter From This Page": "Filter From This Page",
|
||||
"Invalid JSON format": "Invalid JSON format",
|
||||
"JSON content is empty": "JSON content is empty",
|
||||
"JSON formatted successfully": "JSON formatted successfully",
|
||||
"JSON is already formatted": "JSON is already formatted"
|
||||
}
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "Error al Obtener Configuración de Notificación",
|
||||
"empty is indicates permanent validity": "Vacío indica validez permanente",
|
||||
"Create user groups to organize permissions": "Cree grupos de usuarios para organizar permisos",
|
||||
"Filter From This Page": "Filtrar Desde Esta Página"
|
||||
"Filter From This Page": "Filtrar Desde Esta Página",
|
||||
"Invalid JSON format": "Formato JSON inválido",
|
||||
"JSON content is empty": "El contenido JSON está vacío",
|
||||
"JSON formatted successfully": "JSON formateado exitosamente",
|
||||
"JSON is already formatted": "JSON ya está formateado"
|
||||
}
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "Échec de l'obtention de la configuration de notification",
|
||||
"empty is indicates permanent validity": "vide indique une validité permanente",
|
||||
"Create user groups to organize permissions": "Créez des groupes d'utilisateurs pour organiser les permissions",
|
||||
"Filter From This Page": "Filtrer depuis cette page"
|
||||
"Filter From This Page": "Filtrer depuis cette page",
|
||||
"Invalid JSON format": "Format JSON invalide",
|
||||
"JSON content is empty": "Le contenu JSON est vide",
|
||||
"JSON formatted successfully": "JSON formaté avec succès",
|
||||
"JSON is already formatted": "JSON est déjà formaté"
|
||||
}
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "Gagal Mengambil Konfigurasi Notifikasi",
|
||||
"empty is indicates permanent validity": "kosong menandakan validitas permanen",
|
||||
"Create user groups to organize permissions": "Buat grup pengguna untuk mengatur izin",
|
||||
"Filter From This Page": "Filter Dari Halaman Ini"
|
||||
"Filter From This Page": "Filter Dari Halaman Ini",
|
||||
"Invalid JSON format": "Format JSON tidak valid",
|
||||
"JSON content is empty": "Konten JSON kosong",
|
||||
"JSON formatted successfully": "JSON berhasil diformat",
|
||||
"JSON is already formatted": "JSON sudah diformat"
|
||||
}
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "Recupero configurazione notifica non riuscito",
|
||||
"empty is indicates permanent validity": "Vuoto indica validità permanente",
|
||||
"Create user groups to organize permissions": "Crea gruppi utenti per organizzare le autorizzazioni",
|
||||
"Filter From This Page": "Filtra da questa pagina"
|
||||
"Filter From This Page": "Filtra da questa pagina",
|
||||
"Invalid JSON format": "Formato JSON non valido",
|
||||
"JSON content is empty": "Il contenuto JSON è vuoto",
|
||||
"JSON formatted successfully": "JSON formattato con successo",
|
||||
"JSON is already formatted": "JSON è già formattato"
|
||||
}
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "通知設定の取得に失敗しました",
|
||||
"empty is indicates permanent validity": "空は永続的な有効性を示します",
|
||||
"Create user groups to organize permissions": "権限を整理するユーザーグループを作成します",
|
||||
"Filter From This Page": "このページからフィルター"
|
||||
"Filter From This Page": "このページからフィルター",
|
||||
"Invalid JSON format": "無効なJSON形式",
|
||||
"JSON content is empty": "JSONコンテンツが空です",
|
||||
"JSON formatted successfully": "JSONのフォーマットが成功しました",
|
||||
"JSON is already formatted": "JSONは既にフォーマットされています"
|
||||
}
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "알림 구성 가져오기 실패",
|
||||
"empty is indicates permanent validity": "비어 있으면 영구 유효성을 나타냅니다",
|
||||
"Create user groups to organize permissions": "권한을 구성하는 사용자 그룹을 생성하세요",
|
||||
"Filter From This Page": "이 페이지에서 필터링"
|
||||
"Filter From This Page": "이 페이지에서 필터링",
|
||||
"Invalid JSON format": "잘못된 JSON 형식",
|
||||
"JSON content is empty": "JSON 내용이 비어 있습니다",
|
||||
"JSON formatted successfully": "JSON 형식화 성공",
|
||||
"JSON is already formatted": "JSON이 이미 형식화되었습니다"
|
||||
}
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "Falha ao Obter Configuração de Notificação",
|
||||
"empty is indicates permanent validity": "Vazio indica validade permanente",
|
||||
"Create user groups to organize permissions": "Crie grupos de usuários para organizar permissões",
|
||||
"Filter From This Page": "Filtrar Desta Página"
|
||||
"Filter From This Page": "Filtrar Desta Página",
|
||||
"Invalid JSON format": "Formato JSON inválido",
|
||||
"JSON content is empty": "O conteúdo JSON está vazio",
|
||||
"JSON formatted successfully": "JSON formatado com sucesso",
|
||||
"JSON is already formatted": "JSON já está formatado"
|
||||
}
|
||||
|
||||
@@ -879,5 +879,9 @@
|
||||
"Get Notification Config Failed": "Ошибка получения конфигурации уведомлений",
|
||||
"empty is indicates permanent validity": "Пустое значение указывает на постоянную действительность",
|
||||
"Create user groups to organize permissions": "Создайте группы пользователей для организации разрешений",
|
||||
"Filter From This Page": "Фильтровать с этой страницы"
|
||||
"Filter From This Page": "Фильтровать с этой страницы",
|
||||
"Invalid JSON format": "Неверный формат JSON",
|
||||
"JSON content is empty": "Содержимое JSON пусто",
|
||||
"JSON formatted successfully": "JSON успешно отформатирован",
|
||||
"JSON is already formatted": "JSON уже отформатирован"
|
||||
}
|
||||
|
||||
@@ -878,5 +878,9 @@
|
||||
"Get Notification Config Failed": "Bildirim Yapılandırması Alınamadı",
|
||||
"empty is indicates permanent validity": "boş, kalıcı geçerlilik gösterir",
|
||||
"Create user groups to organize permissions": "Kullanıcı grupları oluşturarak izinleri düzenleyin",
|
||||
"Filter From This Page": "Bu sayfadan filtreleme yapın"
|
||||
"Filter From This Page": "Bu sayfadan filtreleme yapın",
|
||||
"Invalid JSON format": "Geçersiz JSON formatı",
|
||||
"JSON content is empty": "JSON içeriği boş",
|
||||
"JSON formatted successfully": "JSON başarıyla formatlandı",
|
||||
"JSON is already formatted": "JSON zaten formatlanmış"
|
||||
}
|
||||
|
||||
@@ -878,5 +878,9 @@
|
||||
"Get Notification Config Failed": "获取通知配置失败",
|
||||
"empty is indicates permanent validity": "空表示永久有效",
|
||||
"Create user groups to organize permissions": "创建用户组以组织权限",
|
||||
"Filter From This Page": "从本页筛选"
|
||||
"Filter From This Page": "从本页筛选",
|
||||
"Invalid JSON format": "JSON 格式无效",
|
||||
"JSON content is empty": "JSON 内容为空",
|
||||
"JSON formatted successfully": "JSON 格式化成功",
|
||||
"JSON is already formatted": "JSON 已格式化"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user