Browse Source

feat: add JsonPreviewModal component

main
刘凯 1 year ago
parent
commit
44b4e9b6b7
  1. 1
      src/components/JsonPreviewModal/index.ts
  2. 34
      src/components/JsonPreviewModal/src/index.vue

1
src/components/JsonPreviewModal/index.ts

@ -0,0 +1 @@
export { default } from './src/index.vue'

34
src/components/JsonPreviewModal/src/index.vue

@ -0,0 +1,34 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Modal } from 'ant-design-vue'
import { JsonPreview } from '@/components/CodeEditor'
const modalProps = withDefaults(defineProps<{
title?: string
width?: string
data: string
}>(), { width: '50%' })
const open = ref(false)
const jsonData = computed(() => {
try {
return JSON.parse(modalProps.data)
}
catch {
return {}
}
})
</script>
<template>
<div @click="open = true">
<slot />
</div>
<Modal v-bind="modalProps" v-model:open="open" :footer="null">
<div p="20px" border-rounded bg-gray-50>
<JsonPreview :data="jsonData" />
</div>
</Modal>
</template>
Loading…
Cancel
Save