refactor: Remove outdated files and enhance Web GUI functionality

- Deleted obsolete markdown files related to follow tab coordinates testing and results.
- Removed outdated batch scripts for launching the Web GUI.
- Updated `config.json` to improve reservation handling and adjust prize value settings.
- Enhanced logging and error handling in `web_gui.py` and `app.js` for better user experience.
- Added automatic screenshot functionality during Web GUI startup for improved monitoring.
This commit is contained in:
Your Name committed 2025-12-19 03:31:08 +08:00
1 parent b0bd7c72c8
commit 836a31d817
59 files changed
+17232 -6965

No files matched your search

+101 -18
View File
@@ -4,6 +4,7 @@ let statsTimer = null;
let shotTimer = null;
let lastLogUpdateTime = 0; // 最后成功获取日志的时间
let logErrorCount = 0; // 连续错误计数
let emptyResponseCount = 0; // 连续空响应计数(用于检测索引卡住)
const DEFAULTS = {
// 筛选
@@ -42,7 +43,11 @@ const DEFAULTS = {
high_value_room_revisit_enabled: true,
high_value_room_revisit_only_current_run: false,
reservation_back_verify_enabled: true,
// 找福袋图标相关
fudai_find_max_attempts: 5,
fudai_icon_retry_delay_seconds: 0.6,
fudai_icon_max_wait_seconds: 5.0,
live_room_match_threshold: 0.8,
reservation_preempt_min_value: 0,
reservation_back_swipe_delay: 0.6,
@@ -577,9 +582,27 @@ async function startRun() {
appendLog([`[WEB] 已开始运行:device=${deviceId || '(auto)'}`]);
// 启动时自动截图
if (deviceId) {
try {
appendLog(["[截图] 启动时自动截图..."]);
const screenshotResult = await apiPost("/api/screenshot", { device_id: deviceId });
if (screenshotResult.ok) {
appendLog(["[截图] 启动截图成功,已保存到 pic/screenshot.png"]);
// 刷新截图显示
pollShot();
} else {
appendLog([`[截图] 启动截图失败: ${screenshotResult.error || "未知错误"}`]);
}
} catch (e) {
appendLog([`[截图] 启动截图失败: ${e?.message || e}`]);
}
}
// 重置本地日志索引并清空显示区域,然后立即拉取最新日志
try {
logIdx = 0;
emptyResponseCount = 0; // 重置空响应计数
// 清空日志显示区域,准备显示新进程的日志
const logEl = $("log");
if (logEl) {
@@ -591,7 +614,12 @@ async function startRun() {
}
} catch (e) {
console.error("[WEB] startRun error:", e);
appendLog([`[WEB] 启动时出错: ${e.message || e}`]);
const errorMsg = e.message || String(e);
appendLog([`[WEB] 启动失败: ${errorMsg}`]);
// 如果是"running"错误,显示友好提示
if (errorMsg === "running" || (e.status === 409)) {
appendLog([`[WEB] 提示:已有进程在运行中,请先点击"停止"按钮`]);
}
}
}
@@ -615,6 +643,7 @@ async function stopRun() {
// 重置并拉取日志,确保能看到后端的停止确认输出
try {
logIdx = 0;
emptyResponseCount = 0; // 重置空响应计数
await pollLogs();
} catch (e) {
// ignore
@@ -632,15 +661,25 @@ async function pollLogs() {
return;
}
// 重置错误计数
// 重置错误计数(API调用成功)
logErrorCount = 0;
lastLogUpdateTime = Date.now();
// 记录API调用成功的时间(即使没有新日志,也说明连接正常)
const apiCallTime = Date.now();
// 先检查索引是否异常(后端返回的next小于当前索引,说明日志被截断了)
const nextIdx = typeof data.next === 'number' ? data.next : logIdx;
// 获取返回的索引
const nextIdx = typeof data.next === 'number' ? data.next : 0;
// 如果返回的索引小于当前索引,说明日志被截断了,需要重置
// 或者如果返回了所有日志(lines数量很大),也可能是重置了索引
if (nextIdx < logIdx && logIdx > 0) {
console.warn('[WEB_DBG] pollLogs: 检测到日志截断,重置索引', { oldIdx: logIdx, newIdx: nextIdx });
logIdx = 0;
emptyResponseCount = 0; // 重置空响应计数
// 清空日志显示区域,准备重新显示
const log = document.getElementById('log');
if (log) {
log.textContent = '';
}
// 重新请求一次以获取所有日志
const retryData = await apiGet(`/api/logs?since=0`);
if (retryData && typeof retryData === 'object' && Array.isArray(retryData.lines)) {
@@ -653,28 +692,26 @@ async function pollLogs() {
}
// 更新日志索引
if (typeof data.next === 'number') {
logIdx = data.next;
}
logIdx = nextIdx;
// API调用成功,更新最后更新时间(不管是否有新日志)
lastLogUpdateTime = apiCallTime;
// 追加日志
if (Array.isArray(data.lines) && data.lines.length > 0) {
appendLog(data.lines);
lastLogUpdateTime = Date.now();
emptyResponseCount = 0; // 重置空响应计数
} else {
// 没有新日志是正常的(比如脚本没有运行),不需要重置索引
// 只有在检测到索引不同步时才重置(已在前面处理)
emptyResponseCount++;
// 移除自动重置逻辑,避免在没有新日志时频繁清空日志显示
}
// 容错:确保索引不为负数
if (logIdx < 0) {
console.warn('[WEB_DBG] pollLogs: logIdx为负数,重置为0');
logIdx = 0;
}
// 如果超过30秒没有获取到新日志且索引很大,可能是索引卡住了,重置索引
const now = Date.now();
if (lastLogUpdateTime > 0 && (now - lastLogUpdateTime > 30000) && logIdx > 1000) {
console.warn('[WEB_DBG] pollLogs: 长时间未更新,重置索引尝试恢复', { logIdx, lastUpdate: now - lastLogUpdateTime });
logIdx = 0;
lastLogUpdateTime = 0;
emptyResponseCount = 0;
}
} catch (e) {
logErrorCount++;
@@ -684,6 +721,7 @@ async function pollLogs() {
console.warn('[WEB_DBG] pollLogs: 连续10次错误,重置索引');
logIdx = 0;
logErrorCount = 0;
emptyResponseCount = 0; // 重置空响应计数
}
// 错误时不追加日志到界面,避免刷屏,只在控制台输出
// 如果是网络错误或超时,不重置索引;如果是其他错误,考虑重置
@@ -693,6 +731,7 @@ async function pollLogs() {
if (e.message.includes('JSON') || e.message.includes('parse')) {
console.warn('[WEB_DBG] pollLogs: 数据解析错误,重置索引');
logIdx = 0;
emptyResponseCount = 0; // 重置空响应计数
}
}
}
@@ -1031,6 +1070,50 @@ window.addEventListener("DOMContentLoaded", async () => {
$("btnSave").addEventListener("click", async () => { await saveConfig(); });
$("btnStart").addEventListener("click", async () => { await startRun(); });
$("btnStop").addEventListener("click", async () => { await stopRun(); });
// 截图按钮
$("btnScreenshot").addEventListener("click", async () => {
const deviceId = $("device").value || "";
if (!deviceId) {
appendLog(["[截图] 请先选择设备"]);
return;
}
try {
appendLog(["[截图] 正在截图..."]);
const result = await apiPost("/api/screenshot", { device_id: deviceId });
if (result.ok) {
appendLog(["[截图] 截图成功,已保存到 pic/screenshot.png"]);
// 刷新截图显示
pollShot();
} else {
appendLog([`[截图] 截图失败: ${result.error || "未知错误"}`]);
}
} catch (e) {
appendLog([`[截图] 截图失败: ${e?.message || e}`]);
}
});
// 截图按钮
$("btnScreenshot").addEventListener("click", async () => {
const deviceId = $("device").value || "";
if (!deviceId) {
appendLog(["[截图] 请先选择设备"]);
return;
}
try {
appendLog(["[截图] 正在截图..."]);
const result = await apiPost("/api/screenshot", { device_id: deviceId });
if (result.ok) {
appendLog(["[截图] 截图成功,已保存到 pic/screenshot.png"]);
// 刷新截图显示
pollShot();
} else {
appendLog([`[截图] 截图失败: ${result.error || "未知错误"}`]);
}
} catch (e) {
appendLog([`[截图] 截图失败: ${e?.message || e}`]);
}
});
await refreshDevices();
await loadConfig();
@@ -1043,4 +1126,4 @@ window.addEventListener("DOMContentLoaded", async () => {
pollShot();
pollReservations();
pollHighValueRooms();
});
});