Files
online_sys/frontend_智能开发/updateProjectDataOnly.cjs
KQL a7242f0c69 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>
2025-12-12 18:16:55 +08:00

146 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require('fs');
// 读取智能开发项目案例数据
const projectData = JSON.parse(
fs.readFileSync('./网页未导入数据/智能开发产业/智能开发项目案例.json', 'utf-8')
);
console.log(`找到 ${projectData.length} 个智能开发项目案例`);
// 转换为项目库页面需要的格式 - 保持原有的数据结构
const projects = projectData.map((item, index) => {
// 解析适用岗位
const positionsStr = item['适用岗位'] || '';
const positionsList = positionsStr ? positionsStr.split(',').map(p => p.trim()) : [];
// 将岗位转换为原有格式带level的对象数组
const positions = positionsList.map(pos => ({
level: "技术骨干岗", // 默认级别
position: pos
}));
// 确定单元名称(优先使用垂直能力课,其次复合能力课)
const unit = item['对应单元名称(垂直能力课)'] || item['对应单元名称(复合能力课)'] || '';
// 确定项目类别和方向
const direction = item['所属垂直方向'] || '智能开发';
// 提取项目详情内容的各个部分
const projectDetail = item['项目案例内容'] || '';
// 简单的解析逻辑 - 提取概述、流程和技术点
let overview = '';
let process = '';
let keyPoints = '';
if (projectDetail) {
// 尝试提取项目概述
const overviewMatch = projectDetail.match(/项目概述[\s\S]*?(?=\n#|$)/);
if (overviewMatch) {
overview = overviewMatch[0].replace(/^.*项目概述\s*/, '').trim();
}
// 尝试提取项目流程
const processMatch = projectDetail.match(/项目整体流程介绍[\s\S]*?(?=\n#.*项目案例关键技术点|$)/);
if (processMatch) {
process = processMatch[0].replace(/^.*项目整体流程介绍\s*/, '').trim();
}
// 尝试提取关键技术点
const keyPointsMatch = projectDetail.match(/项目案例关键技术点[\s\S]*$/);
if (keyPointsMatch) {
keyPoints = keyPointsMatch[0].replace(/^.*项目案例关键技术点\s*/, '').trim();
}
}
// 返回与原有格式完全一致的数据结构
return {
id: index + 1,
name: item['案例名称'],
positions: positions,
unit: unit,
overview: overview || `${item['案例名称']}的项目概述`,
process: process || '',
keyPoints: keyPoints || ''
};
});
// 读取现有的projectLibraryMock.js文件
const mockFilePath = './src/mocks/projectLibraryMock.js';
let mockFileContent = fs.readFileSync(mockFilePath, 'utf-8');
// 找到projects数组的位置并替换
const projectsStr = JSON.stringify(projects, null, 2);
// 使用正则表达式替换projects数组
const startPattern = /const projects = \[/;
const startMatch = mockFileContent.match(startPattern);
if (startMatch) {
const startIndex = startMatch.index;
// 找到对应的结束位置
let bracketCount = 0;
let inString = false;
let escapeNext = false;
let endIndex = -1;
for (let i = startIndex + startMatch[0].length - 1; i < mockFileContent.length; i++) {
const char = mockFileContent[i];
if (escapeNext) {
escapeNext = false;
continue;
}
if (char === '\\') {
escapeNext = true;
continue;
}
if (char === '"' && !inString) {
inString = true;
} else if (char === '"' && inString) {
inString = false;
}
if (!inString) {
if (char === '[') bracketCount++;
if (char === ']') {
bracketCount--;
if (bracketCount === 0) {
endIndex = i + 1;
break;
}
}
}
}
if (endIndex > 0) {
// 构建新的projects部分
const newProjectsSection = `const projects = ${projectsStr}`;
// 替换内容
mockFileContent =
mockFileContent.substring(0, startIndex) +
newProjectsSection +
mockFileContent.substring(endIndex);
// 写入文件
fs.writeFileSync(mockFilePath, mockFileContent, 'utf-8');
console.log('✅ 项目库数据替换成功!');
console.log(`- 共更新 ${projects.length} 个项目`);
// 统计信息
console.log('\n前3个项目示例');
projects.slice(0, 3).forEach((p, i) => {
console.log(` ${i+1}. ${p.name}`);
console.log(` 单元: ${p.unit}`);
console.log(` 岗位数: ${p.positions.length}`);
});
} else {
console.error('❌ 未找到projects数组结束位置');
}
} else {
console.error('❌ 未找到projects数组位置请检查文件格式');
}