perf: support view as base64 text for the key with type string
This commit is contained in:
parent
9152a32fd3
commit
dbb5969e34
|
@ -48,23 +48,42 @@ const viewOption = [
|
||||||
]
|
]
|
||||||
const viewAs = ref(types.PLAIN_TEXT)
|
const viewAs = ref(types.PLAIN_TEXT)
|
||||||
|
|
||||||
const jsonValue = computed(() => {
|
const getJsonValue = () => {
|
||||||
try {
|
try {
|
||||||
const jsonObj = JSON.parse(props.value)
|
const jsonObj = JSON.parse(props.value)
|
||||||
return JSON.stringify(jsonObj, null, 2)
|
return JSON.stringify(jsonObj, null, 2)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return props.value
|
return props.value
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
const getBase64Value = () => {
|
||||||
|
try {
|
||||||
|
return atob(props.value)
|
||||||
|
} catch (e) {
|
||||||
|
return props.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getBase64JsonValue = () => {
|
||||||
|
try {
|
||||||
|
const text = atob(props.value)
|
||||||
|
const jsonObj = JSON.parse(text)
|
||||||
|
return JSON.stringify(jsonObj, null, 2)
|
||||||
|
} catch (e) {
|
||||||
|
return props.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const autoDetectFormat = () => {
|
const autoDetectFormat = () => {
|
||||||
// auto check format when loaded
|
// auto check format when loaded
|
||||||
if (IsJson(jsonValue.value)) {
|
if (IsJson(props.value)) {
|
||||||
viewAs.value = types.JSON
|
viewAs.value = types.JSON
|
||||||
} else {
|
} else {
|
||||||
viewAs.value = types.PLAIN_TEXT
|
viewAs.value = types.PLAIN_TEXT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
autoDetectFormat()
|
autoDetectFormat()
|
||||||
})
|
})
|
||||||
|
@ -85,11 +104,11 @@ const viewValue = computed(() => {
|
||||||
case types.PLAIN_TEXT:
|
case types.PLAIN_TEXT:
|
||||||
return props.value
|
return props.value
|
||||||
case types.JSON:
|
case types.JSON:
|
||||||
return jsonValue.value
|
return getJsonValue()
|
||||||
case types.BASE64_TO_TEXT:
|
case types.BASE64_TO_TEXT:
|
||||||
return props.value
|
return getBase64Value()
|
||||||
case types.BASE64_TO_JSON:
|
case types.BASE64_TO_JSON:
|
||||||
return props.value
|
return getBase64JsonValue()
|
||||||
default:
|
default:
|
||||||
return props.value
|
return props.value
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue