diff --git a/frontend/crawlab-ui/src/components/core/spider/SpiderForm.vue b/frontend/crawlab-ui/src/components/core/spider/SpiderForm.vue index 26156f87..ba36663b 100644 --- a/frontend/crawlab-ui/src/components/core/spider/SpiderForm.vue +++ b/frontend/crawlab-ui/src/components/core/spider/SpiderForm.vue @@ -8,10 +8,13 @@ import { isZeroObjectId } from '@/utils/mongo'; import { useSpiderDetail } from '@/views'; import { getToRunNodes, priorityOptions, translate } from '@/utils'; import { getSpiderTemplateGroups, getSpiderTemplates } from '@/utils/spider'; +import useRequest from '@/services/request'; // i18n const t = translate; +const { get } = useRequest(); + // store const store = useStore(); @@ -90,6 +93,29 @@ const activeTemplateOption = computed(() => { return getSpiderTemplates().find(d => d.name === form.value.template); }); +const projectLoading = ref(false); +const projectList = ref([]); +const getProjects = async (query?: string) => { + try { + projectLoading.value = true; + const res = await get('/projects', { + conditions: { + name: query, + }, + limit: 1000, + }); + projectList.value = res.data || []; + } catch (e) { + console.error('Error setting project loading state:', e); + } finally { + projectLoading.value = false; + } +}; + +const getActiveNodes = async () => { + await store.dispatch('node/getActiveNodes'); +}; + defineExpose({ validate, }); diff --git a/frontend/crawlab-ui/src/interfaces/store/modules/node.d.ts b/frontend/crawlab-ui/src/interfaces/store/modules/node.d.ts index d4eb3ff7..8195776c 100644 --- a/frontend/crawlab-ui/src/interfaces/store/modules/node.d.ts +++ b/frontend/crawlab-ui/src/interfaces/store/modules/node.d.ts @@ -13,9 +13,8 @@ interface NodeStoreState extends BaseStoreState { type NodeStoreGetters = BaseStoreGetters; interface NodeStoreMutations extends BaseStoreMutations { - setAllNodeSelectOptions: StoreMutation, SelectOption[]>; - setAllNodeTags: StoreMutation, string[]>; setNodeMetricsMap: StoreMutation>; + setActiveNodes: StoreMutation; } interface NodeStoreActions extends BaseStoreActions { diff --git a/frontend/crawlab-ui/src/store/modules/node.ts b/frontend/crawlab-ui/src/store/modules/node.ts index 03792b3d..9ac63d22 100644 --- a/frontend/crawlab-ui/src/store/modules/node.ts +++ b/frontend/crawlab-ui/src/store/modules/node.ts @@ -15,19 +15,13 @@ const { get } = useRequest(); const state = { ...getDefaultStoreState('node'), - newFormFn: () => { - return { - tags: [], - max_runners: 8, - enabled: true, - }; - }, tabs: [ { id: TAB_NAME_OVERVIEW, title: 'common.tabs.overview' }, { id: TAB_NAME_TASKS, title: 'common.tabs.tasks' }, { id: TAB_NAME_MONITORING, title: 'common.tabs.monitoring' }, ], nodeMetricsMap: {}, + activeNodes: [], } as NodeStoreState; const getters = { @@ -39,13 +33,16 @@ const mutations = { setNodeMetricsMap(state: NodeStoreState, metricsMap: Record) { state.nodeMetricsMap = metricsMap; }, + setActiveNodes: (state: NodeStoreState, activeNodes: CNode[]) => { + state.activeNodes = activeNodes; + }, } as NodeStoreMutations; const actions = { ...getDefaultStoreActions('/nodes'), async getNodeMetrics({ state, commit }: StoreActionContext) { const { page, size } = state.tablePagination; - const res = await get>('nodes/metrics', { + const res = await get>('/nodes/metrics', { page, size, conditions: JSON.stringify(state.tableListFilter), @@ -54,6 +51,11 @@ const actions = { commit('setNodeMetricsMap', res.data); return res; }, + async getActiveNodes({ commit }: StoreActionContext) { + const res = await get('/nodes'); + commit('setActiveNodes', res.data || []); + return res; + }, } as NodeStoreActions; export default {