From 01ce77eaa656262fac28cd4a915215a957368dbf Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 31 May 2026 10:47:49 +0800 Subject: [PATCH] refactor(webui): extract frontend constants --- webui/app.js | 198 ------------------------------------------ webui/index.html | 3 +- webui/js/constants.js | 197 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+), 199 deletions(-) create mode 100644 webui/js/constants.js diff --git a/webui/app.js b/webui/app.js index 60226a0..cf3e634 100644 --- a/webui/app.js +++ b/webui/app.js @@ -1,88 +1,3 @@ -const UI_LIMITS = Object.freeze({ - runLogMaxLines: 50000, - runLogMaxChars: 200000, - actionsLogMaxLines: 5000, - scrollBottomThresholdPx: 5, - screenshotPollMs: 1500, - logPollMs: 800, - statsPollMs: 1200, -}); - -const UI_CLASS = Object.freeze({ - busy: "isBusy", - clickable: "isClickable", - collapsed: "isCollapsed", - listCollapsed: "isListCollapsed", - reservationHeader: "reservationHeader", - reservationBody: "reservationBody", - reservationsList: "reservationsList", - shotEmpty: "isShotEmpty", - statusRunning: "statusRunning", - statusIdle: "statusIdle", - statusError: "statusError", -}); - -const RUN_TONE = Object.freeze({ - running: "running", - idle: "idle", - error: "error", -}); - -const UI_COPY = Object.freeze({ - empty: "-", - device: { - autoOption: "(auto)", - autoLabel: "(auto)", - noOnline: "无在线设备", - adbReady: "ADB 已就绪", - adbMissing: "ADB 未找到", - autoOnline: (count) => `${count} 台在线 / 自动选择`, - }, - runOverview: { - starting: "启动中", - startingMeta: "正在向后端发送启动请求", - failed: "启动失败", - stopping: "停止中", - stoppingMeta: "已请求后端停止运行", - meta: (pid, uptimeSeconds) => `PID ${pid ?? "-"} / 运行时长 ${fmtDuration(uptimeSeconds)}`, - }, - overview: { - logLines: (count) => `${count ?? 0} 行`, - lastLog: (ts) => `最后日志 ${fmtTime(ts)}`, - fudaiState: (opened, attended) => `${opened} / ${attended}`, - fudaiMeta: (seen, wins) => `识别 ${seen} / 中奖 ${wins}`, - }, -}); - -const TIMELINE_SERIES_KEYS = Object.freeze([ - "fudai_open_detail", - "fudai_attend_ok", - "fudai_attend_fail", - "fudai_result_win", - "fudai_result_no_win", - "fudai_skip", - "switch_room", -]); - -const TIMELINE_LAYOUT = Object.freeze({ - width: 900, - height: 220, - paddingLeft: 36, - paddingRight: 14, - paddingTop: 10, - paddingBottom: 26, -}); - -const TIMELINE_STROKES = Object.freeze({ - fudai_open_detail: { stroke: "var(--primary)", opacity: 1.0, dash: "" }, - fudai_attend_ok: { stroke: "var(--primary)", opacity: 0.7, dash: "" }, - fudai_attend_fail: { stroke: "var(--primary)", opacity: 0.4, dash: "4 3" }, - fudai_result_win: { stroke: "var(--primary)", opacity: 1.0, dash: "2 3" }, - fudai_result_no_win:{ stroke: "var(--primary)", opacity: 0.4, dash: "" }, - fudai_skip: { stroke: "var(--muted)", opacity: 0.7, dash: "4 3" }, - switch_room: { stroke: "var(--muted)", opacity: 1.0, dash: "2 3" }, -}); - const BUSY_DISABLED_BUTTONS = new Set(["btnStart", "btnSave"]); let logIdx = 0; @@ -106,119 +21,6 @@ let actionsLogFilter = ""; const actionsLogMaxLines = UI_LIMITS.actionsLogMaxLines; let deviceOverviewState = { devices: [], adb: "" }; -const DEFAULTS = { - // 筛选 - min_prize_value_yuan: 0, - min_participants: 0, - max_participants: 0, - skip_if_countdown_lt_seconds: 15, - reset_after_swipes_enabled: false, - reset_after_swipes: 10, - auto_join_fansclub: false, - fansclub_fail_action: "stay", - - // 养号 - yanghao_enabled: true, - yanghao_enable_actions: true, - yanghao_step_screenshot: false, - yanghao_recommend_duration_seconds: 60, - yanghao_recommend_interval_seconds: 0, - yanghao_like_prob: 0.15, - yanghao_fav_prob: 0.05, - yanghao_comment_prob: 0, - yanghao_icon_roi_size: 180, - yanghao_icon_match_threshold: 0.72, - yanghao_like_template_path: "assets/like.png", - yanghao_fav_template_path: "assets/fav.png", - yanghao_like_icon_x: 0, - yanghao_like_icon_y: 0, - yanghao_fav_icon_x: 0, - yanghao_fav_icon_y: 0, - yanghao_comment_btn_x: 0, - yanghao_comment_btn_y: 0, - yanghao_after_dwell_swipe_direction: "up", - yanghao_after_dwell_swipe_distance_px: 900, - - // 高价值福袋预约 - high_value_fudai_enabled: false, - high_value_fudai_threshold_yuan: 1000, - high_value_fudai_join_ahead_seconds: 300, - high_value_fudai_max_swipe_back: 60, - high_value_fudai_max_reservations: 5, - high_value_fudai_after_action: "continue", - 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, - // 是否禁用福袋内容OCR识别(仅前端默认,实际值以 config.json 为准) - fudai_disable_content_recognition: false, - live_room_match_threshold: 0.8, - reservation_back_swipe_delay: 0.6, - - // 定时禁抢福袋(默认 2-7 点) - 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.use_dated_logs": 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", - "gui.realtime_status.refresh_interval_ms": 1000, - "gui.realtime_status.tail_items": 50, - log_unified_enabled: true, - log_unified_path: "logs/unified.log", -}; - function $(id) { return document.getElementById(id); } function initTheme() { diff --git a/webui/index.html b/webui/index.html index c49b159..8afdff3 100644 --- a/webui/index.html +++ b/webui/index.html @@ -1278,6 +1278,7 @@ - + + diff --git a/webui/js/constants.js b/webui/js/constants.js new file mode 100644 index 0000000..95b834d --- /dev/null +++ b/webui/js/constants.js @@ -0,0 +1,197 @@ +const UI_LIMITS = Object.freeze({ + runLogMaxLines: 50000, + runLogMaxChars: 200000, + actionsLogMaxLines: 5000, + scrollBottomThresholdPx: 5, + screenshotPollMs: 1500, + logPollMs: 800, + statsPollMs: 1200, +}); + +const UI_CLASS = Object.freeze({ + busy: "isBusy", + clickable: "isClickable", + collapsed: "isCollapsed", + listCollapsed: "isListCollapsed", + reservationHeader: "reservationHeader", + reservationBody: "reservationBody", + reservationsList: "reservationsList", + shotEmpty: "isShotEmpty", + statusRunning: "statusRunning", + statusIdle: "statusIdle", + statusError: "statusError", +}); + +const RUN_TONE = Object.freeze({ + running: "running", + idle: "idle", + error: "error", +}); + +const UI_COPY = Object.freeze({ + empty: "-", + device: { + autoOption: "(auto)", + autoLabel: "(auto)", + noOnline: "无在线设备", + adbReady: "ADB 已就绪", + adbMissing: "ADB 未找到", + autoOnline: (count) => `${count} 台在线 / 自动选择`, + }, + runOverview: { + starting: "启动中", + startingMeta: "正在向后端发送启动请求", + failed: "启动失败", + stopping: "停止中", + stoppingMeta: "已请求后端停止运行", + meta: (pid, uptimeSeconds) => `PID ${pid ?? "-"} / 运行时长 ${fmtDuration(uptimeSeconds)}`, + }, + overview: { + logLines: (count) => `${count ?? 0} 行`, + lastLog: (ts) => `最后日志 ${fmtTime(ts)}`, + fudaiState: (opened, attended) => `${opened} / ${attended}`, + fudaiMeta: (seen, wins) => `识别 ${seen} / 中奖 ${wins}`, + }, +}); + +const TIMELINE_SERIES_KEYS = Object.freeze([ + "fudai_open_detail", + "fudai_attend_ok", + "fudai_attend_fail", + "fudai_result_win", + "fudai_result_no_win", + "fudai_skip", + "switch_room", +]); + +const TIMELINE_LAYOUT = Object.freeze({ + width: 900, + height: 220, + paddingLeft: 36, + paddingRight: 14, + paddingTop: 10, + paddingBottom: 26, +}); + +const TIMELINE_STROKES = Object.freeze({ + fudai_open_detail: { stroke: "var(--primary)", opacity: 1.0, dash: "" }, + fudai_attend_ok: { stroke: "var(--primary)", opacity: 0.7, dash: "" }, + fudai_attend_fail: { stroke: "var(--primary)", opacity: 0.4, dash: "4 3" }, + fudai_result_win: { stroke: "var(--primary)", opacity: 1.0, dash: "2 3" }, + fudai_result_no_win:{ stroke: "var(--primary)", opacity: 0.4, dash: "" }, + fudai_skip: { stroke: "var(--muted)", opacity: 0.7, dash: "4 3" }, + switch_room: { stroke: "var(--muted)", opacity: 1.0, dash: "2 3" }, +}); + +const DEFAULTS = { + // 筛选 + min_prize_value_yuan: 0, + min_participants: 0, + max_participants: 0, + skip_if_countdown_lt_seconds: 15, + reset_after_swipes_enabled: false, + reset_after_swipes: 10, + auto_join_fansclub: false, + fansclub_fail_action: "stay", + + // 养号 + yanghao_enabled: true, + yanghao_enable_actions: true, + yanghao_step_screenshot: false, + yanghao_recommend_duration_seconds: 60, + yanghao_recommend_interval_seconds: 0, + yanghao_like_prob: 0.15, + yanghao_fav_prob: 0.05, + yanghao_comment_prob: 0, + yanghao_icon_roi_size: 180, + yanghao_icon_match_threshold: 0.72, + yanghao_like_template_path: "assets/like.png", + yanghao_fav_template_path: "assets/fav.png", + yanghao_like_icon_x: 0, + yanghao_like_icon_y: 0, + yanghao_fav_icon_x: 0, + yanghao_fav_icon_y: 0, + yanghao_comment_btn_x: 0, + yanghao_comment_btn_y: 0, + yanghao_after_dwell_swipe_direction: "up", + yanghao_after_dwell_swipe_distance_px: 900, + + // 高价值福袋预约 + high_value_fudai_enabled: false, + high_value_fudai_threshold_yuan: 1000, + high_value_fudai_join_ahead_seconds: 300, + high_value_fudai_max_swipe_back: 60, + high_value_fudai_max_reservations: 5, + high_value_fudai_after_action: "continue", + 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, + // 是否禁用福袋内容OCR识别(仅前端默认,实际值以 config.json 为准) + fudai_disable_content_recognition: false, + live_room_match_threshold: 0.8, + reservation_back_swipe_delay: 0.6, + + // 定时禁抢福袋(默认 2-7 点) + 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.use_dated_logs": 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", + "gui.realtime_status.refresh_interval_ms": 1000, + "gui.realtime_status.tail_items": 50, + log_unified_enabled: true, + log_unified_path: "logs/unified.log", +};