81 lines
2.7 KiB
JavaScript
81 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* 管理后台登录+截图脚本 (Playwright)
|
|
* 用法: node scripts/admin-screenshots.mjs
|
|
*/
|
|
import { chromium } from 'playwright'
|
|
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
const OUT = path.join(__dirname, '../玩值开发文档/4、前端')
|
|
const BASE = 'https://wzdj.quwanzhi.com'
|
|
|
|
const adminPages = [
|
|
['/admin', '管理-登录页'],
|
|
['/admin', '管理-数据概览'], // 登录后同路径
|
|
]
|
|
|
|
const adminSubPages = [
|
|
['/admin/users', '管理-用户管理'],
|
|
['/admin/streamers', '管理-主播管理'],
|
|
['/admin/guilds', '管理-公会管理'],
|
|
['/admin/stars', '管理-明星管理'],
|
|
['/admin/live', '管理-直播管理'],
|
|
['/admin/party', '管理-派对管理'],
|
|
['/admin/mall', '管理-商城管理'],
|
|
['/admin/orders', '管理-订单管理'],
|
|
['/admin/pawn', '管理-典当管理'],
|
|
['/admin/hotel', '管理-酒店管理'],
|
|
['/admin/content', '管理-内容管理'],
|
|
['/admin/finance', '管理-财务管理'],
|
|
['/admin/settings', '管理-系统设置'],
|
|
]
|
|
|
|
async function main() {
|
|
const browser = await chromium.launch({ headless: true })
|
|
const context = await browser.newContext({
|
|
viewport: { width: 1920, height: 1080 },
|
|
ignoreHTTPSErrors: true,
|
|
})
|
|
const page = await context.newPage()
|
|
|
|
try {
|
|
// 1. 截图登录页
|
|
await page.goto(`${BASE}/admin`, { waitUntil: 'networkidle', timeout: 15000 })
|
|
await page.waitForTimeout(2000)
|
|
await page.screenshot({ path: path.join(OUT, '管理-登录页.png') })
|
|
console.log('✅ 管理-登录页.png')
|
|
|
|
// 2. 填写并登录
|
|
await page.fill('input[placeholder="请输入用户名"]', 'admin')
|
|
await page.fill('input[placeholder="请输入密码"]', 'admin123')
|
|
await page.click('button:has-text("登录后台")')
|
|
await page.waitForTimeout(3000)
|
|
|
|
// 3. 截图数据概览(登录后 /admin 显示仪表盘)
|
|
await page.screenshot({ path: path.join(OUT, '管理-数据概览.png') })
|
|
console.log('✅ 管理-数据概览.png')
|
|
|
|
// 4. 逐个访问子页面并截图
|
|
for (const [urlPath, name] of adminSubPages) {
|
|
await page.goto(`${BASE}${urlPath}`, { waitUntil: 'networkidle', timeout: 15000 })
|
|
await page.waitForTimeout(2000)
|
|
// 若被重定向回登录页,则登录态失效,跳过
|
|
const currentUrl = page.url()
|
|
if (currentUrl.includes('/admin') && !currentUrl.includes('login')) {
|
|
await page.screenshot({ path: path.join(OUT, `${name}.png`) })
|
|
console.log(`✅ ${name}.png`)
|
|
} else {
|
|
console.log(`⚠️ 跳过 ${name} (可能需登录)`)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('Error:', e.message)
|
|
} finally {
|
|
await browser.close()
|
|
}
|
|
}
|
|
|
|
main()
|