Files
ALL-teach_sys/frontend_食品/src/utils/interviewQuestionMapper.js

79 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

import interviewQuestionsData from '@/data/interviewQuestions.json';
// 创建岗位群名称到面试题内容的映射
const createInterviewQuestionsMap = () => {
const map = {};
interviewQuestionsData.forEach(item => {
// 根据岗位群名称创建映射
map[item['岗位群名称']] = {
groupName: item['岗位群名称'],
questionTitle: item['面试题名称'],
content: item['面试题内容']
};
});
return map;
};
// 导出映射
export const interviewQuestionsMap = createInterviewQuestionsMap();
// 根据岗位群名称获取面试题内容
export const getInterviewQuestionsByGroup = (groupName) => {
return interviewQuestionsMap[groupName] || null;
};
// 将Markdown格式的内容解析为结构化数据用于简单展示
export const parseInterviewContent = (content) => {
if (!content) return [];
const sections = [];
const lines = content.split('\n');
let currentSection = null;
let currentQuestion = null;
lines.forEach(line => {
// 匹配一级标题(章节)
if (line.startsWith('# ')) {
if (currentSection) {
sections.push(currentSection);
}
currentSection = {
title: line.replace('# ', '').trim(),
questions: []
};
currentQuestion = null;
}
// 匹配问题(数字开头)
else if (/^\d+\.\s/.test(line)) {
if (currentQuestion && currentSection) {
currentSection.questions.push(currentQuestion);
}
currentQuestion = {
question: line.replace(/^\d+\.\s/, '').trim(),
answer: ''
};
}
// 匹配答案或示例回答
else if (line.includes('答案:') || line.includes('示例回答:') || line.includes('参考答案:')) {
if (currentQuestion) {
currentQuestion.answer = line.replace(/^(答案:|示例回答:|参考答案:)/, '').trim();
}
}
// 继续收集答案内容
else if (currentQuestion && currentQuestion.answer && line.trim()) {
currentQuestion.answer += '\n' + line.trim();
}
});
// 添加最后的section和question
if (currentQuestion && currentSection) {
currentSection.questions.push(currentQuestion);
}
if (currentSection) {
sections.push(currentSection);
}
return sections;
};