forked from element-plus/element-plus
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated spider data related modules
- Loading branch information
Showing
8 changed files
with
271 additions
and
133 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
src/components/core/spider/SpiderResultDataWithDatabase.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<script setup lang="ts"> | ||
import { computed, onBeforeMount, ref, watch } from 'vue'; | ||
import { useStore } from 'vuex'; | ||
import { ElMessage } from 'element-plus'; | ||
import { debounce } from 'lodash'; | ||
import { TAB_NAME_DATA } from '@/constants'; | ||
import { EMPTY_OBJECT_ID, translate } from '@/utils'; | ||
import useRequest from '@/services/request'; | ||
import { ClDatabaseTableDetailData } from '@/components'; | ||
import { useSpider } from '@/components'; | ||
const t = translate; | ||
const { get, post } = useRequest(); | ||
const dataRef = ref<typeof ClDatabaseTableDetailData | null>(null); | ||
// store | ||
const ns: ListStoreNamespace = 'spider'; | ||
const store = useStore(); | ||
const { spider: state } = store.state; | ||
const displayAllFields = computed<boolean>(() => state.dataDisplayAllFields); | ||
const { form } = useSpider(store); | ||
const databaseMetadata = computed(() => state.databaseMetadata); | ||
const getDatabaseMetadata = debounce(async () => { | ||
if (!form.value?.data_source_id) return; | ||
await store.dispatch(`${ns}/getDatabaseMetadata`, form.value.data_source_id); | ||
}); | ||
watch(() => form.value?.data_source_id, getDatabaseMetadata); | ||
const activeTable = ref<DatabaseTable>(); | ||
const getActiveTable = debounce(async () => { | ||
const { data_source_id, col_name } = form.value; | ||
if (!data_source_id || !col_name) return; | ||
const res = await post<any, Promise<ResponseWithData>>( | ||
`/databases/${data_source_id}/tables/metadata/get`, | ||
{ | ||
table: col_name, | ||
filter: dataFilter.value, | ||
} | ||
); | ||
activeTable.value = res.data; | ||
}); | ||
onBeforeMount(getActiveTable); | ||
watch(() => form.value?.col_name, getActiveTable); | ||
watch(databaseMetadata, getActiveTable); | ||
const activeTabName = ref<string>(TAB_NAME_DATA); | ||
const tabsItems = computed<NavItem[]>(() => [ | ||
{ | ||
id: TAB_NAME_DATA, | ||
title: t('common.tabs.data'), | ||
}, | ||
]); | ||
const hasChanges = computed<boolean>(() => dataRef.value?.hasChanges); | ||
const commitLoading = ref(false); | ||
const onCommit = async () => { | ||
commitLoading.value = true; | ||
try { | ||
switch (activeTabName.value) { | ||
case TAB_NAME_DATA: | ||
await dataRef.value?.commit?.(); | ||
break; | ||
} | ||
ElMessage.success(t('common.message.success.action')); | ||
} catch (error: any) { | ||
ElMessage.error(error.message); | ||
throw error; | ||
} finally { | ||
commitLoading.value = false; | ||
} | ||
}; | ||
const onRollback = () => { | ||
dataRef.value?.rollback?.(); | ||
}; | ||
const dataFilter = computed<{ [key: string]: any } | undefined>(() => { | ||
if (!form.value?._id) return; | ||
return { | ||
_sid: form.value._id, | ||
}; | ||
}); | ||
defineOptions({ name: 'ClSpiderResultDataWithDatabase' }); | ||
</script> | ||
|
||
<template> | ||
<div class="spider-result-data-with-database"> | ||
<cl-database-nav-tabs | ||
v-model="activeTabName" | ||
:tabs-items="tabsItems" | ||
:can-save="hasChanges" | ||
:commit-loading="commitLoading" | ||
@commit="onCommit" | ||
@rollback="onRollback" | ||
/> | ||
<template v-if="activeTabName === TAB_NAME_DATA"> | ||
<cl-database-table-detail-data | ||
v-if="activeTable" | ||
ref="dataRef" | ||
:active-table="activeTable" | ||
:active-id="form?.data_source_id || EMPTY_OBJECT_ID" | ||
:filter="dataFilter" | ||
/> | ||
</template> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.