From b0d98b78d97a5a07347d9f877d7626a10ea06eed Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Mon, 13 Jul 2026 23:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=81=9C=E6=AD=A2=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=9A=E6=90=9C=E7=B4=A2=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=E5=8D=B3=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 搜索开始就显示停止按钮 - 搜索完成后隐藏,自动抓取时再显示 - 整个流程中都可以随时停止 --- static/js/search.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/static/js/search.js b/static/js/search.js index c2818be..9d6f5a2 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -45,9 +45,11 @@ async function doSearch() { updateStatus('searching', `正在通过 ${engineNames[engine]} 搜索...`); document.getElementById('search-btn').disabled = true; - // 显示进度 + // 显示进度和停止按钮 + shouldStop = false; const progress = document.getElementById('search-progress'); progress.style.display = 'block'; + document.getElementById('stop-btn').style.display = 'inline-flex'; document.getElementById('progress-fill').style.width = '0%'; document.getElementById('progress-text').textContent = '正在搜索...'; @@ -70,6 +72,14 @@ async function doSearch() { displayResults(); + // 检查是否被停止 + if (shouldStop) { + document.getElementById('stop-btn').style.display = 'none'; + document.getElementById('progress-text').textContent = '已停止'; + updateStatus('warning', '搜索已停止'); + return; + } + // 显示缓存状态 if (data.cached) { updateStatus('success', `找到 ${searchResults.length} 条结果(使用缓存)`); @@ -83,25 +93,28 @@ async function doSearch() { document.getElementById('progress-fill').style.width = '100%'; document.getElementById('progress-text').textContent = '搜索完成!'; + document.getElementById('stop-btn').style.display = 'none'; // 隐藏停止按钮 // 自动抓取和保存 if (autoFetch && searchResults.length > 0) { setTimeout(() => fetchAllResults(autoSave), 500); + } else { + setTimeout(() => { + progress.style.display = 'none'; + }, 1000); } } else { + document.getElementById('stop-btn').style.display = 'none'; updateStatus('error', '搜索失败'); showToast('搜索失败: ' + data.error, 'error'); } } catch (error) { + document.getElementById('stop-btn').style.display = 'none'; updateStatus('error', '搜索出错'); showToast('搜索出错', 'error'); console.error(error); } - setTimeout(() => { - progress.style.display = 'none'; - }, 1000); - document.getElementById('search-btn').disabled = false; }