#!/usr/bin/env python3 """ 自动截图脚本 - 为三个端的所有页面生成截图 """ import subprocess import time import os from pathlib import Path # 页面配置 PAGES = { 'onsite': { 'base_url': 'http://localhost:8000/emergency-app/onsite', 'pages': [ ('workbench/index.html', 'screenshots/index.jpg'), ('workbench/work-order-detail-ongoing.html', 'screenshots/work-order-detail-ongoing.jpg'), ('workbench/work-order-detail.html', 'screenshots/work-order-detail.jpg'), ('workbench/serious-illness-list.html', 'screenshots/serious-illness-list.jpg'), ('workbench/serious-illness-detail-pending.html', 'screenshots/serious-illness-detail-pending.jpg'), ('workbench/serious-illness-detail-done.html', 'screenshots/serious-illness-detail-done.jpg'), ('knowledge/index.html', 'screenshots/knowledge-index.jpg'), ('knowledge/article-detail.html', 'screenshots/knowledge-article-detail.jpg'), ('profile/index.html', 'screenshots/profile-index.jpg'), ('profile/edit-profile.html', 'screenshots/edit-profile.jpg'), ('profile/change-pwd.html', 'screenshots/change-pwd.jpg'), ] }, 'operator': { 'base_url': 'http://localhost:8000/emergency-app/operator', 'pages': [ ('workbench/index.html', 'screenshots/index.jpg'), ('workbench/emergency-chat-ongoing.html', 'screenshots/emergency-chat-ongoing.jpg'), ('workbench/emergency-chat-done.html', 'screenshots/emergency-chat-done.jpg'), ('workbench/work-order-detail.html', 'screenshots/work-order-detail.jpg'), ('workbench/serious-illness-detail-pending.html', 'screenshots/serious-illness-detail-pending.jpg'), ('knowledge/index.html', 'screenshots/knowledge-index.jpg'), ('knowledge/article-detail.html', 'screenshots/knowledge-article-detail.jpg'), ('profile/index.html', 'screenshots/profile-index.jpg'), ('profile/edit-profile.html', 'screenshots/edit-profile.jpg'), ('profile/change-pwd.html', 'screenshots/change-pwd.jpg'), ] }, 'professional': { 'base_url': 'http://localhost:8000/emergency-app/professional', 'pages': [ ('workbench/index.html', 'screenshots/index.jpg'), ('workbench/emergency-chat-ongoing.html', 'screenshots/emergency-chat-ongoing.jpg'), ('workbench/emergency-chat-done.html', 'screenshots/emergency-chat-done.jpg'), ('workbench/work-order-detail-ongoing.html', 'screenshots/work-order-detail-ongoing.jpg'), ('workbench/work-order-detail.html', 'screenshots/work-order-detail.jpg'), ('knowledge/index.html', 'screenshots/knowledge-index.jpg'), ('knowledge/article-detail.html', 'screenshots/knowledge-article-detail.jpg'), ('profile/index.html', 'screenshots/profile-index.jpg'), ('profile/edit-profile.html', 'screenshots/edit-profile.jpg'), ('profile/change-pwd.html', 'screenshots/change-pwd.jpg'), ] } } def take_screenshot(url, output_path): """使用Puppeteer截图""" try: # 使用npx puppeteer-cli截图 cmd = [ 'npx', 'puppeteer', 'screenshot', '--url', url, '--path', output_path, '--width', '375', '--height', '812', '--device-scale-factor', '2' ] result = subprocess.run(cmd, capture_output=True, timeout=30) if result.returncode == 0: print(f"✓ {output_path}") return True else: print(f"✗ {output_path}: {result.stderr.decode()}") return False except Exception as e: print(f"✗ {output_path}: {e}") return False def main(): base_dir = Path('D:/AI/work/platform-prototype/emergency-app') for role, config in PAGES.items(): print(f"\n[{role}] Starting screenshots...") role_dir = base_dir / role / 'doc' for page_path, screenshot_rel in config['pages']: url = f"{config['base_url']}/{page_path}" output_path = str(role_dir / screenshot_rel) # 确保目录存在 Path(output_path).parent.mkdir(parents=True, exist_ok=True) take_screenshot(url, output_path) time.sleep(1) # 避免请求过快 if __name__ == '__main__': main()