- 包含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>
312 lines
9.6 KiB
JavaScript
312 lines
9.6 KiB
JavaScript
const fs = require('fs');
|
||
|
||
// 读取智能开发项目案例数据
|
||
const smartDevData = JSON.parse(
|
||
fs.readFileSync('./网页未导入数据/智能开发产业/智能开发项目案例.json', 'utf-8')
|
||
);
|
||
|
||
console.log(`找到 ${smartDevData.length} 个智能开发项目案例`);
|
||
|
||
// 转换为项目库格式
|
||
const projects = smartDevData.map((item, index) => {
|
||
// 解析适用岗位
|
||
const positionsStr = item['适用岗位'] || '';
|
||
const positionsList = positionsStr ? positionsStr.split(',').map(p => p.trim()) : [];
|
||
|
||
// 为岗位分配等级
|
||
const positions = positionsList.map(pos => {
|
||
let level = '技术骨干岗'; // 默认级别
|
||
|
||
if (pos.includes('助理') || pos.includes('实习') || pos.includes('初级')) {
|
||
level = '普通岗';
|
||
} else if (pos.includes('高级') || pos.includes('专家') || pos.includes('经理') || pos.includes('总监')) {
|
||
level = '储备干部岗';
|
||
}
|
||
|
||
return {
|
||
level: level,
|
||
position: pos
|
||
};
|
||
});
|
||
|
||
// 确定单元名称
|
||
const unit = item['对应单元名称(垂直能力课)'] || 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*/, '').replace(/^[\n#]+/, '').trim();
|
||
// 清理markdown标记
|
||
overview = overview.replace(/^#\s*/gm, '').replace(/\*\*/g, '').replace(/\n+/g, ' ');
|
||
// 只取前500个字符
|
||
if (overview.length > 500) {
|
||
overview = overview.substring(0, 497) + '...';
|
||
}
|
||
}
|
||
|
||
// 提取项目流程
|
||
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();
|
||
}
|
||
}
|
||
|
||
// 如果没有提取到概述,使用默认描述
|
||
if (!overview) {
|
||
overview = `${item['案例名称']}是一个${item['所属垂直方向'] || '智能开发'}方向的项目,旨在提升相关技术能力和实践经验。`;
|
||
}
|
||
|
||
return {
|
||
id: index + 1,
|
||
name: item['案例名称'],
|
||
description: item['所属垂直方向'] || '智能开发',
|
||
positions: positionsList, // 保留字符串数组格式
|
||
unit: unit,
|
||
direction: item['所属垂直方向'] || '智能开发',
|
||
category: item['所属垂直方向'] || '智能开发',
|
||
overview: overview,
|
||
process: process,
|
||
keyPoints: keyPoints,
|
||
// 为详情页准备的额外数据
|
||
detailData: {
|
||
positions: positions, // 带等级的岗位数组
|
||
applicablePositions: positions,
|
||
correspondingUnits: unit ? [unit] : [],
|
||
compoundUnit: item['对应单元名称(复合能力课)'] || '',
|
||
verticalUnit: item['对应单元名称(垂直能力课)'] || ''
|
||
}
|
||
};
|
||
});
|
||
|
||
// 1. 更新projectLibraryMock.js
|
||
const mockPath = './src/mocks/projectLibraryMock.js';
|
||
let mockContent = fs.readFileSync(mockPath, 'utf-8');
|
||
|
||
// 构建新的getMockProjectsList函数
|
||
const projectsListStr = JSON.stringify(projects.map(p => ({
|
||
id: p.id,
|
||
name: p.name,
|
||
description: p.description,
|
||
positions: p.positions,
|
||
unit: p.unit,
|
||
direction: p.direction,
|
||
category: p.category
|
||
})), null, 4);
|
||
|
||
const newGetMockProjectsList = `// 项目库Mock数据
|
||
export const getMockProjectsList = (params = {}) => {
|
||
const { search = "", page = 1, pageSize = 10 } = params;
|
||
|
||
// 智能开发项目列表数据
|
||
const projects = ${projectsListStr};
|
||
|
||
// 搜索过滤
|
||
let filteredProjects = projects;
|
||
if (search) {
|
||
filteredProjects = projects.filter(project =>
|
||
project.name.includes(search) ||
|
||
project.description.includes(search) ||
|
||
project.positions.some(pos => pos.includes(search)) ||
|
||
project.category.includes(search)
|
||
);
|
||
}
|
||
|
||
// 分页
|
||
const start = (page - 1) * pageSize;
|
||
const end = start + pageSize;
|
||
const paginatedProjects = filteredProjects.slice(start, end);
|
||
|
||
return {
|
||
success: true,
|
||
code: 0,
|
||
msg: "success",
|
||
data: paginatedProjects,
|
||
total: filteredProjects.length
|
||
};
|
||
};`;
|
||
|
||
// 替换getMockProjectsList函数
|
||
const listFuncPattern = /\/\/ 项目库Mock数据[\s\S]*?export const getMockProjectsList[\s\S]*?\n\};/;
|
||
const listFuncMatch = mockContent.match(listFuncPattern);
|
||
|
||
if (listFuncMatch) {
|
||
mockContent = mockContent.replace(listFuncMatch[0], newGetMockProjectsList);
|
||
} else {
|
||
console.error('未找到getMockProjectsList函数,尝试其他模式');
|
||
const altPattern = /export const getMockProjectsList[\s\S]*?\n\};/;
|
||
const altMatch = mockContent.match(altPattern);
|
||
if (altMatch) {
|
||
mockContent = mockContent.replace(altMatch[0], newGetMockProjectsList);
|
||
}
|
||
}
|
||
|
||
// 构建新的getMockProjectDetail函数
|
||
const projectsDetailStr = JSON.stringify(projects, null, 2);
|
||
|
||
const newGetMockProjectDetail = `
|
||
|
||
export const getMockProjectDetail = (id) => {
|
||
// 智能开发项目详细数据
|
||
const projects = ${projectsDetailStr};
|
||
|
||
const project = projects.find(p => p.id === parseInt(id));
|
||
|
||
if (!project) {
|
||
return {
|
||
success: false,
|
||
code: 404,
|
||
message: "项目不存在",
|
||
data: null
|
||
};
|
||
}
|
||
|
||
// 构造返回数据
|
||
return {
|
||
success: true,
|
||
code: 0,
|
||
message: "success",
|
||
data: {
|
||
id: project.id,
|
||
title: project.name,
|
||
category: project.category,
|
||
description: project.overview,
|
||
overview: project.overview,
|
||
applicablePositions: project.detailData.applicablePositions || [],
|
||
correspondingUnits: project.detailData.correspondingUnits || [],
|
||
process: project.process || "",
|
||
keyPoints: project.keyPoints || "",
|
||
attachments: []
|
||
}
|
||
};
|
||
};`;
|
||
|
||
// 替换getMockProjectDetail函数
|
||
const detailFuncPattern = /export const getMockProjectDetail[\s\S]*?\n\};/;
|
||
const detailFuncMatch = mockContent.match(detailFuncPattern);
|
||
|
||
if (detailFuncMatch) {
|
||
mockContent = mockContent.replace(detailFuncMatch[0], newGetMockProjectDetail);
|
||
} else {
|
||
// 如果没找到,就添加在文件末尾
|
||
mockContent += '\n' + newGetMockProjectDetail;
|
||
}
|
||
|
||
// 写入文件
|
||
fs.writeFileSync(mockPath, mockContent, 'utf-8');
|
||
|
||
console.log('✅ projectLibraryMock.js已更新为智能开发项目数据!');
|
||
|
||
// 2. 更新项目库页面的标题和分类
|
||
const pagePath = './src/pages/ProjectLibraryPage/index.jsx';
|
||
let pageContent = fs.readFileSync(pagePath, 'utf-8');
|
||
|
||
// 更新标题
|
||
pageContent = pageContent.replace(
|
||
/<p className="project-library-title">.*?<\/p>/,
|
||
'<p className="project-library-title">智能开发班级项目库</p>'
|
||
);
|
||
|
||
// 更新分类
|
||
const categories = [...new Set(projects.map(p => p.direction))];
|
||
const categoriesWithAll = ['全部', ...categories];
|
||
const categoriesStr = JSON.stringify(categoriesWithAll);
|
||
|
||
pageContent = pageContent.replace(
|
||
/const categories = \[.*?\];/,
|
||
`const categories = ${categoriesStr};`
|
||
);
|
||
|
||
fs.writeFileSync(pagePath, pageContent, 'utf-8');
|
||
|
||
console.log('✅ 项目库页面标题和分类已更新!');
|
||
|
||
// 3. 更新projectUnitsMapping.js
|
||
const mappingPath = './src/data/projectUnitsMapping.js';
|
||
|
||
// 构建新的映射数据
|
||
const unitsMapping = {};
|
||
projects.forEach(p => {
|
||
unitsMapping[p.name] = {
|
||
compoundUnits: p.detailData.compoundUnit ? [p.detailData.compoundUnit] : [],
|
||
verticalUnits: p.detailData.verticalUnit ? [p.detailData.verticalUnit] : []
|
||
};
|
||
});
|
||
|
||
const mappingContent = `// 项目案例对应单元映射数据
|
||
// 基于智能开发产业项目案例
|
||
|
||
export const projectUnitsMapping = ${JSON.stringify(unitsMapping, null, 2)};
|
||
|
||
// 获取项目的复合能力课程
|
||
export const getCompoundUnits = (projectTitle) => {
|
||
if (!projectTitle) return [];
|
||
|
||
// 直接匹配
|
||
if (projectUnitsMapping[projectTitle]) {
|
||
return projectUnitsMapping[projectTitle].compoundUnits || [];
|
||
}
|
||
|
||
// 尝试去除后缀后匹配(如"详情")
|
||
const cleanTitle = projectTitle.replace(/详情$/, '');
|
||
if (projectUnitsMapping[cleanTitle]) {
|
||
return projectUnitsMapping[cleanTitle].compoundUnits || [];
|
||
}
|
||
|
||
return [];
|
||
};
|
||
|
||
// 获取项目的垂直能力课程
|
||
export const getVerticalUnits = (projectTitle) => {
|
||
if (!projectTitle) return [];
|
||
|
||
// 直接匹配
|
||
if (projectUnitsMapping[projectTitle]) {
|
||
return projectUnitsMapping[projectTitle].verticalUnits || [];
|
||
}
|
||
|
||
// 尝试去除后缀后匹配(如"详情")
|
||
const cleanTitle = projectTitle.replace(/详情$/, '');
|
||
if (projectUnitsMapping[cleanTitle]) {
|
||
return projectUnitsMapping[cleanTitle].verticalUnits || [];
|
||
}
|
||
|
||
return [];
|
||
};
|
||
|
||
// 获取项目的所有对应单元
|
||
export const getProjectUnits = (projectTitle) => {
|
||
const mapping = projectUnitsMapping[projectTitle];
|
||
if (!mapping) return [];
|
||
|
||
return [...mapping.compoundUnits, ...mapping.verticalUnits];
|
||
};`;
|
||
|
||
fs.writeFileSync(mappingPath, mappingContent, 'utf-8');
|
||
|
||
console.log('✅ projectUnitsMapping.js已更新!');
|
||
|
||
// 输出统计信息
|
||
console.log('\n📊 数据替换统计:');
|
||
console.log(`- 项目总数: ${projects.length}`);
|
||
console.log(`- 分类数量: ${categories.length}`);
|
||
console.log('\n前5个项目示例:');
|
||
projects.slice(0, 5).forEach((p, i) => {
|
||
console.log(` ${i + 1}. ${p.name}`);
|
||
console.log(` 方向: ${p.direction}`);
|
||
console.log(` 岗位: ${p.positions.join(', ')}`);
|
||
console.log(` 单元: ${p.unit}`);
|
||
}); |