"""截图莱塔萝仪表盘"""
import asyncio
from playwright.async_api import async_playwright
import os, sys
sys.stdout.reconfigure(encoding='utf-8', errors='replace')

BASE = os.path.dirname(os.path.abspath(__file__))
HTML = os.path.join(BASE, '莱塔萝门店数据看板.html')

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page(viewport={'width': 1400, 'height': 950})

        await page.goto('file:///' + HTML.replace('\\', '/'), wait_until='networkidle')
        await asyncio.sleep(2.5)

        await page.screenshot(path=os.path.join(BASE, 'screenshot_v2.png'), full_page=True)
        print('OK: screenshot_v2.png')

        await page.click('.mode-btn[data-mode="custom"]')
        await asyncio.sleep(0.3)
        await page.click('text=查看')
        await asyncio.sleep(1.5)
        await page.screenshot(path=os.path.join(BASE, 'screenshot_v2_custom.png'), full_page=True)
        print('OK: screenshot_v2_custom.png')

        await browser.close()

asyncio.run(main())
