【功能完善】修复 jsonEditor 编辑回显不生效的问题

This commit is contained in:
puhui999
2025-03-28 15:05:13 +08:00
parent bff2327eba
commit fe905721bd
2 changed files with 14 additions and 29 deletions

View File

@ -41,9 +41,9 @@ const initJsonEditor = () => {
navigationBar: props.showNavigationBar,
statusBar: props.showStatusBar,
mainMenuBar: props.showMainMenuBar,
onChangeJSON: (json: any) => {
jsonObj.value = json
emits('change', json)
onChange: () => {
jsonObj.value = jsonEditor?.get()
emits('change', jsonEditor?.get())
},
onValidationError: (errors: any) => {
emits('error', errors)

View File

@ -8,24 +8,10 @@
class="my-4"
description="如需编辑文件,请点击下方编辑按钮"
/>
<!-- JSON 编辑器读模式 -->
<Vue3Jsoneditor
v-if="isEditing"
<JsonEditor
v-model="config"
:options="editorOptions"
height="500px"
currentMode="code"
@error="onError"
/>
<!-- JSON 编辑器写模式 -->
<Vue3Jsoneditor
v-else
v-model="config"
:options="editorOptions"
height="500px"
currentMode="view"
v-loading.fullscreen.lock="loading"
:mode="isEditing ? 'code' : 'view'"
height="600px"
@error="onError"
/>
<div class="mt-5 text-center">
@ -40,9 +26,11 @@
</template>
<script lang="ts" setup>
import Vue3Jsoneditor from 'v3-jsoneditor/src/Vue3Jsoneditor.vue'
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
import { jsonParse } from '@/utils'
import { isEmpty } from '@/utils/is'
defineOptions({ name: 'DeviceDetailConfig' })
const props = defineProps<{
device: DeviceVO
@ -63,12 +51,6 @@ watchEffect(() => {
})
const isEditing = ref(false) // 编辑状态
const editorOptions = computed(() => ({
mainMenuBar: false,
navigationBar: false,
statusBar: false
})) // JSON 编辑器的选项
/** 启用编辑模式的函数 */
const enableEdit = () => {
isEditing.value = true
@ -112,8 +94,11 @@ const updateDeviceConfig = async () => {
}
/** 处理 JSON 编辑器错误的函数 */
const onError = (e: any) => {
console.log('onError', e)
const onError = (errors: any) => {
if (isEmpty(errors)) {
hasJsonError.value = false
return
}
hasJsonError.value = true
}
</script>