diff --git a/packages/nc-gui-v2/components/dlg/QuickImport.vue b/packages/nc-gui-v2/components/dlg/QuickImport.vue index 9db0e84bf7..ce48653783 100644 --- a/packages/nc-gui-v2/components/dlg/QuickImport.vue +++ b/packages/nc-gui-v2/components/dlg/QuickImport.vue @@ -35,7 +35,7 @@ const templateEditorModal = ref(false) const useForm = Form.useForm const importState = reactive({ - fileList: [], + fileList: [] as Record, url: '', jsonEditor: {}, parserConfig: { @@ -45,15 +45,21 @@ const importState = reactive({ }, }) +const isImportTypeJson = computed(() => importType === 'json') + +const isImportTypeCsv = computed(() => importType === 'csv') + +const IsImportTypeExcel = computed(() => importType === 'excel') + const validators = computed(() => { return { - url: [fieldRequiredValidator, importUrlValidator, importType === 'csv' ? importCsvUrlValidator : importExcelUrlValidator], + url: [fieldRequiredValidator, importUrlValidator, isImportTypeCsv.value ? importCsvUrlValidator : importExcelUrlValidator], maxRowsToParse: [fieldRequiredValidator], } }) const importMeta = computed(() => { - if (importType === 'excel') { + if (IsImportTypeExcel.value) { return { header: 'QUICK IMPORT - EXCEL', uploadHint: t('msg.info.excelSupport'), @@ -61,7 +67,7 @@ const importMeta = computed(() => { loadUrlDirective: ['c:quick-import:excel:load-url'], acceptTypes: '.xls, .xlsx, .xlsm, .ods, .ots', } - } else if (importType === 'csv') { + } else if (isImportTypeCsv.value) { return { header: 'QUICK IMPORT - CSV', uploadHint: '', @@ -69,7 +75,7 @@ const importMeta = computed(() => { loadUrlDirective: ['c:quick-import:csv:load-url'], acceptTypes: '.csv', } - } else if (importType === 'json') { + } else if (isImportTypeJson.value) { return { header: 'QUICK IMPORT - JSON', uploadHint: '', @@ -93,10 +99,7 @@ const { resetFields, validate, validateInfos } = useForm(importState, validators async function handlePreImport() { loading.value = true if (activeKey.value === 'uploadTab') { - // FIXME: - importState.fileList.map(async (file: any) => { - await parseAndExtractData(file.data, file.name) - }) + await parseAndExtractData(importState.fileList[0].data, importState.fileList[0].name) } else if (activeKey.value === 'urlTab') { try { await validate() @@ -138,10 +141,6 @@ async function parseAndExtractData(val: any, name: string) { } } -function handleDrop(e: DragEvent) { - console.log(e) -} - function rejectDrop(fileList: any[]) { fileList.map((file) => { return toast.error(`Failed to upload file ${file.name}`) @@ -182,13 +181,13 @@ function populateUniqueTableName() { } function getAdapter(name: string, val: any) { - if (importType === 'excel' || importType === 'csv') { + if (IsImportTypeExcel.value || isImportTypeCsv.value) { if (activeKey.value === 'uploadTab') { return new ExcelTemplateAdapter(name, val, importState.parserConfig) } else if (activeKey.value === 'urlTab') { return new ExcelUrlTemplateAdapter(val, importState.parserConfig) } - } else if (importType === 'json') { + } else if (isImportTypeJson.value) { if (activeKey.value === 'uploadTab') { return new JSONTemplateAdapter(name, val, importState.parserConfig) } else if (activeKey.value === 'urlTab') { @@ -197,7 +196,7 @@ function getAdapter(name: string, val: any) { return new JSONTemplateAdapter(name, val, importState.parserConfig) } } - return {} + return null } @@ -236,7 +235,6 @@ function getAdapter(name: string, val: any) { :max-count="1" list-type="picture" @change="handleChange" - @drop="handleDrop" @reject="rejectDrop" > @@ -247,7 +245,7 @@ function getAdapter(name: string, val: any) { - +