Complete missing Web GUI controls

This commit is contained in:
Your Name committed 2026-05-20 17:54:40 +08:00
1 parent 8368f1f3b7
commit 89128deb0f
3 files changed
+762 -100

No files matched your search

+174 -4
View File
@@ -74,6 +74,56 @@ const DEFAULTS = {
fudai_quiet_hours_enabled: true,
fudai_quiet_start_hour: 2,
fudai_quiet_end_hour: 7,
// 桌面 GUI 对齐补充
infinite_loop_enabled: false,
skip_if_countdown_gt_seconds: 900,
reset_after_swipes_action: "swipe",
enable_back_on_misses: true,
enable_streaming_screenshot: true,
swipe_duration_ms: 600,
swipe_up_start_y: 1200,
swipe_up_end_y: 600,
switch_room_wait_after_stage_diag_seconds: 7.0,
fansclub_click_delay: 0.6,
fansclub_auto_join_wait_seconds: 5.0,
fansclub_manual_wait_seconds: 3.0,
high_value_fudai_poll_before_seconds: 10.0,
high_value_room_revisit_min_interval_seconds: 300,
high_value_room_revisit_max_per_run: 5,
high_value_room_revisit_min_prize_value: 0,
high_value_room_revisit_max_age_days: 30,
reservation_back_verify_wait_seconds: 5.0,
fudai_disable_task_recognition: false,
fudai_exit_after_misses: 30,
fudai_click_wait_seconds: 2.0,
fudai_detail_template_threshold: 0.7,
coupon_template_match_threshold: 0.75,
attend_button_red_ratio_threshold: 0.25,
fansclub_join_red_ratio_threshold: 0.25,
shopping_redpacket_red_ratio_threshold: 0.15,
yanghao_only: false,
yanghao_icon_match_threshold: 0.72,
"debug_captures.async_save": true,
"debug_captures.log_on_complete": false,
"logging.beautify_output": true,
"logging.color_output": true,
"logging.show_timestamps": true,
"logging.enable_monitor": true,
"logging.compress_logs": true,
"logging.keep_days": 30,
"logging.max_total_size_gb": 10.0,
"logging.compress_after_days": 7,
"logging.debug_detail_level": "normal",
"logging.error_detail_level": "full",
"logging.action_log_format": "concise",
"logging.log_format_mode": "simple",
"logging.monitor_warning_mb": 500,
"logging.monitor_critical_mb": 2000,
"logging.stage_diag_verbose": true,
"logging.performance_tracking.enabled": true,
"logging.performance_tracking.track_function_calls": true,
"gui.theme": "litera",
};
function $(id) { return document.getElementById(id); }
@@ -565,6 +615,40 @@ function getConfigBoundElements() {
return Array.from(document.querySelectorAll("[data-key]"));
}
function syncMirrorFields() {
const mirrors = Array.from(document.querySelectorAll("[data-mirror-key]"));
for (const mirror of mirrors) {
const key = mirror.dataset.mirrorKey;
const source = document.querySelector(`[data-key="${CSS.escape(key)}"]`);
if (!source) continue;
const copy = () => {
if (mirror.type === "checkbox") mirror.checked = !!source.checked;
else mirror.value = source.value;
};
copy();
source.addEventListener("input", copy);
source.addEventListener("change", copy);
mirror.addEventListener("input", () => {
if (source.type === "checkbox") source.checked = !!mirror.checked;
else source.value = mirror.value;
source.dispatchEvent(new Event("input", { bubbles: true }));
source.dispatchEvent(new Event("change", { bubbles: true }));
});
}
}
function getConfigValue(cfg, key) {
if (!cfg || !key) return undefined;
if (Object.prototype.hasOwnProperty.call(cfg, key)) return cfg[key];
if (!String(key).includes(".")) return undefined;
let cur = cfg;
for (const part of String(key).split(".")) {
if (!cur || typeof cur !== "object" || !Object.prototype.hasOwnProperty.call(cur, part)) return undefined;
cur = cur[part];
}
return cur;
}
function coerceValue(type, raw, isCheckbox) {
if (type === "bool") return !!raw;
if (type === "int") {
@@ -587,7 +671,7 @@ function applyConfigToUI(cfg) {
for (const el of getConfigBoundElements()) {
const key = el.dataset.key;
const type = el.dataset.type || "str";
const val = cfg ? cfg[key] : undefined;
const val = getConfigValue(cfg, key);
// undefined/null 都视为“未配置”:保留页面默认值
const hasVal = !(typeof val === "undefined" || val === null);
@@ -638,13 +722,72 @@ async function saveConfig() {
appendLog(["[WEB] 配置已保存到 config.json"]);
}
function selectedDeviceId() {
const el = $("device");
return el ? (el.value || "") : "";
}
async function postDeviceAction(path, body, successPrefix) {
try {
const result = await apiPost(path, body || {});
const msg = result.message || result.output || result.error || "完成";
appendLog([`${successPrefix}: ${msg}`]);
if (result.devices) await refreshDevices();
return result;
} catch (e) {
appendLog([`${successPrefix}失败: ${e?.message || e}`]);
throw e;
}
}
async function forceStopRun() {
await postDeviceAction("/api/force-stop", {}, "[WEB] 强制停止");
}
async function sendBackKey() {
const deviceId = selectedDeviceId();
await postDeviceAction("/api/back-key", { device_id: deviceId }, "[WEB] 返回键");
}
async function wifiEnable() {
const deviceId = selectedDeviceId();
if (!deviceId) {
appendLog(["[WiFi ADB] 请先选择 USB 设备"]);
return;
}
const result = await postDeviceAction("/api/wifi/enable", { device_id: deviceId }, "[WiFi ADB] 启用");
setTextIfExists("wifiStatus", result.message || "已发送启用命令");
}
async function wifiConnect() {
const ip = ($("wifi_ip")?.value || "").trim();
const port = ($("wifi_port")?.value || "5555").trim() || "5555";
if (!ip) {
appendLog(["[WiFi ADB] 请填写设备 IP"]);
return;
}
const result = await postDeviceAction("/api/wifi/connect", { ip, port }, "[WiFi ADB] 连接");
setTextIfExists("wifiStatus", result.message || "连接命令已执行");
}
async function wifiDisconnect() {
const ip = ($("wifi_ip")?.value || selectedDeviceId() || "").trim();
const port = ($("wifi_port")?.value || "5555").trim() || "5555";
if (!ip) {
appendLog(["[WiFi ADB] 请填写 IP 或选择 WiFi 设备"]);
return;
}
const result = await postDeviceAction("/api/wifi/disconnect", { ip, port }, "[WiFi ADB] 断开");
setTextIfExists("wifiStatus", result.message || "断开命令已执行");
}
async function startRun() {
try {
const deviceId = $("device").value || "";
const yPianyi = parseInt($("y_pianyi").value || "0", 10);
const waitMinutes = parseInt($("wait_minutes").value || "5", 10);
const needswitch = $("needswitch").checked;
const cfgPart = collectConfigFromUI();
const waitMinutes = cfgPart.infinite_loop_enabled ? 0 : parseInt($("wait_minutes").value || "5", 10);
const needswitch = $("needswitch").checked;
appendLog([`[WEB] 正在启动...`]);
@@ -661,11 +804,26 @@ async function startRun() {
reset_after_swipes: cfgPart.reset_after_swipes,
auto_join_fansclub: cfgPart.auto_join_fansclub,
fansclub_fail_action: cfgPart.fansclub_fail_action,
skip_if_countdown_gt_seconds: cfgPart.skip_if_countdown_gt_seconds,
reset_after_swipes_action: cfgPart.reset_after_swipes_action,
enable_back_on_misses: cfgPart.enable_back_on_misses,
swipe_down_back_enabled: cfgPart.swipe_down_back_enabled,
swipe_down_back_count: cfgPart.swipe_down_back_count,
high_value_room_revisit_enabled: cfgPart.high_value_room_revisit_enabled,
high_value_room_revisit_only_current_run: cfgPart.high_value_room_revisit_only_current_run,
high_value_room_revisit_min_interval_seconds: cfgPart.high_value_room_revisit_min_interval_seconds,
high_value_room_revisit_max_per_run: cfgPart.high_value_room_revisit_max_per_run,
high_value_room_revisit_min_prize_value: cfgPart.high_value_room_revisit_min_prize_value,
high_value_room_revisit_max_age_days: cfgPart.high_value_room_revisit_max_age_days,
reservation_back_verify_enabled: cfgPart.reservation_back_verify_enabled,
reservation_back_swipe_delay: cfgPart.reservation_back_swipe_delay,
reservation_back_verify_wait_seconds: cfgPart.reservation_back_verify_wait_seconds,
fudai_find_max_attempts: cfgPart.fudai_find_max_attempts,
enable_ocr_mode1: cfgPart.enable_ocr_mode1,
fudai_template_match_enabled: cfgPart.fudai_template_match_enabled,
fudai_template_match_threshold: cfgPart.fudai_template_match_threshold,
yanghao_only: cfgPart.yanghao_only,
yanghao_seconds: cfgPart.yanghao_recommend_duration_seconds,
});
// 检查返回结果
@@ -1168,6 +1326,16 @@ window.addEventListener("DOMContentLoaded", async () => {
$("btnSave").addEventListener("click", async () => { await saveConfig(); });
$("btnStart").addEventListener("click", async () => { await startRun(); });
$("btnStop").addEventListener("click", async () => { await stopRun(); });
const btnForceStop = $("btnForceStop");
if (btnForceStop) btnForceStop.addEventListener("click", async () => { await forceStopRun(); });
const btnBackKey = $("btnBackKey");
if (btnBackKey) btnBackKey.addEventListener("click", async () => { await sendBackKey(); });
const btnWifiEnable = $("btnWifiEnable");
if (btnWifiEnable) btnWifiEnable.addEventListener("click", async () => { await wifiEnable(); });
const btnWifiConnect = $("btnWifiConnect");
if (btnWifiConnect) btnWifiConnect.addEventListener("click", async () => { await wifiConnect(); });
const btnWifiDisconnect = $("btnWifiDisconnect");
if (btnWifiDisconnect) btnWifiDisconnect.addEventListener("click", async () => { await wifiDisconnect(); });
// 截图按钮
$("btnScreenshot").addEventListener("click", async () => {
@@ -1231,6 +1399,8 @@ window.addEventListener("DOMContentLoaded", async () => {
if (runSearchBtn) runSearchBtn.addEventListener('click', async () => { await doRunLogSearch(); });
if (runClear) runClear.addEventListener('click', () => { runLogBuffer = []; runSearchResultsBuffer = []; runSearchActive = false; runLogFilter = ''; if (runSearchEl) runSearchEl.value=''; renderRunLog(); });
syncMirrorFields();
const actionsSearchEl = $("actionsLogSearch");
if (actionsSearchEl) {
actionsSearchEl.addEventListener('input', (e) => { actionsLogFilter = String(e.target.value || ''); renderActionsLog(); });
@@ -1252,4 +1422,4 @@ window.addEventListener("DOMContentLoaded", async () => {
pollShot();
pollReservations();
pollHighValueRooms();
});
});