feat: priority crawl UI to dashboard

This commit is contained in:
2026-04-11 19:54:24 +08:00
parent 67a5f7cfab
commit 7ba2011ead
3 changed files with 59 additions and 189 deletions
+58 -2
View File
@@ -1,6 +1,6 @@
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { fetchStats, flushIndex, fetchFlushStatus, fetchWorkers, setWorkers, fetchBacklink, triggerBacklink, fetchPriorityStatus, fetchCrawlStatus } from '../api.js'
import { fetchStats, flushIndex, fetchFlushStatus, fetchWorkers, setWorkers, fetchBacklink, triggerBacklink, fetchPriorityStatus, fetchCrawlStatus, addPriority } from '../api.js'
const stats = ref(null)
const loading = ref(true)
@@ -15,7 +15,9 @@ const workersInput = ref(0)
const workersSaving = ref(false)
// Priority 相关状态
const priorityStatus = ref(null) // { pending, active, max_workers, children_queue }
const priorityStatus = ref(null) // { level1, level2_queue, level2_inflight, active, max_workers }
const batchUrls = ref('')
const batchAdding = ref(false)
// 爬取状态
const crawlStatus = ref(null) // { current_epoch, max_epoch, queue_length, completed_count, visited_total, is_running }
@@ -172,6 +174,44 @@ function langColor(lang) {
const map = { zh: '#e53e3e', en: '#3182ce', ja: '#e53e3e', ko: '#3182ce', fr: '#38a169', de: '#d69e2e', es: '#38a169', ru: '#805ad5', other: '#718096' }
return map[lang] || map.other
}
function isValidUrl(s) {
try {
const u = new URL(s)
return u.protocol === 'http:' || u.protocol === 'https:'
} catch {
return false
}
}
async function doBatchAdd() {
const lines = batchUrls.value.split('\n').map(l => l.trim()).filter(l => l)
const valid = lines.filter(isValidUrl)
if (valid.length === 0) {
error.value = '未检测到有效 URL'
return
}
batchAdding.value = true
let ok = 0, fail = 0
try {
for (const url of valid) {
try {
await addPriority(url)
ok++
} catch {
fail++
}
}
batchUrls.value = ''
await loadPriorityStatus()
error.value = null
if (fail > 0) {
error.value = `添加完成:${ok} 成功,${fail} 失败`
}
} finally {
batchAdding.value = false
}
}
</script>
<template>
@@ -255,6 +295,22 @@ function langColor(lang) {
<div class="text-2xl font-bold text-blue-400">{{ priorityStatus.max_workers }}</div>
</div>
</div>
<!-- 批量添加 -->
<div class="mt-4 flex gap-2">
<textarea
v-model="batchUrls"
rows="3"
placeholder="批量添加 URL(每行一个,仅发送有效链接)"
class="flex-1 bg-gray-800 border border-gray-700 text-gray-200 text-sm rounded-lg px-3 py-2 resize-none focus:outline-none focus:border-blue-500 placeholder-gray-600"
></textarea>
<button
class="bg-blue-700 hover:bg-blue-600 disabled:bg-gray-700 text-white text-sm font-medium px-4 py-2 rounded-lg transition-colors cursor-pointer whitespace-nowrap self-end"
:disabled="batchAdding || !batchUrls.trim()"
@click="doBatchAdd"
>
{{ batchAdding ? '添加中...' : '批量添加' }}
</button>
</div>
</div>
<!-- 爬取进度 -->