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,21 +1036,38 @@
); );
} }
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() {
if (activeRecord.value.id === 'root') { settingFormRef.value?.validate((errors) => {
data.value = [{ ...activeRecord.value }]; if (!errors) {
} else { if (activeRecord.value.id === 'root') {
const brothers = activeRecord.value.parent?.children || []; data.value = [{ ...activeRecord.value }];
const index = brothers.findIndex((item: any) => item.id === activeRecord.value.id); } else {
if (index > -1) { const brothers = activeRecord.value.parent?.children || [];
brothers.splice(index, 1, { ...activeRecord.value }); const index = brothers.findIndex((item: any) => item.id === activeRecord.value.id);
if (index > -1) {
brothers.splice(index, 1, { ...activeRecord.value });
}
}
settingDrawerVisible.value = false;
emitChange('applySetting');
} }
} });
settingDrawerVisible.value = false;
emitChange('applySetting');
} }
const showQuickInputParam = ref(false); const showQuickInputParam = ref(false);

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>