<template>
  <div class="app-container">
    <div style="height:20px"></div>

    <LogTable
      type="spider"
      v-loading="listLoading"
      :data="list"
      :scrapydServerId="scrapydServerId"
      :project="project"
      :spider="spider"
      stripe
      border
    />
  </div>
</template>


<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import LogTable from './LogTable.vue';
import { getSpiderLogs } from '@/api/log';

const route = useRoute();
const scrapydServerId = ref('');
const project = ref('');
const spider = ref('');
const list = ref<any[]>([]);
const listLoading = ref(true);

async function getData() {
  listLoading.value = true;

  try {
    const res = await getSpiderLogs({
      scrapydServerId: scrapydServerId.value,
      project: project.value,
      spider: spider.value,
    });

    list.value = res.data;
  } catch (error) {
    console.error('获取爬虫日志失败:', error);
  } finally {
    listLoading.value = false;
  }
}

const handleStatusChange = () => {
  getData();
};

onMounted(() => {
  scrapydServerId.value = route.query.scrapydServerId as string;
  project.value = route.query.project as string;
  spider.value = route.query.spider as string;
  getData();
});
</script>

<style lang="scss" scoped>
</style>
