- 包含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>
167 lines
5.5 KiB
JavaScript
167 lines
5.5 KiB
JavaScript
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
// 读取智能开发项目案例数据 - 注意这是一个数组
|
||
const rawData = fs.readFileSync('网页未导入数据/智能开发产业/智能开发项目案例.json', 'utf-8');
|
||
const smartDevProjects = JSON.parse(rawData);
|
||
|
||
console.log('开始替换项目数据...');
|
||
console.log('项目总数:', smartDevProjects.length);
|
||
console.log('第一个项目:', smartDevProjects[0]['案例名称']);
|
||
|
||
// 读取当前的mock文件
|
||
const mockFilePath = path.join(__dirname, 'src/mocks/projectLibraryMock.js');
|
||
let mockFileContent = fs.readFileSync(mockFilePath, 'utf-8');
|
||
|
||
// 构建项目列表数据 - 保持原有结构
|
||
const projectsList = smartDevProjects.map((project, index) => {
|
||
// 获取项目名称 - 使用正确的字段名
|
||
const projectName = project['案例名称'];
|
||
|
||
// 获取适用岗位 - 这是一个字符串,需要分割
|
||
const positionsStr = project['适用岗位'] || '';
|
||
const positions = positionsStr ? positionsStr.split(',').map(p => p.trim()) : [];
|
||
const positionNames = positions.map(pos => `"${pos}"`).join(', ');
|
||
|
||
// 获取所属垂直方向
|
||
const direction = project['所属垂直方向'] || '智能开发';
|
||
|
||
// 获取类别
|
||
const category = direction;
|
||
|
||
// 获取单元 - 优先使用垂直能力课
|
||
let unit = direction;
|
||
const verticalUnit = project['对应单元名称(垂直能力课)'];
|
||
const compoundUnit = project['对应单元名称(复合能力课)'];
|
||
|
||
if (verticalUnit) {
|
||
unit = verticalUnit;
|
||
} else if (compoundUnit) {
|
||
unit = compoundUnit;
|
||
}
|
||
|
||
return ` {
|
||
id: ${index + 1},
|
||
name: "${projectName}",
|
||
description: "${direction}",
|
||
positions: [${positionNames}],
|
||
unit: "${unit}",
|
||
direction: "${direction}",
|
||
category: "${category}"
|
||
}`;
|
||
});
|
||
|
||
// 替换getMockProjectsList中的项目列表
|
||
const projectsListStr = projectsList.join(',\n');
|
||
const projectsListPattern = /const projects = \[[\s\S]*?\n \];/;
|
||
const projectsListReplacement = `const projects = [\n${projectsListStr}\n ];`;
|
||
mockFileContent = mockFileContent.replace(projectsListPattern, projectsListReplacement);
|
||
|
||
console.log('✅ 项目列表数据已替换');
|
||
|
||
// 构建项目详情数据 - 保持原有结构
|
||
let projectDetailsStr = ' const projectDetails = {\n';
|
||
|
||
smartDevProjects.forEach((project, index) => {
|
||
const id = index + 1;
|
||
|
||
// 从智能开发岗位简历.json获取岗位等级信息
|
||
const positionsStr = project['适用岗位'] || '';
|
||
const positionsList = positionsStr ? positionsStr.split(',').map(p => p.trim()) : [];
|
||
|
||
// 为每个岗位生成默认等级(这里需要从另一个文件获取实际等级)
|
||
const applicablePositions = positionsList.map(pos => {
|
||
// 根据岗位名称判断等级
|
||
let level = '技术骨干岗';
|
||
if (pos.includes('助理') || pos.includes('管培生')) {
|
||
level = '基础岗';
|
||
} else if (pos.includes('总监') || pos.includes('经理')) {
|
||
level = '储备干部岗';
|
||
}
|
||
return `{ level: '${level}', position: '${pos}' }`;
|
||
}).join(', ');
|
||
|
||
// 获取单元列表
|
||
const units = [];
|
||
const compoundUnit = project['对应单元名称(复合能力课)'];
|
||
const verticalUnit = project['对应单元名称(垂直能力课)'];
|
||
|
||
if (compoundUnit) {
|
||
units.push(compoundUnit);
|
||
}
|
||
if (verticalUnit) {
|
||
units.push(verticalUnit);
|
||
}
|
||
|
||
const unitsStr = units.map(u => `'${u.replace(/'/g, "\\'")}'`).join(', ');
|
||
|
||
// 处理项目案例内容 - 提取概述、流程和技术点
|
||
const content = project['项目案例内容'] || '';
|
||
|
||
// 提取项目概述
|
||
let overview = '';
|
||
const overviewMatch = content.match(/# 一、项目概述[\s\S]*?(?=# 二、|$)/);
|
||
if (overviewMatch) {
|
||
overview = overviewMatch[0]
|
||
.replace(/# 一、项目概述\s*\n/, '')
|
||
.replace(/\n/g, ' ')
|
||
.replace(/\s+/g, ' ')
|
||
.trim()
|
||
.replace(/'/g, "\\'");
|
||
}
|
||
|
||
// 提取项目流程
|
||
let process = '';
|
||
const processMatch = content.match(/# 二、项目整体流程介绍[\s\S]*?(?=# 三、|$)/);
|
||
if (processMatch) {
|
||
process = processMatch[0]
|
||
.replace(/'/g, "\\'")
|
||
.replace(/\n/g, '\\n');
|
||
}
|
||
|
||
// 提取关键技术点
|
||
let keyPoints = '';
|
||
const keyPointsMatch = content.match(/# 三、项目案例关键技术点[\s\S]*$/);
|
||
if (keyPointsMatch) {
|
||
keyPoints = keyPointsMatch[0]
|
||
.replace(/'/g, "\\'")
|
||
.replace(/\n/g, '\\n');
|
||
}
|
||
|
||
// 处理文本内容
|
||
const title = (project['案例名称'] + '详情').replace(/'/g, "\\'");
|
||
|
||
projectDetailsStr += ` ${id}: {
|
||
id: ${id},
|
||
title: '${title}',
|
||
overview: '${overview}',
|
||
applicablePositions: [${applicablePositions}],
|
||
units: [${unitsStr}],
|
||
process: '${process}',
|
||
keyPoints: '${keyPoints}',
|
||
attachments: [
|
||
{ name: '项目文档.docx', size: '1.2MB', type: 'doc' },
|
||
{ name: '项目执行手册.pdf', size: '1.8MB', type: 'pdf' }
|
||
]
|
||
}`;
|
||
|
||
if (index < smartDevProjects.length - 1) {
|
||
projectDetailsStr += ',\n';
|
||
}
|
||
});
|
||
|
||
projectDetailsStr += '\n };\n';
|
||
|
||
// 替换projectDetails对象
|
||
const detailsPattern = /const projectDetails = \{[\s\S]*?\n \};/;
|
||
mockFileContent = mockFileContent.replace(detailsPattern, projectDetailsStr.trim());
|
||
|
||
console.log('✅ 项目详情数据已替换');
|
||
|
||
// 写入文件
|
||
fs.writeFileSync(mockFilePath, mockFileContent);
|
||
|
||
console.log('\n✅ 所有项目数据已成功替换!');
|
||
console.log('- 项目列表:24个智能开发项目');
|
||
console.log('- 项目详情:包含岗位等级和对应单元');
|
||
console.log('- 数据结构:保持原有格式不变'); |