113 lines
3.7 KiB
JavaScript
113 lines
3.7 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');
|
||
|
|
|
||
|
|
// 构建项目列表数据
|
||
|
|
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;
|
||
|
|
|
||
|
|
// 获取单元
|
||
|
|
const unit = project['对应单元'] ?
|
||
|
|
(project['对应单元']['垂直能力课'] && project['对应单元']['垂直能力课'][0]) || direction :
|
||
|
|
direction;
|
||
|
|
|
||
|
|
return ` {
|
||
|
|
id: ${index + 1},
|
||
|
|
name: "${project['项目名称']}",
|
||
|
|
description: "${direction}",
|
||
|
|
positions: [${positionNames}],
|
||
|
|
unit: "${unit}",
|
||
|
|
direction: "${direction}",
|
||
|
|
category: "${category}"
|
||
|
|
}`;
|
||
|
|
});
|
||
|
|
|
||
|
|
// 替换getMockProjectsList中的项目列表
|
||
|
|
const projectsListStr = projectsList.join(',\n');
|
||
|
|
mockFileContent = mockFileContent.replace(
|
||
|
|
/const projects = \[[\s\S]*?\];/,
|
||
|
|
`const projects = [\n${projectsListStr}\n ];`
|
||
|
|
);
|
||
|
|
|
||
|
|
// 构建项目详情数据
|
||
|
|
const projectDetails = {};
|
||
|
|
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}'`).join(', ');
|
||
|
|
|
||
|
|
projectDetails[id] = {
|
||
|
|
id,
|
||
|
|
title: project['项目名称'] + '详情',
|
||
|
|
overview: project['项目概述'] || '',
|
||
|
|
applicablePositions,
|
||
|
|
units: unitsStr,
|
||
|
|
process: project['项目整体流程介绍'] || '',
|
||
|
|
keyPoints: project['项目案例关键技术点'] || '',
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
// 构建projectDetails对象字符串
|
||
|
|
let projectDetailsStr = ' const projectDetails = {\n';
|
||
|
|
for (const [id, detail] of Object.entries(projectDetails)) {
|
||
|
|
projectDetailsStr += ` ${id}: {
|
||
|
|
id: ${id},
|
||
|
|
title: '${detail.title}',
|
||
|
|
overview: '${detail.overview.replace(/'/g, "\\'")}',
|
||
|
|
applicablePositions: [${detail.applicablePositions}],
|
||
|
|
units: [${detail.units}],
|
||
|
|
process: '${detail.process.replace(/'/g, "\\'")}',
|
||
|
|
keyPoints: '${detail.keyPoints.replace(/'/g, "\\'")}',
|
||
|
|
attachments: [
|
||
|
|
{ name: '项目文档.docx', size: '1.2MB', type: 'doc' },
|
||
|
|
{ name: '项目执行手册.pdf', size: '1.8MB', type: 'pdf' }
|
||
|
|
]
|
||
|
|
},\n`;
|
||
|
|
}
|
||
|
|
// 移除最后的逗号
|
||
|
|
projectDetailsStr = projectDetailsStr.slice(0, -2) + '\n };\n';
|
||
|
|
|
||
|
|
// 替换getMockProjectDetail函数中的projectDetails
|
||
|
|
mockFileContent = mockFileContent.replace(
|
||
|
|
/const projectDetails = \{[\s\S]*?\n \};/,
|
||
|
|
projectDetailsStr.trim()
|
||
|
|
);
|
||
|
|
|
||
|
|
// 写入文件
|
||
|
|
fs.writeFileSync(mockFilePath, mockFileContent);
|
||
|
|
|
||
|
|
console.log('✅ 项目数据已更新,保持原始代码结构!');
|