// 转换智能制造项目案例数据为项目库格式 import fs from 'fs'; // 读取智能制造项目案例数据 const rawData = JSON.parse( fs.readFileSync('网页未导入数据/智能制造产业/智能制造项目案例.json', 'utf8') ); // 转换数据格式 const projects = rawData.map((item, index) => { // 提取岗位名称列表 const positions = item['对应个人简历名称'] ? item['对应个人简历名称'].split(',').map(p => p.trim()) : []; // 确定项目类别 let category = '智能制造'; let direction = item['所属垂直方向'] || '智能制造'; // 根据单元名称细分类别 if (item['对应单元名称(垂直能力课)']) { if (item['对应单元名称(垂直能力课)'].includes('新能源')) { category = '新能源制造'; } else if (item['对应单元名称(垂直能力课)'].includes('PLC')) { category = 'PLC控制系统'; } else if (item['对应单元名称(垂直能力课)'].includes('机器人')) { category = '工业机器人'; } else if (item['对应单元名称(垂直能力课)'].includes('3D打印')) { category = '3D打印技术'; } else if (item['对应单元名称(垂直能力课)'].includes('数控')) { category = '数控加工'; } } return { id: index + 1, name: item['案例名称'], description: direction, positions: positions, unit: item['对应单元名称(垂直能力课)'] || item['对应单元名称(复合能力课)'], direction: direction, category: category, content: item['项目案例内容'] || '' }; }); // 生成mock数据格式 const mockCode = `// 项目库Mock数据 export const getMockProjectsList = (params = {}) => { const { search = "", page = 1, pageSize = 10 } = params; // 完整项目列表数据 const projects = ${JSON.stringify(projects, null, 4)}; // 搜索过滤 let filteredProjects = projects; if (search) { const searchLower = search.toLowerCase(); filteredProjects = projects.filter(project => 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 total = filteredProjects.length; const startIndex = (page - 1) * pageSize; const endIndex = startIndex + pageSize; const pagedProjects = filteredProjects.slice(startIndex, endIndex); return { success: true, data: { list: pagedProjects, total: total, page: page, pageSize: pageSize } }; }; // 获取项目详情 export const getMockProjectDetail = (id) => { const projects = ${JSON.stringify(projects.slice(0, 3), null, 4)}; const project = projects.find(p => p.id === parseInt(id)); if (project) { return { success: true, data: project }; } return { success: false, message: "项目不存在" }; }; `; // 写入转换后的文件 fs.writeFileSync('projectLibraryMock_new.js', mockCode, 'utf8'); console.log(`转换完成! - 项目总数: ${projects.length} - 类别分布: ${[...new Set(projects.map(p => p.category))].map(cat => ` - ${cat}: ${projects.filter(p => p.category === cat).length}个` ).join('\n')} 文件已保存为: projectLibraryMock_new.js `);