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>
179 lines
6.2 KiB
JavaScript
179 lines
6.2 KiB
JavaScript
const { chromium } = require('playwright');
|
||
|
||
(async () => {
|
||
let browser;
|
||
|
||
try {
|
||
console.log('启动浏览器修复菜单显示问题...');
|
||
browser = await chromium.launch({
|
||
headless: false,
|
||
slowMo: 100
|
||
});
|
||
|
||
const context = await browser.newContext({
|
||
viewport: { width: 1920, height: 1080 }
|
||
});
|
||
|
||
const page = await context.newPage();
|
||
|
||
// 登录
|
||
console.log('\n1. 执行登录...');
|
||
await page.goto('http://localhost:5173/', { 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('dashboard')) {
|
||
await page.goto('http://localhost:5173/dashboard/home', { waitUntil: 'networkidle' });
|
||
}
|
||
|
||
console.log('\n2. 打开浏览器控制台执行修复...');
|
||
|
||
// 在浏览器控制台中执行修复代码
|
||
const fixResult = await page.evaluate(() => {
|
||
console.log('开始修复菜单...');
|
||
|
||
// 定义菜单数据
|
||
const menuData = [
|
||
{
|
||
name: 'Dashboard',
|
||
path: '/dashboard',
|
||
meta: { title: '仪表板', icon: 'lucide:home', order: 1 },
|
||
children: [
|
||
{ name: 'DashboardHome', path: '/dashboard/home', meta: { title: '首页' } }
|
||
]
|
||
},
|
||
{
|
||
name: 'AccountManage',
|
||
path: '/account-manage',
|
||
meta: { title: '账号管理', icon: 'lucide:smartphone', order: 2 },
|
||
children: [
|
||
{ name: 'AccountList', path: '/account-manage/list', meta: { title: 'TG账号列表' } },
|
||
{ name: 'AccountUsage', path: '/account-manage/usage', meta: { title: 'TG账号用途' } },
|
||
{ name: 'TelegramUsers', path: '/account-manage/telegram-users', meta: { title: 'Telegram用户列表' } },
|
||
{ name: 'UnifiedRegister', path: '/account-manage/unified-register', meta: { title: '统一注册系统' } }
|
||
]
|
||
},
|
||
{
|
||
name: 'GroupConfig',
|
||
path: '/group-config',
|
||
meta: { title: '群组管理', icon: 'lucide:users', order: 3 },
|
||
children: [
|
||
{ name: 'GroupList', path: '/group-config/list', meta: { title: '群组列表' } }
|
||
]
|
||
},
|
||
{
|
||
name: 'MessageManagement',
|
||
path: '/message-management',
|
||
meta: { title: '消息管理', icon: 'lucide:message-square', order: 4 },
|
||
children: [
|
||
{ name: 'MessageList', path: '/message-management/list', meta: { title: '消息列表' } }
|
||
]
|
||
},
|
||
{
|
||
name: 'LogManage',
|
||
path: '/log-manage',
|
||
meta: { title: '日志管理', icon: 'lucide:file-text', order: 5 },
|
||
children: [
|
||
{ name: 'GroupSendLog', path: '/log-manage/group-send', meta: { title: '群发日志' } },
|
||
{ name: 'RegisterLog', path: '/log-manage/register', meta: { title: '注册日志' } }
|
||
]
|
||
},
|
||
{
|
||
name: 'SystemConfig',
|
||
path: '/system-config',
|
||
meta: { title: '系统配置', icon: 'lucide:settings', order: 6 },
|
||
children: [
|
||
{ name: 'GeneralConfig', path: '/system-config/general', meta: { title: '通用设置' } },
|
||
{ name: 'SystemParams', path: '/system-config/params', meta: { title: '系统参数' } },
|
||
{ name: 'ProxyPlatform', path: '/system-config/proxy-platform', meta: { title: '代理IP平台' } }
|
||
]
|
||
}
|
||
];
|
||
|
||
// 尝试找到Vue应用实例
|
||
let app = window.__VUE_APP__ || window.app || document.querySelector('#app')?.__vue_app__;
|
||
|
||
if (app) {
|
||
console.log('找到Vue应用实例');
|
||
|
||
// 尝试获取Pinia store
|
||
const stores = app._context.provides.pinia?._s;
|
||
if (stores) {
|
||
console.log('找到Pinia stores');
|
||
|
||
// 查找access store
|
||
let accessStore = null;
|
||
stores.forEach((store, key) => {
|
||
if (store.setAccessMenus && typeof store.setAccessMenus === 'function') {
|
||
accessStore = store;
|
||
console.log('找到access store:', key);
|
||
}
|
||
});
|
||
|
||
if (accessStore) {
|
||
// 设置菜单
|
||
console.log('设置菜单数据...');
|
||
accessStore.setAccessMenus(menuData);
|
||
accessStore.setIsAccessChecked(true);
|
||
|
||
// 触发更新
|
||
if (app._instance?.update) {
|
||
app._instance.update();
|
||
}
|
||
|
||
return { success: true, message: '菜单设置成功' };
|
||
}
|
||
}
|
||
}
|
||
|
||
// 如果上面的方法失败,尝试直接操作localStorage
|
||
console.log('尝试通过localStorage设置菜单...');
|
||
localStorage.setItem('access-menus', JSON.stringify(menuData));
|
||
|
||
return { success: false, message: '需要刷新页面' };
|
||
});
|
||
|
||
console.log('\n修复结果:', fixResult);
|
||
|
||
if (!fixResult.success) {
|
||
console.log('\n3. 刷新页面...');
|
||
await page.reload({ waitUntil: 'networkidle' });
|
||
await page.waitForTimeout(2000);
|
||
}
|
||
|
||
// 检查菜单是否显示
|
||
console.log('\n4. 检查菜单状态...');
|
||
const menuCount = await page.locator('.ant-menu-item, .ant-menu-submenu').count();
|
||
console.log(`菜单项数量: ${menuCount}`);
|
||
|
||
if (menuCount > 0) {
|
||
console.log('\n✅ 菜单修复成功!');
|
||
|
||
// 展开第一个菜单
|
||
const firstSubmenu = await page.locator('.ant-menu-submenu').first();
|
||
if (await firstSubmenu.count() > 0) {
|
||
await firstSubmenu.click();
|
||
await page.waitForTimeout(500);
|
||
console.log('已展开第一个菜单');
|
||
}
|
||
} else {
|
||
console.log('\n❌ 菜单仍然没有显示');
|
||
console.log('可能需要检查路由配置或菜单组件');
|
||
}
|
||
|
||
// 截图
|
||
await page.screenshot({ path: 'test-screenshots/menu-fix-result.png', fullPage: true });
|
||
|
||
console.log('\n保持浏览器打开,您可以查看结果...');
|
||
await new Promise(() => {});
|
||
|
||
} catch (error) {
|
||
console.error('出错了:', error);
|
||
if (browser) {
|
||
await browser.close();
|
||
}
|
||
}
|
||
})(); |