feat: 添加单源爬取功能并优化数据库同步
新增单源爬取功能,支持在界面上单独更新每个数据源 添加数据库同步脚本,支持主从数据库结构同步和数据同步 优化华能集团爬虫的页面导航和稳定性 新增系统托盘功能,支持最小化到托盘
This commit is contained in:
@@ -37,6 +37,20 @@
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="100" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="crawlSingleSource(row.source)"
|
||||
:loading="crawlingSources.has(row.source)"
|
||||
:disabled="crawlingSources.has(row.source)"
|
||||
>
|
||||
<el-icon><Refresh /></el-icon>
|
||||
更新
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="summary" v-if="crawlStats.length > 0">
|
||||
@@ -75,6 +89,7 @@ interface CrawlStat {
|
||||
|
||||
const crawlStats = ref<CrawlStat[]>([])
|
||||
const loading = ref(false)
|
||||
const crawlingSources = ref<Set<string>>(new Set())
|
||||
|
||||
const totalCount = computed(() => {
|
||||
return crawlStats.value.reduce((sum, item) => sum + item.count, 0)
|
||||
@@ -113,6 +128,28 @@ const fetchCrawlStats = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const crawlSingleSource = async (sourceName: string) => {
|
||||
crawlingSources.value.add(sourceName)
|
||||
try {
|
||||
ElMessage.info(`正在更新 ${sourceName}...`)
|
||||
const res = await axios.post(`/api/crawler/crawl/${encodeURIComponent(sourceName)}`)
|
||||
|
||||
if (res.data.success) {
|
||||
ElMessage.success(`${sourceName} 更新成功,获取 ${res.data.count} 条数据`)
|
||||
} else {
|
||||
ElMessage.error(`${sourceName} 更新失败: ${res.data.error || '未知错误'}`)
|
||||
}
|
||||
|
||||
// 刷新统计数据
|
||||
await fetchCrawlStats()
|
||||
} catch (error) {
|
||||
console.error('Failed to crawl single source:', error)
|
||||
ElMessage.error(`${sourceName} 更新失败`)
|
||||
} finally {
|
||||
crawlingSources.value.delete(sourceName)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchCrawlStats()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user