111 lines
3.7 KiB
JavaScript
111 lines
3.7 KiB
JavaScript
|
|
import fs from 'fs';
|
||
|
|
|
||
|
|
// 简单的修复方案:直接替换整个 mockData.js 文件中有问题的部分
|
||
|
|
let content = fs.readFileSync('src/data/mockData.js', 'utf-8');
|
||
|
|
|
||
|
|
// 查找 transformInterviewStatus 函数的位置,并用一个简单的版本替换
|
||
|
|
const newFunction = `// 转换面试状态数据
|
||
|
|
const transformInterviewStatus = (statusData, jobsData) => {
|
||
|
|
if (!Array.isArray(statusData)) {
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
|
||
|
|
return statusData.map((status, index) => {
|
||
|
|
const matchedJob = jobsData.find(job =>
|
||
|
|
job["内推岗位名称"] === (status["岗位名称"] || status["查询岗位名称"])
|
||
|
|
);
|
||
|
|
|
||
|
|
const dateString = status["投递时间"] || status["阶段日期"] || "2024-01-01";
|
||
|
|
let formattedDate = dateString;
|
||
|
|
let interviewDate = new Date();
|
||
|
|
|
||
|
|
if (dateString.includes('-')) {
|
||
|
|
interviewDate = new Date(dateString);
|
||
|
|
}
|
||
|
|
|
||
|
|
let statusCode = 'PENDING';
|
||
|
|
const statusText = status["面试状态"] || "已投递";
|
||
|
|
|
||
|
|
if (statusText.includes("通过") || statusText.includes("Offer")) {
|
||
|
|
statusCode = 'OFFER';
|
||
|
|
} else if (statusText.includes("未通过") || statusText.includes("失败")) {
|
||
|
|
statusCode = 'FAILED';
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
id: index + 1,
|
||
|
|
position: status["岗位名称"] || status["查询岗位名称"] || "未知岗位",
|
||
|
|
interviewTime: formattedDate,
|
||
|
|
interviewDate: interviewDate,
|
||
|
|
status: statusCode,
|
||
|
|
statusText: statusText,
|
||
|
|
progress: status["面试进度"] || 25,
|
||
|
|
nextStep: status["下一步"] || "等待回复",
|
||
|
|
job: matchedJob ? {
|
||
|
|
salary: matchedJob["薪资"] || "面议",
|
||
|
|
tags: matchedJob["职位标签"] || [],
|
||
|
|
location: matchedJob["工作地点"] || "未知",
|
||
|
|
education: matchedJob["学历要求"] || "不限",
|
||
|
|
companyInfo: matchedJob["公司介绍"] || "",
|
||
|
|
jobCategory: matchedJob["岗位相关标签"] || "专业相关岗位",
|
||
|
|
remainingPositions: 5,
|
||
|
|
description: matchedJob["职位描述"] || "",
|
||
|
|
requirements: matchedJob["任职要求"] || ""
|
||
|
|
} : null
|
||
|
|
};
|
||
|
|
}).filter(item => item !== null);
|
||
|
|
};`;
|
||
|
|
|
||
|
|
// 找到函数并替换
|
||
|
|
const functionPattern = /\/\/ 转换面试状态数据[\s\S]*?const transformInterviewStatus[\s\S]*?\};/;
|
||
|
|
|
||
|
|
if (content.match(functionPattern)) {
|
||
|
|
// 备份
|
||
|
|
fs.copyFileSync('src/data/mockData.js', `src/data/mockData.js.backup_${Date.now()}`);
|
||
|
|
|
||
|
|
// 替换
|
||
|
|
content = content.replace(functionPattern, newFunction);
|
||
|
|
|
||
|
|
// 保存
|
||
|
|
fs.writeFileSync('src/data/mockData.js', content, 'utf-8');
|
||
|
|
console.log('修复完成!');
|
||
|
|
} else {
|
||
|
|
console.log('未找到函数,尝试手动修复...');
|
||
|
|
|
||
|
|
// 手动查找并替换
|
||
|
|
const lines = content.split('\n');
|
||
|
|
let startIndex = -1;
|
||
|
|
let endIndex = -1;
|
||
|
|
|
||
|
|
for (let i = 0; i < lines.length; i++) {
|
||
|
|
if (lines[i].includes('transformInterviewStatus')) {
|
||
|
|
startIndex = i;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (startIndex !== -1) {
|
||
|
|
let braceCount = 0;
|
||
|
|
for (let i = startIndex; i < lines.length; i++) {
|
||
|
|
const line = lines[i];
|
||
|
|
braceCount += (line.match(/\{/g) || []).length;
|
||
|
|
braceCount -= (line.match(/\}/g) || []).length;
|
||
|
|
|
||
|
|
if (braceCount === 0 && line.includes('}')) {
|
||
|
|
endIndex = i;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (endIndex !== -1) {
|
||
|
|
// 替换函数
|
||
|
|
const beforeLines = lines.slice(0, startIndex);
|
||
|
|
const afterLines = lines.slice(endIndex + 1);
|
||
|
|
const newLines = [...beforeLines, ...newFunction.split('\n'), ...afterLines];
|
||
|
|
|
||
|
|
fs.copyFileSync('src/data/mockData.js', `src/data/mockData.js.backup_${Date.now()}`);
|
||
|
|
fs.writeFileSync('src/data/mockData.js', newLines.join('\n'), 'utf-8');
|
||
|
|
console.log('手动修复完成!');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|