Skip to content

Commit 2bdbd2b

Browse files
committed
feat(datasource): datasource management
1 parent 6cab5f2 commit 2bdbd2b

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

frontend/src/api/datasource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export const datasourceApi = {
1919
saveTable: (data: any) => request.post('/datasource/editTable', data),
2020
saveField: (data: any) => request.post('/datasource/editField', data),
2121
getDs: (id: number) => request.post(`/datasource/get/${id}`),
22+
cancelRequests: () => request.cancelRequests(),
2223
}

frontend/src/views/ds/Datasource.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const datasourceListWithSearch = computed(() => {
5656
const beforeClose = () => {
5757
datasourceConfigvVisible.value = false
5858
activeStep.value = 0
59+
datasourceApi.cancelRequests()
5960
}
6061
const defaultDatasourceListWithSearch = computed(() => {
6162
if (!defaultDatasourceKeywords.value) return defaultDatasourceList.value

frontend/src/views/ds/DatasourceForm.vue

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import { ref, reactive, onMounted, computed, watch, nextTick } from 'vue'
2+
import { ref, reactive, onMounted, computed, watch, nextTick, onBeforeUnmount } from 'vue'
33
import { useI18n } from 'vue-i18n'
44
import { datasourceApi } from '@/api/datasource'
55
import icon_upload_outlined from '@/assets/svg/icon_upload_outlined.svg'
@@ -246,23 +246,40 @@ const save = async (formEl: FormInstance | undefined) => {
246246
if (form.value.id) {
247247
if (!isEditTable.value) {
248248
// only update datasource config info
249-
datasourceApi.update(requestObj).then(() => {
250-
close()
251-
emit('refresh')
252-
})
249+
datasourceApi
250+
.update(requestObj)
251+
.then(() => {
252+
close()
253+
emit('refresh')
254+
})
255+
.finally(() => {
256+
saveLoading.value = false
257+
})
253258
} else {
254259
// save table and field
255-
datasourceApi.chooseTables(form.value.id, list).then(() => {
256-
close()
257-
emit('refresh')
258-
})
260+
datasourceApi
261+
.chooseTables(form.value.id, list)
262+
.then(() => {
263+
close()
264+
emit('refresh')
265+
})
266+
.finally(() => {
267+
saveLoading.value = false
268+
})
259269
}
260270
} else {
261271
requestObj.tables = list
262-
datasourceApi.add(requestObj).then(() => {
263-
close()
264-
emit('refresh')
265-
})
272+
const a = datasourceApi
273+
.add(requestObj)
274+
.then(() => {
275+
close()
276+
emit('refresh')
277+
})
278+
.finally(() => {
279+
saveLoading.value = false
280+
})
281+
282+
console.log(a, 'datasourceApi')
266283
}
267284
}
268285
})
@@ -319,6 +336,8 @@ const check = () => {
319336
})
320337
}
321338
339+
onBeforeUnmount(() => (saveLoading.value = false))
340+
322341
const next = async (formEl: FormInstance | undefined) => {
323342
if (!formEl) return
324343
await formEl.validate((valid) => {
@@ -459,7 +478,7 @@ defineExpose({
459478

460479
<template>
461480
<div
462-
v-loading="uploadLoading"
481+
v-loading="uploadLoading || saveLoading"
463482
class="model-form"
464483
:class="(!isCreate || activeStep === 2) && 'edit-form'"
465484
>
@@ -691,12 +710,7 @@ defineExpose({
691710
<el-button v-show="activeStep === 1 && isCreate" type="primary" @click="next(dsFormRef)">
692711
{{ t('common.next') }}
693712
</el-button>
694-
<el-button
695-
v-show="activeStep === 2 || !isCreate"
696-
:loading="saveLoading"
697-
type="primary"
698-
@click="save(dsFormRef)"
699-
>
713+
<el-button v-show="activeStep === 2 || !isCreate" type="primary" @click="save(dsFormRef)">
700714
{{ t('common.save') }}
701715
</el-button>
702716
</div>

0 commit comments

Comments
 (0)