fix(app): refine account progress and screenshots

This commit is contained in:
2025-12-14 01:21:31 +08:00
parent 8931ad5d7f
commit 2ec88eac3b
20 changed files with 78 additions and 57 deletions

51
app.py
View File

@@ -3270,18 +3270,47 @@ def take_screenshot_for_account(user_id, account_id, browse_type="应读", sourc
log_to_client(f"导航到 '{browse_type}' 页面...", user_id, account_id)
# 导航到指定页面
result = automation.browse_content(
navigate_only=True,
browse_type=browse_type,
auto_next_page=False,
auto_view_attachments=False,
interval=0,
should_stop_callback=None
)
# 截图场景:优先用 bz 参数直达页面(更稳定,避免页面按钮点击失败导致截图跑偏)
navigated = False
try:
from urllib.parse import urlsplit
parsed = urlsplit(config.ZSGL_LOGIN_URL)
base = f"{parsed.scheme}://{parsed.netloc}"
if '注册前' in str(browse_type):
bz = 0
elif str(browse_type) == '已读':
bz = 1
else:
bz = 2 # 应读/未读
target_url = f"{base}/admin/center.aspx?bz={bz}"
automation.main_page.goto(target_url, timeout=60000)
current_url = getattr(automation.main_page, "url", "") or ""
if "center.aspx" not in current_url:
raise RuntimeError(f"unexpected_url:{current_url}")
try:
automation.main_page.wait_for_load_state('networkidle', timeout=30000)
except Exception:
pass
try:
automation.main_page.wait_for_selector("table.ltable", timeout=20000)
except Exception:
pass
navigated = True
except Exception as nav_error:
log_to_client(f"直达页面失败,将尝试按钮切换: {str(nav_error)[:120]}", user_id, account_id)
if not result.success and result.error_message:
log_to_client(f"导航警告: {result.error_message}", user_id, account_id)
# 兼容兜底:若直达失败,则回退到原有按钮切换方式
if not navigated:
result = automation.browse_content(
navigate_only=True,
browse_type=browse_type,
auto_next_page=False,
auto_view_attachments=False,
interval=0,
should_stop_callback=None
)
if not result.success and result.error_message:
log_to_client(f"导航警告: {result.error_message}", user_id, account_id)
# 等待页面稳定
time.sleep(2)