修复停止按钮:搜索开始时即显示
- 搜索开始就显示停止按钮 - 搜索完成后隐藏,自动抓取时再显示 - 整个流程中都可以随时停止
This commit is contained in:
+18
-5
@@ -45,9 +45,11 @@ async function doSearch() {
|
|||||||
updateStatus('searching', `正在通过 ${engineNames[engine]} 搜索...`);
|
updateStatus('searching', `正在通过 ${engineNames[engine]} 搜索...`);
|
||||||
document.getElementById('search-btn').disabled = true;
|
document.getElementById('search-btn').disabled = true;
|
||||||
|
|
||||||
// 显示进度
|
// 显示进度和停止按钮
|
||||||
|
shouldStop = false;
|
||||||
const progress = document.getElementById('search-progress');
|
const progress = document.getElementById('search-progress');
|
||||||
progress.style.display = 'block';
|
progress.style.display = 'block';
|
||||||
|
document.getElementById('stop-btn').style.display = 'inline-flex';
|
||||||
document.getElementById('progress-fill').style.width = '0%';
|
document.getElementById('progress-fill').style.width = '0%';
|
||||||
document.getElementById('progress-text').textContent = '正在搜索...';
|
document.getElementById('progress-text').textContent = '正在搜索...';
|
||||||
|
|
||||||
@@ -70,6 +72,14 @@ async function doSearch() {
|
|||||||
|
|
||||||
displayResults();
|
displayResults();
|
||||||
|
|
||||||
|
// 检查是否被停止
|
||||||
|
if (shouldStop) {
|
||||||
|
document.getElementById('stop-btn').style.display = 'none';
|
||||||
|
document.getElementById('progress-text').textContent = '已停止';
|
||||||
|
updateStatus('warning', '搜索已停止');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 显示缓存状态
|
// 显示缓存状态
|
||||||
if (data.cached) {
|
if (data.cached) {
|
||||||
updateStatus('success', `找到 ${searchResults.length} 条结果(使用缓存)`);
|
updateStatus('success', `找到 ${searchResults.length} 条结果(使用缓存)`);
|
||||||
@@ -83,25 +93,28 @@ async function doSearch() {
|
|||||||
|
|
||||||
document.getElementById('progress-fill').style.width = '100%';
|
document.getElementById('progress-fill').style.width = '100%';
|
||||||
document.getElementById('progress-text').textContent = '搜索完成!';
|
document.getElementById('progress-text').textContent = '搜索完成!';
|
||||||
|
document.getElementById('stop-btn').style.display = 'none'; // 隐藏停止按钮
|
||||||
|
|
||||||
// 自动抓取和保存
|
// 自动抓取和保存
|
||||||
if (autoFetch && searchResults.length > 0) {
|
if (autoFetch && searchResults.length > 0) {
|
||||||
setTimeout(() => fetchAllResults(autoSave), 500);
|
setTimeout(() => fetchAllResults(autoSave), 500);
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
progress.style.display = 'none';
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
document.getElementById('stop-btn').style.display = 'none';
|
||||||
updateStatus('error', '搜索失败');
|
updateStatus('error', '搜索失败');
|
||||||
showToast('搜索失败: ' + data.error, 'error');
|
showToast('搜索失败: ' + data.error, 'error');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
document.getElementById('stop-btn').style.display = 'none';
|
||||||
updateStatus('error', '搜索出错');
|
updateStatus('error', '搜索出错');
|
||||||
showToast('搜索出错', 'error');
|
showToast('搜索出错', 'error');
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
progress.style.display = 'none';
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
document.getElementById('search-btn').disabled = false;
|
document.getElementById('search-btn').disabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user