import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // 读取mockData.js文件 const mockDataPath = path.join(__dirname, 'src/data/mockData.js'); let mockDataContent = fs.readFileSync(mockDataPath, 'utf-8'); // 备份原文件 const backupPath = path.join(__dirname, 'src/data', `mockData.js.backup_${new Date().toISOString().replace(/[:.]/g, '-')}`); fs.copyFileSync(mockDataPath, backupPath); console.log(`备份已创建: ${backupPath}`); // 在dashboardStatistics对象定义中添加ranking引用 const dashboardStatisticsPattern = /mockData\.dashboardStatistics\s*=\s*\{([^}]*tasks:\s*\{[^}]*\}[^}]*)\}/s; const match = mockDataContent.match(dashboardStatisticsPattern); if (match) { const newDashboardStatistics = `mockData.dashboardStatistics = {${match[1]}, // 排名数据引用 ranking: mockData.ranking }`; mockDataContent = mockDataContent.replace(dashboardStatisticsPattern, newDashboardStatistics); console.log('成功在dashboardStatistics中添加ranking引用'); } else { // 如果没找到,尝试在文件末尾添加 const addRankingLine = ` // 添加ranking到dashboardStatistics mockData.dashboardStatistics.ranking = mockData.ranking; `; // 在export之前添加 mockDataContent = mockDataContent.replace( /export default mockData;/, `${addRankingLine}\nexport default mockData;` ); console.log('成功在文件末尾添加ranking引用'); } // 写入更新后的文件 fs.writeFileSync(mockDataPath, mockDataContent, 'utf-8'); console.log('\n✅ 成功更新dashboardStatistics的ranking数据引用'); console.log('现在Dashboard页面应该可以正确显示班级排名了');