diff --git a/renderer/src/components/k-input-object/index.vue b/renderer/src/components/k-input-object/index.vue index b745a92..ae916e5 100644 --- a/renderer/src/components/k-input-object/index.vue +++ b/renderer/src/components/k-input-object/index.vue @@ -163,24 +163,26 @@ function getDefaultValue(property: any): string { } } -// 修改 watch 逻辑 -// watch( -// () => props.modelValue, -// (newVal) => { -// const currentParsed = tryParse(inputValue.value) -// if (!isDeepEqual(currentParsed, newVal)) { -// const newContent = JSON.stringify(newVal, null, 2) -// editorView.value?.dispatch({ -// changes: { -// from: 0, -// to: editorView.value.state.doc.length, -// insert: newContent -// } -// }) -// } -// }, -// { deep: true } -// ) +watch( + () => props.modelValue, + (newVal) => { + // 当前编辑器内容 + const currentContent = editorView.value?.state.doc.toString() ?? ''; + const newContent = JSON.stringify(newVal ?? {}, null, 2); + + if (currentContent !== newContent && editorView.value) { + editorView.value.dispatch({ + changes: { + from: 0, + to: editorView.value.state.doc.length, + insert: newContent + } + }); + } + }, + { deep: true } +); + // 辅助函数:尝试解析 JSON const tryParse = (value: string): any => { diff --git a/renderer/src/components/main-panel/tool/tool-executor.vue b/renderer/src/components/main-panel/tool/tool-executor.vue index 0086b0f..082c814 100644 --- a/renderer/src/components/main-panel/tool/tool-executor.vue +++ b/renderer/src/components/main-panel/tool/tool-executor.vue @@ -52,7 +52,6 @@ import { getDefaultValue, normaliseJavascriptType } from '@/hook/mcp'; import KInputObject from '@/components/k-input-object/index.vue'; import { mcpClientAdapter } from '@/views/connect/core'; import { JSONSchemaFaker } from 'json-schema-faker'; -import { faker } from '@faker-js/faker'; defineComponent({ name: 'tool-executor' }); @@ -149,6 +148,7 @@ const generateMockData = async () => { // 将 mock 数据绑定到表单 Object.keys(mockData).forEach(key => { tabStorage.formData[key] = mockData[key]; + console.log(mockData[key]); }); // 如果需要刷新表单校验,可以加上