#!/usr/bin/env python3
"""
检查各个页面的实际内容
"""

from playwright.sync_api import sync_playwright
import time

pages_to_check = [
    ('Dashboard', 'http://localhost:3002/dashboard'),
    ('用户管理', 'http://localhost:3002/users'),
    ('角色管理', 'http://localhost:3002/roles'),
    ('菜单管理', 'http://localhost:3002/menus'),
    ('字典管理', 'http://localhost:3002/dict'),
    ('系统配置', 'http://localhost:3002/sys/config'),
    ('文件管理', 'http://localhost:3002/files'),
    ('通知管理', 'http://localhost:3002/notice'),
    ('操作日志', 'http://localhost:3002/oplog'),
    ('登录日志', 'http://localhost:3002/loginlog'),
]

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()
    
    # 登录
    page.goto("http://localhost:3002/login")
    page.wait_for_load_state("networkidle")
    page.fill('input[placeholder="请输入用户名"]', 'admin')
    page.fill('input[placeholder="请输入密码"]', 'admin123')
    page.click('button:has-text("登录")')
    
    # 等待Token
    for i in range(10):
        time.sleep(1)
        token = page.evaluate("localStorage.getItem('token')")
        if token:
            break
    
    print(f"登录成功: {token[:50] if token else 'None'}...\n")
    
    # 检查每个页面
    for name, url in pages_to_check:
        print(f"检查 {name} ({url})...")
        try:
            page.goto(url)
            page.wait_for_load_state("networkidle")
            time.sleep(2)
            
            # 检查页面内容
            table_count = page.locator('table').count()
            el_table_count = page.locator('.el-table').count()
            body_text = page.locator('body').text_content()[:200]
            
            print(f"  URL: {page.url}")
            print(f"  table标签: {table_count}, .el-table: {el_table_count}")
            print(f"  内容: {body_text[:100]}...")
            
            # 截图
            page.screenshot(path=f"/tmp/{name.replace('/', '_')}.png")
            
        except Exception as e:
            print(f"  ❌ 错误: {e}")
        
        print()
    
    browser.close()
