120 lines
4.4 KiB
JavaScript
120 lines
4.4 KiB
JavaScript
|
|
const fs = require('fs');
|
|||
|
|
const path = require('path');
|
|||
|
|
|
|||
|
|
// 读取智能开发项目案例数据
|
|||
|
|
const smartDevProjects = JSON.parse(
|
|||
|
|
fs.readFileSync('网页未导入数据/智能开发产业/智能开发项目案例.json', 'utf-8')
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
// 读取当前的mock文件
|
|||
|
|
const mockFilePath = path.join(__dirname, 'src/mocks/projectLibraryMock.js');
|
|||
|
|
let mockFileContent = fs.readFileSync(mockFilePath, 'utf-8');
|
|||
|
|
|
|||
|
|
console.log('开始替换项目数据...');
|
|||
|
|
console.log('项目总数:', smartDevProjects.length);
|
|||
|
|
|
|||
|
|
// 构建项目列表数据 - 保持原有结构
|
|||
|
|
const projectsList = smartDevProjects.map((project, index) => {
|
|||
|
|
// 获取适用岗位
|
|||
|
|
const positions = Array.isArray(project['适用岗位']) ? project['适用岗位'] : [];
|
|||
|
|
const positionNames = positions.map(pos => `"${pos['岗位名称']}"`).join(', ');
|
|||
|
|
|
|||
|
|
// 获取所属垂直方向
|
|||
|
|
const direction = project['所属垂直方向'] || '智能开发';
|
|||
|
|
|
|||
|
|
// 获取类别
|
|||
|
|
const category = direction;
|
|||
|
|
|
|||
|
|
// 获取单元 - 优先使用垂直能力课
|
|||
|
|
let unit = direction;
|
|||
|
|
if (project['对应单元']) {
|
|||
|
|
if (project['对应单元']['垂直能力课'] && project['对应单元']['垂直能力课'].length > 0) {
|
|||
|
|
unit = project['对应单元']['垂直能力课'][0];
|
|||
|
|
} else if (project['对应单元']['复合能力课'] && project['对应单元']['复合能力课'].length > 0) {
|
|||
|
|
unit = project['对应单元']['复合能力课'][0];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return ` {
|
|||
|
|
id: ${index + 1},
|
|||
|
|
name: "${project['项目名称']}",
|
|||
|
|
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;
|
|||
|
|
const positions = Array.isArray(project['适用岗位']) ? project['适用岗位'] : [];
|
|||
|
|
|
|||
|
|
// 构建适用岗位数组 - 保持原始格式
|
|||
|
|
const applicablePositions = positions.map(pos => {
|
|||
|
|
return `{ level: '${pos['岗位等级标签']}', position: '${pos['岗位名称']}' }`;
|
|||
|
|
}).join(', ');
|
|||
|
|
|
|||
|
|
// 获取单元列表
|
|||
|
|
const units = [];
|
|||
|
|
if (project['对应单元']) {
|
|||
|
|
if (project['对应单元']['复合能力课']) {
|
|||
|
|
units.push(...project['对应单元']['复合能力课']);
|
|||
|
|
}
|
|||
|
|
if (project['对应单元']['垂直能力课']) {
|
|||
|
|
units.push(...project['对应单元']['垂直能力课']);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
const unitsStr = units.map(u => `'${u.replace(/'/g, "\\'")}'`).join(', ');
|
|||
|
|
|
|||
|
|
// 处理文本内容中的引号
|
|||
|
|
const title = (project['项目名称'] + '详情').replace(/'/g, "\\'");
|
|||
|
|
const overview = (project['项目概述'] || '').replace(/'/g, "\\'").replace(/\n/g, '\\n');
|
|||
|
|
const process = (project['项目整体流程介绍'] || '').replace(/'/g, "\\'").replace(/\n/g, '\\n');
|
|||
|
|
const keyPoints = (project['项目案例关键技术点'] || '').replace(/'/g, "\\'").replace(/\n/g, '\\n');
|
|||
|
|
|
|||
|
|
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('- 数据结构:保持原有格式不变');
|