Initial commit: 教务系统在线平台
- 包含4个产业方向的前端项目:智能开发、智能制造、大健康、财经商贸 - 已清理node_modules、.yoyo等大文件,项目大小从2.6GB优化至631MB - 配置完善的.gitignore文件 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
137
frontend_智能开发/updatePersonalProfile.cjs
Normal file
137
frontend_智能开发/updatePersonalProfile.cjs
Normal file
@@ -0,0 +1,137 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 读取智能开发个人档案数据
|
||||
const profileData = JSON.parse(
|
||||
fs.readFileSync('./网页未导入数据/智能开发产业/智能开发个人档案.json', 'utf-8')
|
||||
);
|
||||
|
||||
// 读取头像列表
|
||||
const avatarList = JSON.parse(
|
||||
fs.readFileSync('./网页未导入数据/头像列表.json', 'utf-8')
|
||||
);
|
||||
|
||||
// 选择前10名学生
|
||||
const top10Students = profileData.slice(0, 10);
|
||||
|
||||
// 为每个学生分配头像
|
||||
const studentsWithAvatars = top10Students.map((student, index) => {
|
||||
// 从头像列表中选择头像
|
||||
const avatarIndex = index % avatarList.length;
|
||||
const avatarUrl = avatarList[avatarIndex].file_url;
|
||||
|
||||
return {
|
||||
id: index + 1,
|
||||
rank: parseInt(student.班级排名),
|
||||
name: student.学员名称,
|
||||
studentId: student.学号,
|
||||
school: student.学校名称,
|
||||
major: student.专业名称,
|
||||
credits: parseInt(student.学分),
|
||||
score: parseInt(student.学分), // 分数等于学分
|
||||
avatar: avatarUrl,
|
||||
mbti: student.MBTI,
|
||||
verticalDirection: student.垂直方向,
|
||||
// 标记袁嘉宇为当前用户
|
||||
isCurrentUser: student.学员名称 === '袁嘉宇'
|
||||
};
|
||||
});
|
||||
|
||||
// 找到袁嘉宇的数据
|
||||
const yuanJiayu = studentsWithAvatars.find(s => s.name === '袁嘉宇');
|
||||
|
||||
if (!yuanJiayu) {
|
||||
console.error('未找到袁嘉宇的数据!');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('找到袁嘉宇的数据:', yuanJiayu);
|
||||
|
||||
// 读取当前的mockData.js文件
|
||||
const mockDataPath = './src/data/mockData.js';
|
||||
let mockDataContent = fs.readFileSync(mockDataPath, 'utf-8');
|
||||
|
||||
// 备份原文件
|
||||
const backupPath = `${mockDataPath}.backup_${new Date().toISOString().replace(/[:.]/g, '-')}`;
|
||||
fs.writeFileSync(backupPath, mockDataContent);
|
||||
console.log(`已创建备份文件:${backupPath}`);
|
||||
|
||||
// 生成新的班级排名数据
|
||||
const topStudentsString = JSON.stringify(studentsWithAvatars, null, 4)
|
||||
.split('\n')
|
||||
.map(line => ' ' + line)
|
||||
.join('\n')
|
||||
.trim();
|
||||
|
||||
// 更新classRanking数组(主页班级排名)
|
||||
mockDataContent = mockDataContent.replace(
|
||||
/classRanking:\s*\[[\s\S]*?\](?=,\s*(?:learningProgress|profileOverview|personalProfile))/,
|
||||
`classRanking: [\n ${topStudentsString}\n ]`
|
||||
);
|
||||
|
||||
// 更新ranking.topStudents(Dashboard页面班级排名)
|
||||
mockDataContent = mockDataContent.replace(
|
||||
/topStudents:\s*\[[\s\S]*?\](?=\s*})/,
|
||||
`topStudents: [\n ${topStudentsString.split('\n').map(line => ' ' + line).join('\n')}\n ]`
|
||||
);
|
||||
|
||||
// 生成个人信息更新代码
|
||||
const personalProfileUpdate = `
|
||||
// 个人档案 - 袁嘉宇(智能开发产业)
|
||||
const personalProfile = {
|
||||
basicInfo: {
|
||||
name: "${yuanJiayu.name}",
|
||||
studentId: "${yuanJiayu.studentId}",
|
||||
school: "${yuanJiayu.school}",
|
||||
major: "${yuanJiayu.major}",
|
||||
class: "智能开发1班",
|
||||
credits: ${yuanJiayu.credits},
|
||||
ranking: ${yuanJiayu.rank},
|
||||
avatar: "${yuanJiayu.avatar}",
|
||||
mbti: "${yuanJiayu.mbti}",
|
||||
direction: "${yuanJiayu.verticalDirection}"
|
||||
},
|
||||
classRanking: mockData.classRanking, // 使用相同的班级排名数据
|
||||
learningRecords: mockData.learningRecords || []
|
||||
};
|
||||
|
||||
mockData.personalProfile = personalProfile;`;
|
||||
|
||||
// 查找并更新personalProfile定义
|
||||
const personalProfileRegex = /\/\/\s*个人档案[\s\S]*?mockData\.personalProfile\s*=\s*personalProfile;/;
|
||||
if (personalProfileRegex.test(mockDataContent)) {
|
||||
mockDataContent = mockDataContent.replace(personalProfileRegex, personalProfileUpdate);
|
||||
} else {
|
||||
// 如果没有找到,在mockData定义之后添加
|
||||
const mockDataDefIndex = mockDataContent.indexOf('const mockData = {');
|
||||
if (mockDataDefIndex !== -1) {
|
||||
const insertIndex = mockDataContent.indexOf('};', mockDataDefIndex) + 2;
|
||||
mockDataContent = mockDataContent.slice(0, insertIndex) + '\n' + personalProfileUpdate + mockDataContent.slice(insertIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新profileOverview中的ranking.rankings(个人档案页面的班级排名)
|
||||
mockDataContent = mockDataContent.replace(
|
||||
/profileOverview:\s*{[\s\S]*?ranking:\s*{[\s\S]*?rankings:\s*\[[\s\S]*?\][\s\S]*?}/,
|
||||
(match) => {
|
||||
return match.replace(
|
||||
/rankings:\s*\[[\s\S]*?\]/,
|
||||
`rankings: [\n ${topStudentsString.split('\n').map(line => ' ' + line).join('\n')}\n ]`
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// 写回文件
|
||||
fs.writeFileSync(mockDataPath, mockDataContent);
|
||||
|
||||
console.log('✅ 个人档案数据更新完成!');
|
||||
console.log('更新内容:');
|
||||
console.log('- 个人信息:袁嘉宇(排名第5)');
|
||||
console.log('- 班级排名:前10名学生');
|
||||
console.log('- 所有相关数据已同步更新');
|
||||
|
||||
// 输出前3名学生信息作为验证
|
||||
console.log('\n前3名学生:');
|
||||
studentsWithAvatars.slice(0, 3).forEach(s => {
|
||||
console.log(`${s.rank}. ${s.name} - ${s.school} - ${s.credits}分`);
|
||||
});
|
||||
Reference in New Issue
Block a user