/** * 菜单功能验证脚本 * 用于验证菜单功能是否正常工作 */ const fs = require('fs'); const path = require('path'); console.log('=== 菜单功能验证 ===\n'); // 验证Layout.js文件 function verifyLayoutJS() { console.log('1. 验证 Layout.js 文件...'); try { const layoutPath = path.join(__dirname, 'src', 'renderer', 'components', 'Layout.js'); const content = fs.readFileSync(layoutPath, 'utf8'); // 检查关键功能点 const hasConsoleLog = content.includes("console.log('菜单点击:', key)"); const hasElectronNavigate = content.includes('electronNavigate(key, navigate)'); const hasWindowLocationHash = content.includes('window.location.hash = key'); const hasWindowReload = content.includes('window.location.reload()'); console.log(` 日志输出: ${hasConsoleLog ? '✅' : '❌'}`); console.log(` Electron导航: ${hasElectronNavigate ? '✅' : '❌'}`); console.log(` Hash导航: ${hasWindowLocationHash ? '✅' : '❌'}`); console.log(` 页面刷新: ${hasWindowReload ? '✅' : '❌'}`); if (hasConsoleLog && hasElectronNavigate && hasWindowLocationHash && hasWindowReload) { console.log(' 结论: Layout.js 菜单处理函数已正确修复\n'); return true; } else { console.log(' 结论: Layout.js 菜单处理函数存在问题\n'); return false; } } catch (error) { console.error(' 错误:', error.message); console.log(' 结论: 无法验证 Layout.js 文件\n'); return false; } } // 验证启动脚本 function verifyStartupScript() { console.log('2. 验证 启动脚本...'); try { const batPath = path.join(__dirname, '启动收银台.bat'); const content = fs.readFileSync(batPath, 'utf8'); // 检查关键环境变量 const hasLogging = content.includes('ELECTRON_ENABLE_LOGGING=1'); const hasMenuBar = content.includes('ELECTRON_FORCE_WINDOW_MENU_BAR=1'); const hasNodeEnv = content.includes('NODE_ENV=production'); const hasAutoBuild = content.includes('if not exist "build\\index.html"'); console.log(` 日志设置: ${hasLogging ? '✅' : '❌'}`); console.log(` 菜单栏设置: ${hasMenuBar ? '✅' : '❌'}`); console.log(` 环境变量: ${hasNodeEnv ? '✅' : '❌'}`); console.log(` 自动构建: ${hasAutoBuild ? '✅' : '❌'}`); if (hasLogging && hasMenuBar && hasNodeEnv && hasAutoBuild) { console.log(' 结论: 启动脚本已正确增强\n'); return true; } else { console.log(' 结论: 启动脚本存在问题\n'); return false; } } catch (error) { console.error(' 错误:', error.message); console.log(' 结论: 无法验证启动脚本\n'); return false; } } // 验证构建文件 function verifyBuildFiles() { console.log('3. 验证 构建文件...'); const indexPath = path.join(__dirname, 'build', 'index.html'); const mainJsPath = path.join(__dirname, 'build', 'js', 'main.js'); const hasIndexHtml = fs.existsSync(indexPath); const hasMainJs = fs.existsSync(mainJsPath); console.log(` index.html: ${hasIndexHtml ? '✅' : '❌'}`); console.log(` main.js: ${hasMainJs ? '✅' : '❌'}`); if (hasIndexHtml && hasMainJs) { console.log(' 结论: 构建文件存在\n'); return true; } else { console.log(' 结论: 构建文件缺失\n'); return false; } } // 主函数 function main() { console.log('开始验证菜单功能修复...\n'); const layoutOk = verifyLayoutJS(); const startupOk = verifyStartupScript(); const buildOk = verifyBuildFiles(); console.log('=== 验证结果 ==='); if (layoutOk && startupOk && buildOk) { console.log('🎉 所有验证通过!菜单功能应该可以正常使用。'); console.log('\n现在您可以:'); console.log('1. 双击 "启动收银台.bat" 启动应用'); console.log('2. 点击左侧菜单项测试功能'); console.log('3. 如仍有问题,请查看 "最终使用说明.md" 获取更多帮助'); } else { console.log('❌ 部分验证失败,请检查上述标记为❌的项目。'); console.log('\n建议操作:'); console.log('1. 运行 "npm run build" 重新构建项目'); console.log('2. 查看 "MENU_FIX_README.md" 获取技术细节'); console.log('3. 查看 "最终使用说明.md" 获取使用指导'); } } main();