fix: Formatted display of json content type (#219)

This commit is contained in:
wuwen 2023-01-16 20:34:51 +08:00 committed by GitHub
parent 70df7605cb
commit 3ef790dc07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,7 +23,7 @@ limitations under the License. -->
class="content mb-10"
:readonly="true"
v-else-if="item.label === 'content'"
:value="currentLog[item.label]"
:value="contentFormat(item.label)"
/>
<span v-else-if="item.label === 'tags'" class="g-sm-8 mb-10">
<div v-for="(d, index) in logTags" :key="index">{{ d }}</div>
@ -38,6 +38,7 @@ limitations under the License. -->
import { useI18n } from "vue-i18n";
import type { Option } from "@/types/app";
import { dateFormat } from "@/utils/dateFormat";
import { formatJson } from "@/utils/formatJson";
/*global defineProps */
const props = defineProps({
@ -53,6 +54,16 @@ limitations under the License. -->
return `${d.key} = ${d.value}`;
});
});
function contentFormat(label: string) {
try {
return props.currentLog.contentType === "JSON"
? formatJson(JSON.parse(props.currentLog[label]))
: props.currentLog[label];
} catch (e) {
return props.currentLog[label];
}
}
</script>
<style lang="scss" scoped>
.content {