fix: schema空参数行过滤&批量添加回显表格数据
This commit is contained in:
parent
b41eaa2d82
commit
673a1a1e23
|
@ -511,27 +511,24 @@
|
|||
:ok-text="t('common.add')"
|
||||
@confirm="applyBatchAdd"
|
||||
>
|
||||
<a-spin class="block h-full w-full" :loading="batchAddLoading">
|
||||
<MsCodeEditor
|
||||
ref="batchAddCodeEditorRef"
|
||||
v-model:model-value="batchAddValue"
|
||||
theme="vs"
|
||||
height="100%"
|
||||
:language="LanguageEnum.JSON"
|
||||
:show-full-screen="false"
|
||||
show-code-format
|
||||
>
|
||||
<template #leftTitle>
|
||||
<a-radio-group v-model:model-value="batchAddType" type="button" @change="batchAddValue = ''">
|
||||
<a-radio-group v-model:model-value="batchAddType" type="button" @change="handleBatchAddTypeChange">
|
||||
<a-radio value="json">Json</a-radio>
|
||||
<a-radio value="schema">JsonSchema</a-radio>
|
||||
</a-radio-group>
|
||||
</template>
|
||||
<template #rightTitle>
|
||||
<div v-if="batchAddType === 'json'" class="flex justify-between">
|
||||
<div class="text-[var(--color-text-4)]">
|
||||
{{ t('ms.json.schema.batchAddTip') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</MsCodeEditor>
|
||||
</a-spin>
|
||||
</MsDrawer>
|
||||
<MsDrawer
|
||||
v-model:visible="previewDrawerVisible"
|
||||
|
@ -542,7 +539,7 @@
|
|||
>
|
||||
<a-spin class="block h-full w-full" :loading="previewDrawerLoading">
|
||||
<MsCodeEditor
|
||||
v-model:model-value="activePreviewValue"
|
||||
:model-value="activePreviewValue"
|
||||
theme="vs"
|
||||
height="100%"
|
||||
:language="LanguageEnum.JSON"
|
||||
|
@ -550,7 +547,7 @@
|
|||
read-only
|
||||
>
|
||||
<template #leftTitle>
|
||||
<a-radio-group v-model:model-value="previewShowType" type="button" @change="batchAddValue = ''">
|
||||
<a-radio-group v-model:model-value="previewShowType" type="button">
|
||||
<a-radio value="json">Json</a-radio>
|
||||
<a-radio value="schema">JsonSchema</a-radio>
|
||||
</a-radio-group>
|
||||
|
@ -991,10 +988,54 @@
|
|||
}
|
||||
|
||||
const batchAddDrawerVisible = ref(false);
|
||||
const batchAddValue = ref('');
|
||||
const batchAddType = ref<'json' | 'schema'>('json');
|
||||
const batchAddLoading = ref(false);
|
||||
const batchAddCodeEditorRef = ref<InstanceType<typeof MsCodeEditor>>();
|
||||
const batchAddCurrentJson = ref('');
|
||||
const batchAddCurrentSchema = ref('');
|
||||
const batchAddValue = computed({
|
||||
get: () => (batchAddType.value === 'json' ? batchAddCurrentJson.value : batchAddCurrentSchema.value),
|
||||
set: (value) => {
|
||||
return value;
|
||||
},
|
||||
});
|
||||
|
||||
function batchAdd() {
|
||||
function handleBatchAddTypeChange(value: string | number | boolean) {
|
||||
if (value === 'json') {
|
||||
batchAddValue.value = batchAddCurrentJson.value;
|
||||
} else {
|
||||
batchAddValue.value = batchAddCurrentSchema.value;
|
||||
}
|
||||
nextTick(() => {
|
||||
batchAddCodeEditorRef.value?.format();
|
||||
});
|
||||
}
|
||||
|
||||
async function batchAdd() {
|
||||
batchAddLoading.value = true;
|
||||
let schema: JsonSchema | JsonSchemaItem | undefined;
|
||||
try {
|
||||
// 先将表格数据转换为 json schema格式
|
||||
schema = parseTableDataToJsonSchema(data.value[0] as JsonSchemaTableItem);
|
||||
batchAddCurrentSchema.value = JSON.stringify(schema);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
batchAddCurrentSchema.value = t('ms.json.schema.convertFailed');
|
||||
batchAddLoading.value = false;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 再将 json schema 转换为 json 格式
|
||||
const res = await convertJsonSchemaToJson(schema as JsonSchema);
|
||||
batchAddCurrentJson.value = res;
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
batchAddCurrentJson.value = t('ms.json.schema.convertFailed');
|
||||
} finally {
|
||||
batchAddLoading.value = false;
|
||||
}
|
||||
batchAddDrawerVisible.value = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ export default {
|
|||
'ms.json.schema.format': 'Format',
|
||||
'ms.json.schema.preview': 'Preview',
|
||||
'ms.json.schema.batchAdd': 'Batch Add',
|
||||
'ms.json.schema.batchAddTip': 'Write in the format: "key":"value", e.g. "name":"natural"',
|
||||
'ms.json.schema.convertFailed': 'Data conversion failed, please try again',
|
||||
'ms.json.schema.minItems': 'Minimum number of items',
|
||||
'ms.json.schema.maxItems': 'Maximum number of items',
|
||||
|
|
|
@ -17,7 +17,6 @@ export default {
|
|||
'ms.json.schema.format': '格式化',
|
||||
'ms.json.schema.preview': '预览',
|
||||
'ms.json.schema.batchAdd': '批量添加',
|
||||
'ms.json.schema.batchAddTip': '书写格式:"键":"值",如"nama":"natural"',
|
||||
'ms.json.schema.convertFailed': '数据转换失败,请重试',
|
||||
'ms.json.schema.minItems': '最小元素数量',
|
||||
'ms.json.schema.maxItems': '最大元素数量',
|
||||
|
|
|
@ -15,7 +15,7 @@ export function parseTableDataToJsonSchema(
|
|||
isRoot: boolean = true
|
||||
): JsonSchema | JsonSchemaItem | undefined {
|
||||
try {
|
||||
if (!schemaItem) return undefined;
|
||||
if (!schemaItem || !schemaItem.title) return undefined;
|
||||
let schema: JsonSchema | JsonSchemaItem = { type: schemaItem.type };
|
||||
|
||||
// 对于 null 类型,只设置 type 和 enable 属性
|
||||
|
|
Loading…
Reference in New Issue