新增自动抓取停止功能
- 添加停止按钮,自动抓取时显示 - 点击可随时终止自动抓取流程 - 显示已停止状态和已抓取数量
This commit is contained in:
@@ -5,6 +5,9 @@ const API_BASE = '';
|
||||
let searchResults = [];
|
||||
let currentResultIndex = -1;
|
||||
|
||||
// 自动流程控制
|
||||
let shouldStop = false;
|
||||
|
||||
// 页面加载初始化
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// 回车搜索
|
||||
@@ -338,13 +341,27 @@ async function saveAllResults() {
|
||||
|
||||
// 抓取所有结果
|
||||
async function fetchAllResults(autoSave) {
|
||||
shouldStop = false; // 重置停止标志
|
||||
|
||||
const progress = document.getElementById('search-progress');
|
||||
progress.style.display = 'block';
|
||||
document.getElementById('stop-btn').style.display = 'inline-flex'; // 显示停止按钮
|
||||
|
||||
const total = searchResults.length;
|
||||
let fetched = 0;
|
||||
|
||||
for (let i = 0; i < searchResults.length; i++) {
|
||||
// 检查是否停止
|
||||
if (shouldStop) {
|
||||
document.getElementById('progress-text').textContent = `已停止(已抓取 ${fetched}/${total})`;
|
||||
document.getElementById('stop-btn').style.display = 'none';
|
||||
setTimeout(() => {
|
||||
progress.style.display = 'none';
|
||||
}, 2000);
|
||||
showToast('自动抓取已停止', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchResults[i].fetched) {
|
||||
fetched++;
|
||||
continue;
|
||||
@@ -361,6 +378,7 @@ async function fetchAllResults(autoSave) {
|
||||
|
||||
document.getElementById('progress-fill').style.width = '100%';
|
||||
document.getElementById('progress-text').textContent = '抓取完成!';
|
||||
document.getElementById('stop-btn').style.display = 'none';
|
||||
|
||||
setTimeout(() => {
|
||||
progress.style.display = 'none';
|
||||
@@ -372,6 +390,11 @@ async function fetchAllResults(autoSave) {
|
||||
}
|
||||
}
|
||||
|
||||
// 停止自动处理
|
||||
function stopAutoProcess() {
|
||||
shouldStop = true;
|
||||
}
|
||||
|
||||
// 显示结果详情
|
||||
function showResultDetail(index) {
|
||||
currentResultIndex = index;
|
||||
|
||||
Reference in New Issue
Block a user