Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0d98b78d9 | ||
|
|
d63fe2f671 |
@@ -151,6 +151,13 @@
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.progress-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* 结果区域 */
|
||||
.results-section {
|
||||
background: white;
|
||||
|
||||
+41
-5
@@ -5,6 +5,9 @@ const API_BASE = '';
|
||||
let searchResults = [];
|
||||
let currentResultIndex = -1;
|
||||
|
||||
// 自动流程控制
|
||||
let shouldStop = false;
|
||||
|
||||
// 页面加载初始化
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// 回车搜索
|
||||
@@ -42,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 = '正在搜索...';
|
||||
|
||||
@@ -67,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} 条结果(使用缓存)`);
|
||||
@@ -80,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;
|
||||
}
|
||||
|
||||
@@ -338,13 +354,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 +391,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 +403,11 @@ async function fetchAllResults(autoSave) {
|
||||
}
|
||||
}
|
||||
|
||||
// 停止自动处理
|
||||
function stopAutoProcess() {
|
||||
shouldStop = true;
|
||||
}
|
||||
|
||||
// 显示结果详情
|
||||
function showResultDetail(index) {
|
||||
currentResultIndex = index;
|
||||
|
||||
@@ -62,7 +62,12 @@
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill" id="progress-fill"></div>
|
||||
</div>
|
||||
<div class="progress-text" id="progress-text">正在搜索...</div>
|
||||
<div class="progress-info">
|
||||
<span class="progress-text" id="progress-text">正在搜索...</span>
|
||||
<button onclick="stopAutoProcess()" class="btn btn-danger btn-sm" id="stop-btn" style="display: none;">
|
||||
<i class="ri-stop-line"></i> 停止
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 搜索结果 -->
|
||||
|
||||
Reference in New Issue
Block a user