87 lines
2.9 KiB
JavaScript
87 lines
2.9 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// 需要更新的页面文件列表
|
|
const pagesToUpdate = [
|
|
'src/pages/scenarios/ScenarioDetail.tsx',
|
|
'src/pages/scenarios/NewPlan.tsx',
|
|
'src/pages/plans/Plans.tsx',
|
|
'src/pages/plans/PlanDetail.tsx',
|
|
'src/pages/orders/Orders.tsx',
|
|
'src/pages/profile/Profile.tsx',
|
|
'src/pages/content/Content.tsx',
|
|
'src/pages/contact-import/ContactImport.tsx',
|
|
'src/pages/traffic-pool/TrafficPool.tsx',
|
|
'src/pages/workspace/Workspace.tsx'
|
|
];
|
|
|
|
// 更新规则
|
|
const updateRules = [
|
|
{
|
|
// 替换旧的header结构
|
|
pattern: /<header className="[^"]*fixed[^"]*">\s*<div className="[^"]*">\s*<div className="[^"]*">\s*<button[^>]*onClick=\{\(\) => navigate\(-1\)\}[^>]*>\s*<ChevronLeft[^>]*\/>\s*<\/button>\s*<h1[^>]*>([^<]*)<\/h1>\s*<\/div>\s*(?:<div[^>]*>([\s\S]*?)<\/div>)?\s*<\/div>\s*<\/header>/g,
|
|
replacement: (match, title, rightContent) => {
|
|
const rightContentStr = rightContent ? `\n rightContent={\n ${rightContent.trim()}\n }` : '';
|
|
return `<PageHeader\n title="${title.trim()}"\n defaultBackPath="/"${rightContentStr}\n />`;
|
|
}
|
|
},
|
|
{
|
|
// 替换简单的header结构
|
|
pattern: /<header className="[^"]*">\s*<div className="[^"]*">\s*<h1[^>]*>([^<]*)<\/h1>\s*<\/div>\s*<\/header>/g,
|
|
replacement: (match, title) => {
|
|
return `<PageHeader\n title="${title.trim()}"\n showBack={false}\n />`;
|
|
}
|
|
},
|
|
{
|
|
// 添加PageHeader导入
|
|
pattern: /import React[^;]+;/,
|
|
replacement: (match) => {
|
|
return `${match}\nimport PageHeader from '@/components/PageHeader';`;
|
|
}
|
|
}
|
|
];
|
|
|
|
function updateFile(filePath) {
|
|
try {
|
|
const fullPath = path.join(process.cwd(), filePath);
|
|
if (!fs.existsSync(fullPath)) {
|
|
console.log(`文件不存在: ${filePath}`);
|
|
return;
|
|
}
|
|
|
|
let content = fs.readFileSync(fullPath, 'utf8');
|
|
let updated = false;
|
|
|
|
// 应用更新规则
|
|
updateRules.forEach(rule => {
|
|
const newContent = content.replace(rule.pattern, rule.replacement);
|
|
if (newContent !== content) {
|
|
content = newContent;
|
|
updated = true;
|
|
}
|
|
});
|
|
|
|
if (updated) {
|
|
fs.writeFileSync(fullPath, content, 'utf8');
|
|
console.log(`✅ 已更新: ${filePath}`);
|
|
} else {
|
|
console.log(`⏭️ 无需更新: ${filePath}`);
|
|
}
|
|
} catch (error) {
|
|
console.error(`❌ 更新失败: ${filePath}`, error.message);
|
|
}
|
|
}
|
|
|
|
// 执行批量更新
|
|
console.log('🚀 开始批量更新页面Header...\n');
|
|
|
|
pagesToUpdate.forEach(filePath => {
|
|
updateFile(filePath);
|
|
});
|
|
|
|
console.log('\n✨ 批量更新完成!');
|
|
console.log('\n📝 注意事项:');
|
|
console.log('1. 请检查更新后的文件是否正确');
|
|
console.log('2. 可能需要手动调整一些特殊的header结构');
|
|
console.log('3. 确保所有页面都正确导入了PageHeader组件');
|
|
console.log('4. 运行 npm run build 检查是否有编译错误');
|