Browse Source

feat(gui-v2): handleImport

pull/2795/head
Wing-Kam Wong 2 years ago
parent
commit
bef2146f26
  1. 24
      packages/nc-gui-v2/components/dlg/FileImport.vue

24
packages/nc-gui-v2/components/dlg/FileImport.vue

@ -30,7 +30,7 @@ const importData = ref()
const templateEditorModal = ref(false) const templateEditorModal = ref(false)
const useForm = Form.useForm const useForm = Form.useForm
const importState = ref({ const importState = reactive({
fileList: [], fileList: [],
url: { url: {
value: '', value: '',
@ -118,18 +118,20 @@ const formatJson = () => {
jsonEditorRef.value.format() jsonEditorRef.value.format()
} }
const handleSubmit = () => { const handleImport = async () => {
if (activeKey.value === 'upload') { if (activeKey.value === 'upload') {
// TODO importState.fileList.map(async (file: any) => {
await parseAndExtractData('file', file.orginFileObj, file.name)
})
} else if (activeKey.value === 'url') { } else if (activeKey.value === 'url') {
// TODO
try { try {
validate() await validate()
} catch (e) { await parseAndExtractData('url', importState.url.value, '')
// TODO } catch (e: any) {
toast.error(await extractSdkResponseErrorMsg(e))
} }
} else if (activeKey.value === 'json') { } else if (activeKey.value === 'json') {
// TODO await parseAndExtractData('string', JSON.stringify(importState.json.value), '')
} }
} }
@ -141,7 +143,7 @@ const populateUniqueTableName = () => {
return `Sheet${c}` return `Sheet${c}`
} }
const parseAndExtractData = async (type: string, val: string, name: string) => { const parseAndExtractData = async (type: string, val: any, name: string) => {
try { try {
let templateGenerator let templateGenerator
templateData.value = null templateData.value = null
@ -176,7 +178,7 @@ const parseAndExtractData = async (type: string, val: string, name: string) => {
<template #footer> <template #footer>
<a-button key="back" @click="dialogShow = false">{{ $t('general.cancel') }}</a-button> <a-button key="back" @click="dialogShow = false">{{ $t('general.cancel') }}</a-button>
<a-button v-if="activeKey === 'json'" key="format" :loading="loading" @click="formatJson">Format JSON</a-button> <a-button v-if="activeKey === 'json'" key="format" :loading="loading" @click="formatJson">Format JSON</a-button>
<a-button key="submit" type="primary" :loading="loading" @click="handleSubmit">Import</a-button> <a-button key="submit" type="primary" :loading="loading" @click="handleImport">Import</a-button>
</template> </template>
<a-tabs v-model:activeKey="activeKey" hide-add type="editable-card" :tab-position="top"> <a-tabs v-model:activeKey="activeKey" hide-add type="editable-card" :tab-position="top">
<a-tab-pane key="upload" :closable="false"> <a-tab-pane key="upload" :closable="false">
@ -240,4 +242,4 @@ const parseAndExtractData = async (type: string, val: string, name: string) => {
overflow: auto; overflow: auto;
height: 300px; height: 300px;
} }
</style> </style>

Loading…
Cancel
Save