163 lines
4.8 KiB
JavaScript
163 lines
4.8 KiB
JavaScript
|
|
const fs = require('fs');
|
|||
|
|
|
|||
|
|
// 读取智能开发项目案例数据
|
|||
|
|
const projectData = JSON.parse(
|
|||
|
|
fs.readFileSync('./网页未导入数据/智能开发产业/智能开发项目案例.json', 'utf-8')
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
console.log(`找到 ${projectData.length} 个智能开发项目案例`);
|
|||
|
|
|
|||
|
|
// 转换为项目库页面需要的格式
|
|||
|
|
const projects = projectData.map((item, index) => {
|
|||
|
|
// 解析对应岗位
|
|||
|
|
const positions = item['对应个人简历名称']
|
|||
|
|
? item['对应个人简历名称'].split(',').map(p => p.trim())
|
|||
|
|
: [];
|
|||
|
|
|
|||
|
|
// 确定单元名称(优先使用垂直能力课,其次复合能力课)
|
|||
|
|
const unit = item['对应单元名称(垂直能力课)'] || item['对应单元名称(复合能力课)'] || '';
|
|||
|
|
|
|||
|
|
// 确定项目类别(基于垂直方向)
|
|||
|
|
const directionMap = {
|
|||
|
|
'AI智能应用开发': 'AI应用开发',
|
|||
|
|
'网络安全': '网络安全',
|
|||
|
|
'AI大前端开发': '前端开发',
|
|||
|
|
'AIOps智能运维': '智能运维'
|
|||
|
|
};
|
|||
|
|
const category = directionMap[item['所属垂直方向']] || item['所属垂直方向'] || '其他';
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
id: index + 1,
|
|||
|
|
name: item['案例名称'],
|
|||
|
|
description: item['所属垂直方向'] || '智能开发项目',
|
|||
|
|
positions: positions,
|
|||
|
|
unit: unit,
|
|||
|
|
direction: item['所属垂直方向'] || '智能开发',
|
|||
|
|
category: category,
|
|||
|
|
// 保留项目详情内容
|
|||
|
|
projectDetail: item['项目案例内容'] || ''
|
|||
|
|
};
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 更新myProjectsData - 按单元分组
|
|||
|
|
const unitProjectMap = {};
|
|||
|
|
projects.forEach(project => {
|
|||
|
|
if (project.unit) {
|
|||
|
|
if (!unitProjectMap[project.unit]) {
|
|||
|
|
unitProjectMap[project.unit] = [];
|
|||
|
|
}
|
|||
|
|
unitProjectMap[project.unit].push(project.name);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const myProjectsData = Object.entries(unitProjectMap).map(([unitName, projectNames]) => ({
|
|||
|
|
unitName: unitName,
|
|||
|
|
projects: projectNames
|
|||
|
|
}));
|
|||
|
|
|
|||
|
|
// 生成projectLibraryMock.js文件内容
|
|||
|
|
const mockFileContent = `// 项目库Mock数据
|
|||
|
|
export const getMockProjectsList = (params = {}) => {
|
|||
|
|
const { search = "", page = 1, pageSize = 10 } = params;
|
|||
|
|
|
|||
|
|
// 完整项目列表数据
|
|||
|
|
const projects = ${JSON.stringify(projects, null, 4)};
|
|||
|
|
|
|||
|
|
// 搜索过滤
|
|||
|
|
const filteredProjects = projects.filter(project => {
|
|||
|
|
if (!search) return true;
|
|||
|
|
const searchLower = search.toLowerCase();
|
|||
|
|
return (
|
|||
|
|
project.name.toLowerCase().includes(searchLower) ||
|
|||
|
|
project.description.toLowerCase().includes(searchLower) ||
|
|||
|
|
project.positions.some(pos => pos.toLowerCase().includes(searchLower)) ||
|
|||
|
|
project.unit.toLowerCase().includes(searchLower) ||
|
|||
|
|
project.category.toLowerCase().includes(searchLower)
|
|||
|
|
);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 分页
|
|||
|
|
const start = (page - 1) * pageSize;
|
|||
|
|
const end = start + pageSize;
|
|||
|
|
const paginatedProjects = filteredProjects.slice(start, end);
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
code: 0,
|
|||
|
|
msg: "success",
|
|||
|
|
data: {
|
|||
|
|
list: paginatedProjects,
|
|||
|
|
total: filteredProjects.length,
|
|||
|
|
page,
|
|||
|
|
pageSize,
|
|||
|
|
hasMore: end < filteredProjects.length
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
export const getMockProjectDetail = (id) => {
|
|||
|
|
const projects = ${JSON.stringify(projects, null, 4)};
|
|||
|
|
|
|||
|
|
const project = projects.find(p => p.id === parseInt(id));
|
|||
|
|
|
|||
|
|
if (!project) {
|
|||
|
|
return {
|
|||
|
|
code: 404,
|
|||
|
|
msg: "项目不存在",
|
|||
|
|
data: null
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
code: 0,
|
|||
|
|
msg: "success",
|
|||
|
|
data: project
|
|||
|
|
};
|
|||
|
|
};`;
|
|||
|
|
|
|||
|
|
// 写入projectLibraryMock.js
|
|||
|
|
fs.writeFileSync('./src/mocks/projectLibraryMock.js', mockFileContent, 'utf-8');
|
|||
|
|
|
|||
|
|
// 更新页面中的myProjectsData
|
|||
|
|
const pageFilePath = './src/pages/ProjectLibraryPage/index.jsx';
|
|||
|
|
let pageContent = fs.readFileSync(pageFilePath, 'utf-8');
|
|||
|
|
|
|||
|
|
// 替换myProjectsData
|
|||
|
|
const myProjectsDataStr = JSON.stringify(myProjectsData, null, 2)
|
|||
|
|
.replace(/"/g, '"'); // 保持双引号
|
|||
|
|
|
|||
|
|
const startMarker = 'const myProjectsData = [';
|
|||
|
|
const endMarker = '];';
|
|||
|
|
|
|||
|
|
const startIndex = pageContent.indexOf(startMarker);
|
|||
|
|
if (startIndex !== -1) {
|
|||
|
|
const endIndex = pageContent.indexOf(endMarker, startIndex) + endMarker.length;
|
|||
|
|
|
|||
|
|
const newContent =
|
|||
|
|
pageContent.substring(0, startIndex) +
|
|||
|
|
`const myProjectsData = ${myProjectsDataStr}];` +
|
|||
|
|
pageContent.substring(endIndex);
|
|||
|
|
|
|||
|
|
fs.writeFileSync(pageFilePath, newContent, 'utf-8');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('✅ 项目库数据更新成功!');
|
|||
|
|
console.log(`- 共更新 ${projects.length} 个项目`);
|
|||
|
|
console.log(`- 生成 ${myProjectsData.length} 个单元分组`);
|
|||
|
|
|
|||
|
|
// 输出统计信息
|
|||
|
|
const categoryCount = {};
|
|||
|
|
projects.forEach(p => {
|
|||
|
|
categoryCount[p.category] = (categoryCount[p.category] || 0) + 1;
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
console.log('\n项目类别统计:');
|
|||
|
|
Object.entries(categoryCount).forEach(([cat, count]) => {
|
|||
|
|
console.log(` ${cat}: ${count}个`);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
console.log('\n前5个项目示例:');
|
|||
|
|
projects.slice(0, 5).forEach((p, i) => {
|
|||
|
|
console.log(` ${i+1}. ${p.name}`);
|
|||
|
|
console.log(` 单元: ${p.unit}`);
|
|||
|
|
console.log(` 岗位: ${p.positions.slice(0, 3).join(', ')}`);
|
|||
|
|
});
|