// 批量修复布局脚本 - 用于Node.js环境批量处理 // 使用方法: node batch-fix-layout.js const fs = require('fs'); const path = require('path'); const glob = require('glob'); // 页面模块映射 const PAGE_MODULES = { // 商机管理 'project-initiation.html': 'project', 'project-list.html': 'project', 'project-detail.html': 'project', 'project-approval.html': 'project', 'project-bidding.html': 'project', 'bidding-detail.html': 'project', 'project-contract.html': 'project', 'contract-detail.html': 'project', // 过程管理 'project-start.html': 'process', 'start-detail.html': 'process', 'output-submit.html': 'process', 'output-detail.html': 'process', 'progress-query.html': 'process', // 财务管理 'finance-invoice.html': 'finance', 'invoice-detail.html': 'finance', 'finance-payment.html': 'finance', 'finance-request.html': 'finance', 'request-detail.html': 'finance', // 报表管理 'report-project-detail.html': 'report', 'report-project-summary.html': 'report', 'report-project.html': 'report', 'report-output-detail.html': 'report', 'report-output-summary.html': 'report', 'report-receivable-detail.html': 'report', 'report-receivable-summary.html': 'report', 'report-payable-detail.html': 'report', 'report-payable-summary.html': 'report', // 审批中心 'approval-center.html': 'approval', 'approval-detail.html': 'approval', // 消息中心 'message-center.html': 'message', // 文件中心 'file-center.html': 'file', // 工具中心 'tool-center.html': 'tool', 'tool-fee-calculator.html': 'tool', 'tool-output-calculator.html': 'tool', 'project-board.html': 'tool', // 帮助中心 'help-center.html': 'help', 'help-guide.html': 'help', 'help-faq.html': 'help', 'help-formula.html': 'help', // 全局搜索 'global-search.html': 'search', // 操作日志 'audit-log.html': 'audit', // 系统设置 'settings-org.html': 'settings', 'settings-user.html': 'settings', 'settings-role.html': 'settings', 'settings-workflow.html': 'settings', 'settings-notice.html': 'settings', 'settings-dict.html': 'settings', 'settings-param.html': 'settings', 'settings-log.html': 'settings', }; // 需要特殊处理的页面(不需要侧边栏) const NO_SIDEBAR_PAGES = [ 'dashboard.html', 'login.html', 'forgot-password.html', '404.html', '403.html', '500.html', 'profile.html', 'profile-edit.html', 'change-password.html', 'index.html', ]; function fixPage(filePath) { const fileName = path.basename(filePath); const module = PAGE_MODULES[fileName] || 'home'; const needsSidebar = !NO_SIDEBAR_PAGES.includes(fileName); let content = fs.readFileSync(filePath, 'utf8'); let modified = false; // 1. 添加统一布局样式 if (!content.includes('unified-layout.css')) { content = content.replace( /()/, `$1\n \n ` ); modified = true; } // 2. 替换layout.js为unified-layout.js if (content.includes('layout.js')) { content = content.replace(/'); content = content.replace(/injectLayout\(['"](\w+)['"]\)/g, `initUnifiedLayout('$1')`); modified = true; } // 3. 如果没有unified-layout.js,添加它 if (!content.includes('unified-layout.js') && !content.includes('NO_LAYOUT')) { const beforeBody = content.lastIndexOf(''); if (beforeBody > 0) { const scriptTag = `\n `; content = content.slice(0, beforeBody) + ' ' + scriptTag + '\n' + content.slice(beforeBody); modified = true; } } if (modified) { fs.writeFileSync(filePath, content, 'utf8'); console.log(`✅ 已修复: ${fileName} (模块: ${module})`); return true; } else { console.log(`⏭️ 跳过: ${fileName} (已是最新)`); return false; } } // 主函数 function main() { const files = glob.sync('pc/**/*.html', { cwd: __dirname + '/..' }); let fixed = 0; console.log(`开始批量修复 ${files.length} 个页面...\n`); files.forEach(file => { const fullPath = path.join(__dirname, '..', file); if (fixPage(fullPath)) { fixed++; } }); console.log(`\n完成!共修复 ${fixed} 个页面`); } if (require.main === module) { main(); } module.exports = { fixPage };