Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
102 lines
3.0 KiB
JavaScript
102 lines
3.0 KiB
JavaScript
const { chromium } = require('playwright');
|
|
|
|
(async () => {
|
|
let browser;
|
|
|
|
try {
|
|
console.log('启动浏览器检查所有菜单...');
|
|
browser = await chromium.launch({
|
|
headless: false,
|
|
slowMo: 200
|
|
});
|
|
|
|
const context = await browser.newContext({
|
|
viewport: { width: 1920, height: 1080 }
|
|
});
|
|
|
|
const page = await context.newPage();
|
|
|
|
// 登录
|
|
console.log('\n执行登录...');
|
|
await page.goto('http://localhost:5174/', { waitUntil: 'networkidle' });
|
|
await page.fill('[name="username"]', 'admin');
|
|
await page.fill('[name="password"]', '111111');
|
|
await page.click('button:has-text("登录")');
|
|
await page.waitForTimeout(2000);
|
|
|
|
// 访问首页
|
|
if (page.url().includes('login')) {
|
|
await page.goto('http://localhost:5174/dashboard/home', { waitUntil: 'networkidle' });
|
|
}
|
|
|
|
console.log('\n收集所有菜单项...');
|
|
|
|
// 收集所有菜单
|
|
const allMenus = [];
|
|
|
|
// 获取所有一级菜单
|
|
const mainMenus = await page.locator('.ant-menu-submenu-title, .ant-menu-item').all();
|
|
|
|
for (const menu of mainMenus) {
|
|
const text = await menu.textContent();
|
|
const trimmedText = text.trim();
|
|
|
|
if (trimmedText && !allMenus.some(m => m.name === trimmedText)) {
|
|
const isSubmenu = await menu.locator('..').evaluate(el => el.classList.contains('ant-menu-submenu'));
|
|
|
|
if (isSubmenu) {
|
|
// 展开子菜单
|
|
await menu.click();
|
|
await page.waitForTimeout(300);
|
|
|
|
// 获取子菜单项
|
|
const submenuItems = await page.locator('.ant-menu-submenu-open .ant-menu-item').all();
|
|
for (const subItem of submenuItems) {
|
|
const subText = await subItem.textContent();
|
|
const trimmedSubText = subText.trim();
|
|
if (trimmedSubText) {
|
|
allMenus.push({
|
|
name: trimmedSubText,
|
|
parent: trimmedText,
|
|
type: 'submenu-item'
|
|
});
|
|
}
|
|
}
|
|
|
|
// 收起子菜单
|
|
await menu.click();
|
|
await page.waitForTimeout(300);
|
|
} else {
|
|
allMenus.push({
|
|
name: trimmedText,
|
|
parent: null,
|
|
type: 'menu-item'
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`\n找到 ${allMenus.length} 个菜单项:\n`);
|
|
allMenus.forEach((menu, index) => {
|
|
if (menu.parent) {
|
|
console.log(`${index + 1}. ${menu.parent} > ${menu.name}`);
|
|
} else {
|
|
console.log(`${index + 1}. ${menu.name}`);
|
|
}
|
|
});
|
|
|
|
// 保存菜单列表
|
|
const fs = require('fs');
|
|
fs.writeFileSync('all-menus.json', JSON.stringify(allMenus, null, 2));
|
|
console.log('\n菜单列表已保存到 all-menus.json');
|
|
|
|
await page.waitForTimeout(5000);
|
|
|
|
} catch (error) {
|
|
console.error('出错了:', error);
|
|
} finally {
|
|
if (browser) {
|
|
await browser.close();
|
|
}
|
|
}
|
|
})(); |