增加json-editor-vue

This commit is contained in:
FunCoder 2025-04-28 14:16:22 +08:00
parent f5f3de0f74
commit 28f2a3a3a1
2 changed files with 65 additions and 0 deletions

View File

@ -46,6 +46,7 @@
"install": "^0.13.0",
"js-cookie": "^3.0.5",
"js-table2excel": "^1.1.2",
"json-editor-vue": "^0.18.1",
"jsplumb": "^2.15.6",
"jwchat": "^2.0.3",
"lodash-es": "^4.17.21",

View File

@ -0,0 +1,64 @@
<!--
// JsonEditorjson
// 使
<template>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
<el-form-item label="内容" prop="content">
<JsonEditor ref="jsonEditorRef" v-model:jsonObj="ruleForm.content"></JsonEditor>
</el-form-item>
</el-col>
</template>
<script lang="ts" setup>
import JsonEditor from '/@/components/jsonEditor/index.vue';
</script>
-->
<template>
<!-- 根据 isJsonValid 控制 JsonEditorVue 的显示 -->
<JsonEditorVue ref="jsonEditorVueRef" v-show="isJsonValid" v-model="internalJsonObj" mode="text" style="width: 100%; height: 800px" />
</template>
<script setup lang="ts" name="jsonEditor">
import { ref, useTemplateRef, watch, onMounted, computed } from 'vue';
import JsonEditorVue from 'json-editor-vue';
const props = defineProps({
jsonObj: {
type: null,
default: null, // null
required: false, //
},
});
const jsonEditorVueRef = useTemplateRef('jsonEditorVueRef');
const internalJsonObj = ref(props.jsonObj);
const emit = defineEmits(['update:jsonObj']);
// jsonObj JSON
const isJsonValid = computed(() => {
// try {
// if (internalJsonObj.value && (internalJsonObj.value.startsWith('{') || internalJsonObj.value.startsWith('[')) && (internalJsonObj.value.endsWith('}') || internalJsonObj.value.endsWith(']'))) {
// return true;
// }
// } catch {
// return false;
// }
return true;
});
// JSON
watch(internalJsonObj, () => {
emit('update:jsonObj', internalJsonObj.value);
});
// JSON
watch(
() => props.jsonObj,
(newVal) => {
internalJsonObj.value = newVal;
}
);
onMounted(() => {
jsonEditorVueRef.value.jsonEditor.focus();
});
</script>