fix(schema): 问题修复

This commit is contained in:
baiqi 2024-07-15 19:08:21 +08:00 committed by Craftsman
parent 46fcef3d72
commit b5410d9519
3 changed files with 63 additions and 17 deletions

View File

@ -306,6 +306,7 @@
lineNumbersMinChars: 3,
lineDecorationsWidth: 0,
tabSize: 2,
scrollBeyondLastLine: false, //
});
editor.getModel()?.setEOL(monaco.editor.EndOfLineSequence.LF); //

View File

@ -250,9 +250,20 @@
v-if="record.type === 'string'"
v-model:model-value="record.format"
:options="formatOptions"
:disabled="props.disabled"
class="ms-form-table-input"
@change="emitChange('enumValuesInput')"
></a-select>
</template>
<template #pattern="{ record }">
<a-input
v-if="record.type === 'string'"
v-model:model-value="record.pattern"
:disabled="props.disabled"
class="ms-form-table-input"
@change="emitChange('enumValuesInput')"
></a-input>
</template>
<template #action="{ record, rowIndex }">
<div class="flex w-full items-center gap-[8px]">
<a-tooltip :content="t('common.advancedSettings')">
@ -312,10 +323,21 @@
:footer="!props.disabled"
@confirm="applySetting"
>
<a-form ref="setting" :model="activeRecord" :disabled="props.disabled" layout="vertical">
<a-form ref="settingFormRef" :model="activeRecord" :disabled="props.disabled" layout="vertical">
<a-form-item
field="title"
:label="t('ms.json.schema.name')"
:rules="[{ required: true, message: t('ms.json.schema.nameNotNull') }]"
:rules="[
{
required: true,
message: t('ms.json.schema.nameNotNull'),
},
{
validator: (value, callback) => {
validRepeat(value, callback);
},
},
]"
asterisk-position="end"
>
<a-input
@ -536,7 +558,7 @@
</template>
<script setup lang="ts">
import { SelectOptionData, TableData, TableRowSelection } from '@arco-design/web-vue';
import { FormInstance, SelectOptionData, TableData, TableRowSelection } from '@arco-design/web-vue';
import { cloneDeep } from 'lodash-es';
import MsButton from '@/components/pure/ms-button/index.vue';
@ -823,11 +845,10 @@
title: t('ms.json.schema.regex'),
dataIndex: 'pattern',
slotName: 'pattern',
inputType: 'input',
size: 'medium',
addLineDisabled: true,
showInTable: false,
isNull: (record) => ['object', 'array', 'null', 'boolean'].includes(record.type),
isNull: (record) => record.type !== 'string',
},
{
title: t('ms.json.schema.format'),
@ -1015,10 +1036,25 @@
);
}
async function validRepeat(value: string, callback: (error?: string) => void) {
if (activeRecord.value.parent) {
(activeRecord.value.parent.children as Record<string, any>[])?.forEach((row) => {
if (row.title.length && row.title === value) {
callback(`${t('ms.json.schema.name')}${t('msFormTable.paramRepeatMessage')}`);
}
});
}
callback();
}
const settingFormRef = ref<FormInstance>();
/**
* 应用设置
*/
function applySetting() {
settingFormRef.value?.validate((errors) => {
if (!errors) {
if (activeRecord.value.id === 'root') {
data.value = [{ ...activeRecord.value }];
} else {
@ -1031,6 +1067,8 @@
settingDrawerVisible.value = false;
emitChange('applySetting');
}
});
}
const showQuickInputParam = ref(false);
const activeQuickInputRecord = ref<JsonSchemaTableItem>();

View File

@ -108,7 +108,7 @@
? 'font-medium !text-[rgb(var(--primary-5))]'
: '!text-[var(--color-text-4)]'
"
@click="activeResponse.body.jsonBody.enableJsonSchema = true"
@click="handleChangeJsonType('Schema')"
>
Schema
</MsButton>
@ -121,7 +121,7 @@
? 'font-medium !text-[rgb(var(--primary-5))]'
: '!text-[var(--color-text-4)]'
"
@click="activeResponse.body.jsonBody.enableJsonSchema = false"
@click="handleChangeJsonType('Json')"
>
Json
</MsButton>
@ -551,6 +551,13 @@
function handleStatusCodeChange() {
emit('change');
}
function handleChangeJsonType(type: 'Schema' | 'Json') {
activeResponse.value.body.jsonBody.enableJsonSchema = type === 'Schema';
if (activeResponse.value.body.jsonBody.jsonValue === '') {
autoMakeJson();
}
}
</script>
<style lang="less" scoped>