【功能完善】修复 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, navigationBar: props.showNavigationBar,
statusBar: props.showStatusBar, statusBar: props.showStatusBar,
mainMenuBar: props.showMainMenuBar, mainMenuBar: props.showMainMenuBar,
onChangeJSON: (json: any) => { onChange: () => {
jsonObj.value = json jsonObj.value = jsonEditor?.get()
emits('change', json) emits('change', jsonEditor?.get())
}, },
onValidationError: (errors: any) => { onValidationError: (errors: any) => {
emits('error', errors) emits('error', errors)

View File

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