diff --git a/packages/editor/src/fields/KeyValue.vue b/packages/editor/src/fields/KeyValue.vue index 1c660e44..8a96f4b0 100644 --- a/packages/editor/src/fields/KeyValue.vue +++ b/packages/editor/src/fields/KeyValue.vue @@ -1,37 +1,60 @@ @@ -42,6 +65,9 @@ import { Delete, Plus } from '@element-plus/icons-vue'; import { TMagicButton, TMagicInput } from '@tmagic/design'; import type { FieldProps } from '@tmagic/form'; +import CodeIcon from '@editor/icons/CodeIcon.vue'; +import MagicCodeEditor from '@editor/layouts/CodeEditor.vue'; + defineOptions({ name: 'MEditorKeyValue', }); @@ -52,6 +78,7 @@ const props = withDefaults( type: 'key-value'; name: string; text: string; + advanced?: boolean; }> >(), { @@ -62,9 +89,19 @@ const props = withDefaults( const emit = defineEmits<(e: 'change', value: Record) => void>(); const records = ref<[string, string][]>([]); +const showCode = ref(false); watchEffect(() => { - records.value = Object.entries(props.model[props.name] || {}); + const initValues: [string, any][] = Object.entries(props.model[props.name] || {}); + + for (const [, value] of initValues) { + if (typeof value !== 'string') { + showCode.value = true; + break; + } + } + + records.value = initValues; }); const getValue = () => { @@ -93,4 +130,8 @@ const deleteHandler = (index: number) => { records.value.splice(index, 1); emit('change', getValue()); }; + +const save = (v: string | any) => { + emit('change', v); +}; diff --git a/packages/editor/src/theme/key-value.scss b/packages/editor/src/theme/key-value.scss index 85728a28..7a7cb84f 100644 --- a/packages/editor/src/theme/key-value.scss +++ b/packages/editor/src/theme/key-value.scss @@ -1,3 +1,10 @@ +.m-fields-key-value { + display: flex; + justify-items: center; + align-items: top; + width: 100%; +} + .m-fields-key-value-item { display: flex; margin-bottom: 10px; diff --git a/packages/editor/src/utils/data-source/formConfigs/http.ts b/packages/editor/src/utils/data-source/formConfigs/http.ts index cdba766e..bf4b4af3 100644 --- a/packages/editor/src/utils/data-source/formConfigs/http.ts +++ b/packages/editor/src/utils/data-source/formConfigs/http.ts @@ -46,6 +46,7 @@ export default [ name: 'data', type: 'key-value', defaultValue: {}, + advanced: true, text: '请求体', }, {