diff --git a/src/store/modules/spider.ts b/src/store/modules/spider.ts index db2387101345f..034d502d13ad7 100644 --- a/src/store/modules/spider.ts +++ b/src/store/modules/spider.ts @@ -20,6 +20,7 @@ import { getBaseFileStoreMutations, getBaseFileStoreState, } from '@/store/utils/file'; +import { ElMessage } from 'element-plus'; // i18n const t = translate; @@ -119,9 +120,14 @@ const actions = { { commit }: StoreActionContext, id: string ) => { - const res = await get(`/databases/${id}/metadata`); - commit('setDatabaseMetadata', res.data); - return res.data; + try { + const res = await get(`/databases/${id}/metadata`); + commit('setDatabaseMetadata', res.data); + return res.data; + } catch (e: any) { + ElMessage.error(e.message); + commit('setDatabaseMetadata', undefined); + } }, } as SpiderStoreActions; diff --git a/src/views/spider/detail/actions/SpiderDetailActionsData.vue b/src/views/spider/detail/actions/SpiderDetailActionsData.vue index b5cf575bd57e9..42e7b48a76688 100644 --- a/src/views/spider/detail/actions/SpiderDetailActionsData.vue +++ b/src/views/spider/detail/actions/SpiderDetailActionsData.vue @@ -7,6 +7,7 @@ import { useDatabase } from '@/components'; import useRequest from '@/services/request'; import { useSpiderDetail } from '@/views'; import { debounce } from 'lodash'; +import { DATABASE_STATUS_OFFLINE } from '@/constants/database'; const t = translate; @@ -15,7 +16,8 @@ const { get } = useRequest(); // store const ns = 'spider'; const store = useStore(); -const { spider: state } = store.state as RootStoreState; +const { spider: state, database: databaseState } = + store.state as RootStoreState; // display all fields const displayAllFields = ref(state.dataDisplayAllFields); @@ -27,14 +29,51 @@ const form = computed(() => state.form); const { activeId } = useSpiderDetail(); -const { - allListSelectOptions: allDatabaseSelectOptions, - allDict: allDatabaseDict, -} = useDatabase(store); +const { allDict: allDatabaseDict } = useDatabase(store); onBeforeMount(() => { store.dispatch(`database/getAllList`); }); +const allDatabaseSelectOptions = computed(() => { + return databaseState.allList.map(db => { + const value = db._id; + let dbName = db.name; + if (db._id === EMPTY_OBJECT_ID) { + dbName = t('components.database.default.name'); + } + let label = dbName; + if (db.status === DATABASE_STATUS_OFFLINE) { + label = `${dbName} (${t('components.database.status.label.offline')})`; + } + return { + value, + label, + }; + }); +}); + +const currentDatabase = computed(() => { + return allDatabaseDict.value.get(dataSourceId.value) as Database | undefined; +}); + +const isDatabaseOffline = computed(() => { + return currentDatabase.value?.status === DATABASE_STATUS_OFFLINE; +}); + +const isDatabaseTableMissing = computed(() => { + if (isMultiDatabases.value) { + return !databaseTableSelectOptions.value.some( + op => + op.value === form.value?.db_name && + op.children?.some(c => c.value === form.value?.col_name) + ); + } else { + return !databaseTableSelectOptions.value.some( + op => op.value === form.value?.col_name + ); + } +}); + const databaseMetadata = computed(() => state.databaseMetadata); const isMultiDatabases = computed(() => { if (!databaseMetadata.value?.databases?.length) return false; @@ -153,6 +192,7 @@ defineOptions({ name: 'ClSpiderDetailActionsData' }); @@ -197,10 +237,12 @@ defineOptions({ name: 'ClSpiderDetailActionsData' });