Files
web-Iot/.workbuddy/capture.js
2026-08-12 09:25:21 +08:00

74 lines
3.4 KiB
JavaScript

const { chromium } = require('playwright');
const fs = require('fs');
const BASE = 'http://localhost:3002';
const TOKEN = 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjQ0NzViNWY4LWQwOTUtNGJjMS05MjhhLTljYmIyMTA3M2I1MCJ9.YMOH00KNb9BaJsLeGU9sLa5L0Z3rKBvqiYPAft7kVexG6dN8Bdesb0FHtfOwUT0F3W3bfFoAzQOWxv6FtoHCKg';
const OUT = 'D:/code/机器人智慧服务系统/.workbuddy/screenshots';
const shots = [
{ route: '/', file: '01_home.png', name: '总览首页' },
{ route: '/devices/overview', file: '02_device_overview.png', name: '设备总览' },
{ route: '/devices/status', file: '03_device_status.png', name: '设备状态' },
{ route: '/devices/wayLineTask', file: '04_wayline.png', name: '航线任务' },
{ route: '/devices/robotTask', file: '05_robot_task.png', name: '机器人任务' },
{ route: '/video', file: '06_video.png', name: '在线视频' },
{ route: '/RealtimeMonitor', file: '07_realtime.png', name: '实时监控(Cesium)' },
{ route: '/monitor', file: '08_monitor.png', name: '视频监控' },
{ route: '/alerts/all', file: '09_alerts.png', name: '告警中心' },
{ route: '/AIanalysis', file: '10_ai.png', name: 'AI诊断分析' },
{ route: '/clean', file: '11_clean.png', name: '清洗优化' },
{ route: '/task', file: '12_workorder.png', name: '工单任务' },
{ route: '/table', file: '13_report.png', name: '报表中心' },
{ route: '/systemSetting', file: '14_system.png', name: '系统设置' },
{ route: '/manage/users', file: '15_users.png', name: '用户管理' },
{ route: '/manage/roles', file: '16_roles.png', name: '角色管理' },
{ route: '/profile', file: '17_profile.png', name: '个人中心' },
];
(async () => {
fs.mkdirSync(OUT, { recursive: true });
const browser = await chromium.launch({
headless: true,
channel: 'msedge',
args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist']
});
const context = await browser.newContext({ viewport: { width: 1536, height: 864 }, deviceScaleFactor: 1 });
const page = await context.newPage();
// ---- 1) 登录页(未登录态,先截图) ----
await page.goto(BASE + '/login', { waitUntil: 'networkidle', timeout: 30000 }).catch(() => {});
await page.waitForTimeout(2500);
await page.screenshot({ path: OUT + '/00_login.png', fullPage: false });
console.log('captured 00_login.png');
// ---- 注入登录态 ----
await page.evaluate((token) => {
const userInfo = {
userId: '1', userName: 'admin', nickName: '迈步管理员',
roleKey: 'admin', roleId: 23, username: 'admin',
avatar: '/profile/avatar/2026/05/18/20211231082559_932c3_20260518163437A001.jpg',
token: token
};
localStorage.setItem('token', token);
localStorage.setItem('userInfo', JSON.stringify(userInfo));
document.cookie = 'Admin-Token=' + token + '; path=/';
document.cookie = 'userId=1; path=/';
}, TOKEN);
// ---- 逐个模块截图 ----
for (const s of shots) {
try {
await page.goto(BASE + s.route, { waitUntil: 'networkidle', timeout: 25000 }).catch(() => {});
await page.waitForTimeout(3500);
// 尝试关掉可能遮挡的弹窗/loading
await page.screenshot({ path: OUT + '/' + s.file, fullPage: false }).catch((e) => console.log('shot fail', s.file, e.message));
console.log('captured', s.file, '->', s.name);
} catch (e) {
console.log('ERROR', s.route, e.message);
}
}
await browser.close();
console.log('DONE');
})();