import { useState, useEffect } from "react"; import { Radio } from "@arco-design/web-react"; import Modal from "@/components/Modal"; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import "./index.css"; export default ({ visible, onClose, data, initialVersion = "2" }) => { const [version, setVersion] = useState(initialVersion); // 使用传入的初始版本 // 响应initialVersion变化 useEffect(() => { setVersion(initialVersion); }, [initialVersion]); const onRadioChange = (value, e) => { e?.stopPropagation(); setVersion(value); }; const handleCloseModal = () => { onClose(); }; // 判断是否应该使用markdown渲染(有真实修改版的岗位) const shouldUseMarkdown = (positionTitle) => { const markdownPositions = [ "会展策划师", "会展讲解员", "活动执行", "活动策划师", "漫展策划师", "会展执行助理", "旅游规划师", "旅游计调专员", "景区运营专员", "文旅运营总监助理" ]; return markdownPositions.includes(positionTitle); }; // Markdown解析器 - 解析简历内容 const parseResumeMarkdown = (markdownContent) => { if (!markdownContent || typeof markdownContent !== 'string') { return null; } const result = { personalInfo: { name: "岗位名称" }, education: [{ school: '苏州信息职业技术学院', major: '旅游管理', period: '2020.9-2023.6' }], projects: [], skills: { core: [], additional: [] }, personalSummary: [] }; // 提取岗位名称 const positionMatch = markdownContent.match(/# 对应岗位:(.+)/); if (positionMatch) { result.personalInfo.name = positionMatch[1].trim(); } // 提取项目经历 const projectSectionMatch = markdownContent.match(/# 一、项目经历\s+([\s\S]*?)(?=# 二、专业技能|$)/); if (projectSectionMatch) { const projectContent = projectSectionMatch[1]; // 提取项目名称 const projectNameMatch = projectContent.match(/### (一)项目名称:(.+)/); const roleMatch = projectContent.match(/### (二)实习岗位:(.+)/); const timeMatch = projectContent.match(/### (三)实习时间:(.+)/); const companyMatch = projectContent.match(/### (四)实习单位:(.+)/); // 提取岗位职责内容 - 从"### (五)岗位职责:"开始到下一个section const responsibilityMatch = projectContent.match(/### (五)岗位职责:\s+([\s\S]*?)$/); if (projectNameMatch) { result.projects = [{ name: projectNameMatch[1].trim(), role: roleMatch ? roleMatch[1].trim() : "参与者", period: timeMatch ? timeMatch[1].trim() : "", company: companyMatch ? companyMatch[1].trim() : "", description: responsibilityMatch ? responsibilityMatch[1].trim() : "" }]; } } // 提取专业技能 const skillsSectionMatch = markdownContent.match(/# 二、专业技能\s+([\s\S]*?)$/); if (skillsSectionMatch) { const skillsContent = skillsSectionMatch[1]; // 提取核心能力 const coreSkillsMatch = skillsContent.match(/### (一)核心能力\s+([\s\S]*?)(?=### (二)复合能力|$)/); if (coreSkillsMatch) { const coreSkills = coreSkillsMatch[1] .split(/\d+\.\s+/) .filter(skill => skill.trim()) .map(skill => skill.trim().replace(/;\s*$/, '')); result.skills.core = coreSkills; } // 提取复合能力 const additionalSkillsMatch = skillsContent.match(/### (二)复合能力\s+([\s\S]*?)$/); if (additionalSkillsMatch) { const additionalSkills = additionalSkillsMatch[1] .split(/\d+\.\s+/) .filter(skill => skill.trim()) .map(skill => skill.trim().replace(/。\s*$/, '')); result.skills.additional = additionalSkills; } } return result; }; // 渲染markdown分块内容 const renderMarkdownSections = (markdownContent) => { if (!markdownContent) return null; const sections = []; // 首先添加教育经历板块 sections.push(
  • 教育经历

  • ); // 按H1标题分割markdown内容(# 开头的行) const markdownSections = markdownContent.split(/^# /gm).filter(section => section.trim()); // 添加markdown渲染的section markdownSections.forEach((section, index) => { // 为每个section添加回# 前缀(除了第一个如果不是以#开头) const fullSection = section.startsWith('#') ? section : `# ${section}`; // 过滤掉"对应岗位"板块 if (fullSection.includes('对应岗位:') || fullSection.includes('对应岗位:')) { return; } sections.push(
  • , h2: ({node, ...props}) =>

    , h3: ({node, ...props}) =>

    , // 段落样式 p: ({node, ...props}) =>

    , // 列表样式 ol: ({node, ...props}) =>

      , ul: ({node, ...props}) =>
        , li: ({node, ...props}) =>
      • , // 加粗和删除线样式 strong: ({node, ...props}) => , del: ({node, ...props}) => }} > {fullSection}
      • ); }); return sections; }; // 获取简历数据 - 支持新的数据结构 let resumeContent = {}; if (data?.content) { // 新的数据结构 - 来自resume-interview页面 if (data.content.original && data.content.modified) { const selectedContent = version === "1" ? data.content.original : data.content.modified; // 如果是markdown格式的字符串,使用解析器 if (typeof selectedContent === 'string') { resumeContent = parseResumeMarkdown(selectedContent); } else if (selectedContent.personalInfo) { // 如果已经是结构化数据 resumeContent = selectedContent; } } else if (data.content.personalInfo) { // 兼容旧的数据结构(单一版本) resumeContent = data.content; } else if (typeof data.content === 'string') { // 如果content直接是markdown字符串 resumeContent = parseResumeMarkdown(data.content); } } else { // 旧的数据结构 - 兼容现有的company jobs页面 const currentTemplate = data?.selectedTemplate; const studentInfo = currentTemplate?.studentInfo; // 检查是否是来自resume-interview页面的数据 (有content和personal_summary字段) if (currentTemplate && currentTemplate.content && currentTemplate.position) { // 来自resume-interview页面的新数据结构 const parsedContent = parseResumeMarkdown(currentTemplate.content); if (parsedContent) { resumeContent = parsedContent; // 添加个人总结 - 检查多个可能的位置 if (currentTemplate.personal_summary) { resumeContent.personalSummary = [currentTemplate.personal_summary]; } else if (currentTemplate.studentInfo?.personalSummary) { resumeContent.personalSummary = [currentTemplate.studentInfo.personalSummary]; } else if (currentTemplate.studentInfo?.personal_summary) { resumeContent.personalSummary = [currentTemplate.studentInfo.personal_summary]; } // 更新岗位名称 resumeContent.personalInfo.name = currentTemplate.position; } } else if (studentInfo) { // 构造兼容格式 resumeContent = { personalInfo: { name: currentTemplate?.position || "岗位名称" }, education: [{ school: studentInfo.education?.university || '苏州信息职业技术学院', major: '旅游管理', period: studentInfo.education?.period || '2020.9-2023.6' }], projects: [], skills: { core: [], additional: [] }, personalSummary: [studentInfo.personalSummary || studentInfo.personal_summary || "具有扎实的专业基础和实践经验"] }; // 处理项目经历 if (studentInfo.projectExperience) { resumeContent.projects = [{ name: "项目经历", role: "参与者", period: "", description: studentInfo.projectExperience }]; } else if (studentInfo.project_experience) { if (Array.isArray(studentInfo.project_experience)) { resumeContent.projects = studentInfo.project_experience.map(proj => ({ name: proj.name || "实习项目", role: proj.role || "参与者", period: proj.period || "", description: proj.description || "参与项目实施" })); } else if (typeof studentInfo.project_experience === 'object') { const proj = studentInfo.project_experience; resumeContent.projects = [{ name: proj.project_name || proj.position || "实习项目", role: proj.role || "参与者", period: proj.period || "", description: proj.description || "参与项目实施" }]; } } // 处理专业技能 if (studentInfo.skills) { // 新格式:skills是字符串,转换为数组 const skillsArray = studentInfo.skills.split('\n').filter(s => s.trim()); const midPoint = Math.ceil(skillsArray.length / 2); resumeContent.skills = { core: skillsArray.slice(0, midPoint), additional: skillsArray.slice(midPoint) }; } else { resumeContent.skills = { core: studentInfo.core_skills || [], additional: studentInfo.compound_skills || [] }; } } } // 数据校验:确保必要字段存在 const isValidData = resumeContent && Object.keys(resumeContent).length > 0 && resumeContent.personalInfo; // 调试日志 (可以移除) // console.log('ResumeInfoModal Debug:', { data, resumeContent }); // 如果数据无效,提供默认值防止渲染异常 if (!isValidData) { console.warn('ResumeInfoModal: Invalid resume data received', { data, resumeContent }); resumeContent = { personalInfo: { name: '数据加载中...' }, education: [], projects: [], skills: { core: [], additional: [] } }; } return ( <>
        e.stopPropagation()}> {data?.content?.original && data?.content?.modified && (
        e.stopPropagation()} > 原始版 个人修改版
        )}

        {data?.title || resumeContent.personalInfo?.name || "职位名称"}

        {/* 判断是否使用markdown渲染 */} {data && shouldUseMarkdown(data?.title) && data?.content?.original && data?.content?.modified ? (
          {renderMarkdownSections(version === "1" ? data.content.original : data.content.modified)}
        ) : (
          {/* 教育经历 */}
        • 教育经历

            {resumeContent.education?.map((edu, index) => (
          • {edu.school} - {edu.major}

            {edu.period}

          • ))}
        • {/* 项目经历 */}
        • 项目经历

            {resumeContent.projects?.map((project, index) => (
          • {project.name}

            {project.company && `${project.company} - `}角色:{project.role}

            {project.period}

            {project.description}

            {project.highlights && (

              主要成果

              {project.highlights.map((highlight, idx) => (
            • {highlight}
            • ))}
            )}
          • ))}
        • {/* 专业技能 */}
        • 专业技能

            {resumeContent.skills?.core && (
          • 核心能力

            {resumeContent.skills.core.map((skill, index) => (

            {index + 1}. {skill}

            ))}
          • )} {resumeContent.skills?.additional && (
          • 复合技能

            {resumeContent.skills.additional.map((skill, index) => (

            {index + 1}. {skill}

            ))}
          • )}
        • {/* 个人总结 */} {(resumeContent.personalSummary && resumeContent.personalSummary.length > 0) || (resumeContent.personalSummary && typeof resumeContent.personalSummary === 'string') ? (
        • 个人总结

          {Array.isArray(resumeContent.personalSummary) ? (
            {resumeContent.personalSummary.map((summary, index) => (
          • {summary}
          • ))}
          ) : (

          {resumeContent.personalSummary}

          )}
        • ) : null} {/* 对应课程单元 - 暂时保留静态展示,后续可根据需要动态化 */} {resumeContent.courses && (
        • 对应课程单元

          • 相关课程
              {resumeContent.courses.map((course, index) => (
            • {course}
            • ))}
        • )}
        )}
        ); };