import { useState, useEffect } from 'react' import { getRecommendJobs } from '../api' import JobCard from '../components/JobCard' const PAGE_SIZE = 10 function RecommendPage({ resumeData, onSelectJob, onBack, onGoHome }) { const [status, setStatus] = useState('loading') const [jobs, setJobs] = useState([]) const [page, setPage] = useState(0) const [errorMsg, setErrorMsg] = useState('') const isBrowsing = !resumeData const fetchJobs = async () => { setStatus('loading') try { const resumeId = resumeData?.id || 1 const res = await getRecommendJobs(resumeId) const list = res.data?.jobs || [] setJobs(list) setPage(0) setStatus(list.length === 0 ? 'empty' : 'success') } catch { setStatus('error') setErrorMsg('加载失败,请重试') } } useEffect(() => { fetchJobs() }, []) const totalPages = Math.ceil(jobs.length / PAGE_SIZE) const pageJobs = jobs.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE) if (status === 'loading') { return (

加载推荐岗位中...

) } if (status === 'error') { return (

{errorMsg}

) } if (status === 'empty') { return (

暂无可推荐岗位,请完善简历后重试

) } return (

推荐岗位

共 {jobs.length} 个岗位
{pageJobs.map((job) => ( onSelectJob(jobId, jobData || job)} lowMatchWarning={(job.match_rate || 0) < 40} showMatch={!isBrowsing} onUploadClick={isBrowsing ? onGoHome : undefined} /> ))}
{totalPages > 1 && (
{page + 1} / {totalPages}
)}
) } export default RecommendPage