Files
online_sys/frontend_财经商贸/replaceProjectLibraryData.js

151 lines
4.6 KiB
JavaScript
Raw Normal View History

const fs = require('fs');
const path = require('path');
// Read finance commerce projects data
const financeProjects = JSON.parse(
fs.readFileSync('网页未导入数据/财经商贸产业/财经商贸项目案例.json', 'utf8')
);
// Transform finance projects to match the exact structure of manufacturing projects
const transformedProjects = financeProjects.map((project, index) => ({
id: index + 1,
name: project['案例名称'],
description: project['所属垂直方向'],
positions: project['对应个人简历名称'].split(',').map(p => p.trim()),
unit: project['对应单元名称(垂直能力课)'] || project['对应单元名称(复合能力课)'],
direction: project['所属垂直方向'],
category: getCategoryFromDirection(project['所属垂直方向'])
}));
// Helper function to map direction to category
function getCategoryFromDirection(direction) {
const categoryMap = {
'国际贸易': '国际贸易',
'供应链管理': '供应链管理',
'电子商务': '电子商务'
};
return categoryMap[direction] || direction;
}
// Generate the complete mock file content
const mockFileContent = `// 项目库Mock数据
export const getMockProjectsList = (params = {}) => {
const { search = "", page = 1, pageSize = 10 } = params;
// 完整项目列表数据
const projects = ${JSON.stringify(transformedProjects, null, 4)};
// 搜索过滤
let filteredProjects = projects;
if (search) {
filteredProjects = projects.filter(project =>
project.name.includes(search) ||
project.description.includes(search) ||
project.positions.some(pos => pos.includes(search)) ||
project.category.includes(search)
);
}
// 分页
const start = (page - 1) * pageSize;
const end = start + pageSize;
const paginatedProjects = filteredProjects.slice(start, end);
return {
success: true,
data: paginatedProjects,
total: filteredProjects.length,
page,
pageSize
};
};
// 项目详情Mock数据 - 财经商贸
export const getMockProjectDetail = (id) => {
const projects = ${JSON.stringify(transformedProjects, null, 4)};
const project = projects.find(p => p.id === parseInt(id));
if (!project) {
return {
success: false,
message: '项目不存在'
};
}
// 查找原始项目数据以获取详细内容
const financeProjectsData = ${JSON.stringify(financeProjects, null, 4)};
const originalProject = financeProjectsData[project.id - 1];
// 处理项目内容
let sections = [];
if (originalProject && originalProject['项目案例内容']) {
// 将Markdown内容转换为sections
const content = originalProject['项目案例内容'];
const lines = content.split('\\n');
let currentSection = null;
let currentContent = [];
lines.forEach(line => {
if (line.startsWith('# ') || line.startsWith('## ')) {
if (currentSection) {
sections.push({
title: currentSection,
content: currentContent.join('\\n').trim()
});
}
currentSection = line.replace(/^#+\\s*/, '').trim();
currentContent = [];
} else {
currentContent.push(line);
}
});
if (currentSection) {
sections.push({
title: currentSection,
content: currentContent.join('\\n').trim()
});
}
}
return {
success: true,
data: {
id: project.id,
title: project.name,
description: project.description || '',
images: [],
sections: sections.length > 0 ? sections : [
{
title: "项目概述",
content: project.name
}
]
}
};
};
`;
// Backup existing file
const timestamp = Date.now();
const backupPath = `src/mocks/projectLibraryMock.js.backup_${timestamp}`;
fs.copyFileSync('src/mocks/projectLibraryMock.js', backupPath);
console.log(`✅ Created backup at: ${backupPath}`);
// Write the new mock file
fs.writeFileSync('src/mocks/projectLibraryMock.js', mockFileContent);
console.log('✅ Successfully replaced projectLibraryMock.js with finance/commerce data');
// Update categories in ProjectLibraryPage/index.jsx
const indexPath = 'src/pages/ProjectLibraryPage/index.jsx';
const indexContent = fs.readFileSync(indexPath, 'utf8');
// Get unique categories and directions
const uniqueDirections = [...new Set(financeProjects.map(p => p['所属垂直方向']))];
const categories = ['全部', ...uniqueDirections];
console.log('📋 Categories to update:', categories);
console.log('✅ Project library data replacement complete!');
console.log(`📊 Total projects: ${transformedProjects.length}`);
console.log(`📁 Backup saved at: ${backupPath}`);