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, lineNumbersMinChars: 3,
lineDecorationsWidth: 0, lineDecorationsWidth: 0,
tabSize: 2, tabSize: 2,
scrollBeyondLastLine: false, //
}); });
editor.getModel()?.setEOL(monaco.editor.EndOfLineSequence.LF); // editor.getModel()?.setEOL(monaco.editor.EndOfLineSequence.LF); //

View File

@ -250,9 +250,20 @@
v-if="record.type === 'string'" v-if="record.type === 'string'"
v-model:model-value="record.format" v-model:model-value="record.format"
:options="formatOptions" :options="formatOptions"
:disabled="props.disabled"
class="ms-form-table-input" class="ms-form-table-input"
@change="emitChange('enumValuesInput')"
></a-select> ></a-select>
</template> </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 }"> <template #action="{ record, rowIndex }">
<div class="flex w-full items-center gap-[8px]"> <div class="flex w-full items-center gap-[8px]">
<a-tooltip :content="t('common.advancedSettings')"> <a-tooltip :content="t('common.advancedSettings')">
@ -312,10 +323,21 @@
:footer="!props.disabled" :footer="!props.disabled"
@confirm="applySetting" @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 <a-form-item
field="title"
:label="t('ms.json.schema.name')" :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" asterisk-position="end"
> >
<a-input <a-input
@ -536,7 +558,7 @@
</template> </template>
<script setup lang="ts"> <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 { cloneDeep } from 'lodash-es';
import MsButton from '@/components/pure/ms-button/index.vue'; import MsButton from '@/components/pure/ms-button/index.vue';
@ -823,11 +845,10 @@
title: t('ms.json.schema.regex'), title: t('ms.json.schema.regex'),
dataIndex: 'pattern', dataIndex: 'pattern',
slotName: 'pattern', slotName: 'pattern',
inputType: 'input',
size: 'medium', size: 'medium',
addLineDisabled: true, addLineDisabled: true,
showInTable: false, showInTable: false,
isNull: (record) => ['object', 'array', 'null', 'boolean'].includes(record.type), isNull: (record) => record.type !== 'string',
}, },
{ {
title: t('ms.json.schema.format'), 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() { function applySetting() {
settingFormRef.value?.validate((errors) => {
if (!errors) {
if (activeRecord.value.id === 'root') { if (activeRecord.value.id === 'root') {
data.value = [{ ...activeRecord.value }]; data.value = [{ ...activeRecord.value }];
} else { } else {
@ -1031,6 +1067,8 @@
settingDrawerVisible.value = false; settingDrawerVisible.value = false;
emitChange('applySetting'); emitChange('applySetting');
} }
});
}
const showQuickInputParam = ref(false); const showQuickInputParam = ref(false);
const activeQuickInputRecord = ref<JsonSchemaTableItem>(); const activeQuickInputRecord = ref<JsonSchemaTableItem>();

View File

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