121 lines
4.7 KiB
JavaScript
121 lines
4.7 KiB
JavaScript
|
|
import fs from 'fs';
|
||
|
|
import path from 'path';
|
||
|
|
import { fileURLToPath } from 'url';
|
||
|
|
|
||
|
|
const __filename = fileURLToPath(import.meta.url);
|
||
|
|
const __dirname = path.dirname(__filename);
|
||
|
|
|
||
|
|
// 读取环保项目案例数据
|
||
|
|
const envProjectsPath = path.join(__dirname, '网页未导入数据/环保产业/环保项目案例.json');
|
||
|
|
const envProjectsData = JSON.parse(fs.readFileSync(envProjectsPath, 'utf-8'));
|
||
|
|
|
||
|
|
// 创建备份
|
||
|
|
const mockFilePath = path.join(__dirname, 'src/mocks/projectLibraryMock.js');
|
||
|
|
const backupPath = mockFilePath + '.backup_' + new Date().toISOString().replace(/[:.]/g, '-');
|
||
|
|
fs.copyFileSync(mockFilePath, backupPath);
|
||
|
|
console.log(`✅ 备份已创建: ${backupPath}`);
|
||
|
|
|
||
|
|
// 转换环保项目数据为所需格式
|
||
|
|
const projectsList = envProjectsData.map((project, index) => {
|
||
|
|
const id = index + 1;
|
||
|
|
|
||
|
|
// 解析对应岗位
|
||
|
|
const positions = project["对应个人简历名称"] ?
|
||
|
|
project["对应个人简历名称"].split(',').map(pos => {
|
||
|
|
// 根据岗位名称判断等级
|
||
|
|
let level = "技术骨干岗";
|
||
|
|
if (pos.includes("助理") || pos.includes("员")) {
|
||
|
|
level = "基础岗";
|
||
|
|
} else if (pos.includes("总监")) {
|
||
|
|
level = "储备干部岗";
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
level,
|
||
|
|
position: pos.trim()
|
||
|
|
};
|
||
|
|
}) : [];
|
||
|
|
|
||
|
|
// 处理项目概述 - 提取第一段作为简短概述
|
||
|
|
const fullContent = project["项目案例内容"] || "";
|
||
|
|
const overviewMatch = fullContent.match(/# 一、项目概述\n\n([^#]+)/);
|
||
|
|
const overview = overviewMatch ? overviewMatch[1].trim() : "";
|
||
|
|
|
||
|
|
return {
|
||
|
|
id,
|
||
|
|
name: project["案例名称"],
|
||
|
|
description: project["所属垂直方向"],
|
||
|
|
positions,
|
||
|
|
unit: project["对应单元名称(垂直能力课)"],
|
||
|
|
direction: project["所属垂直方向"],
|
||
|
|
category: getCategoryFromProject(project["案例名称"]),
|
||
|
|
// 项目详情数据
|
||
|
|
overview,
|
||
|
|
process: extractSection(fullContent, "项目整体流程介绍"),
|
||
|
|
keyPoints: extractSection(fullContent, "项目案例关键技术点")
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
// 根据项目名称判断分类
|
||
|
|
function getCategoryFromProject(name) {
|
||
|
|
if (name.includes("环境影响评价")) return "环境评价";
|
||
|
|
if (name.includes("碳排放") || name.includes("碳")) return "碳管理";
|
||
|
|
if (name.includes("节能")) return "节能技术";
|
||
|
|
if (name.includes("水处理") || name.includes("污水")) return "水处理";
|
||
|
|
if (name.includes("生态修复") || name.includes("湿地")) return "生态修复";
|
||
|
|
if (name.includes("土壤")) return "土壤修复";
|
||
|
|
if (name.includes("回收")) return "资源回收";
|
||
|
|
if (name.includes("检测") || name.includes("监测")) return "环境监测";
|
||
|
|
if (name.includes("ISO") || name.includes("体系")) return "体系认证";
|
||
|
|
if (name.includes("EHS") || name.includes("安全")) return "安全管理";
|
||
|
|
return "其他";
|
||
|
|
}
|
||
|
|
|
||
|
|
// 提取内容中的特定章节
|
||
|
|
function extractSection(content, sectionTitle) {
|
||
|
|
const regex = new RegExp(`# [二三]、${sectionTitle}\\n\\n([\\s\\S]*?)(?=# [二三四]、|$)`, 'g');
|
||
|
|
const match = regex.exec(content);
|
||
|
|
return match ? match[1].trim() : "";
|
||
|
|
}
|
||
|
|
|
||
|
|
// 读取原始mock文件
|
||
|
|
let mockContent = fs.readFileSync(mockFilePath, 'utf-8');
|
||
|
|
|
||
|
|
// 生成新的项目列表代码
|
||
|
|
const projectsListCode = `const projects = ${JSON.stringify(projectsList, null, 2)}`;
|
||
|
|
|
||
|
|
// 替换getMockProjectsList函数中的projects数组
|
||
|
|
mockContent = mockContent.replace(
|
||
|
|
/export const getMockProjectsList[\s\S]*?const projects = \[[\s\S]*?\n \];/,
|
||
|
|
`export const getMockProjectsList = (params = {}) => {
|
||
|
|
const { search = "", page = 1, pageSize = 10 } = params;
|
||
|
|
|
||
|
|
// 完整项目列表数据
|
||
|
|
${projectsListCode};`
|
||
|
|
);
|
||
|
|
|
||
|
|
// 替换getMockProjectDetail函数中的projects数组
|
||
|
|
mockContent = mockContent.replace(
|
||
|
|
/export const getMockProjectDetail[\s\S]*?const projects = \[[\s\S]*?\n \];/,
|
||
|
|
`export const getMockProjectDetail = (id) => {
|
||
|
|
// 直接根据ID返回对应项目的详情
|
||
|
|
${projectsListCode};`
|
||
|
|
);
|
||
|
|
|
||
|
|
// 写入更新后的内容
|
||
|
|
fs.writeFileSync(mockFilePath, mockContent, 'utf-8');
|
||
|
|
|
||
|
|
console.log(`✅ 成功替换 ${projectsList.length} 个环保项目数据`);
|
||
|
|
console.log('✅ 项目分类:', [...new Set(projectsList.map(p => p.category))].join(', '));
|
||
|
|
|
||
|
|
// 验证数据
|
||
|
|
const validateData = () => {
|
||
|
|
console.log('\n📋 数据验证:');
|
||
|
|
console.log(`- 项目总数: ${projectsList.length}`);
|
||
|
|
console.log(`- 包含overview字段的项目: ${projectsList.filter(p => p.overview).length}`);
|
||
|
|
console.log(`- 包含positions的项目: ${projectsList.filter(p => p.positions && p.positions.length > 0).length}`);
|
||
|
|
console.log(`- 包含process的项目: ${projectsList.filter(p => p.process).length}`);
|
||
|
|
console.log(`- 包含keyPoints的项目: ${projectsList.filter(p => p.keyPoints).length}`);
|
||
|
|
};
|
||
|
|
|
||
|
|
validateData();
|