搜索功能bug修复
Some checks failed
Node CI / build (14.x, macOS-latest) (push) Has been cancelled
Node CI / build (14.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (14.x, windows-latest) (push) Has been cancelled
Node CI / build (16.x, macOS-latest) (push) Has been cancelled
Node CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (16.x, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
coverage CI / build (push) Has been cancelled
Node pnpm CI / build (16.x, macOS-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, windows-latest) (push) Has been cancelled

This commit is contained in:
冯辉
2026-06-28 16:34:03 +08:00
parent 4df17de061
commit ead4a0567b

View File

@@ -24,7 +24,7 @@ import {
TrophyOutlined TrophyOutlined
} from '@ant-design/icons'; } from '@ant-design/icons';
import { history, useLocation } from '@umijs/max'; import { history, useLocation } from '@umijs/max';
import { getJobList } from '@/services/common/jobTitle'; import { getJobList, getJobRecommend } from '@/services/common/jobTitle';
import JobPortalHeader from '@/components/JobPortalHeader'; import JobPortalHeader from '@/components/JobPortalHeader';
import { favoriteJob, unfavoriteJob, applyJob, browseJob } from '@/services/jobportal/user'; import { favoriteJob, unfavoriteJob, applyJob, browseJob } from '@/services/jobportal/user';
import { ensureJobPortalLogin, requireJobPortalUserId } from '@/utils/jobPortalAuth'; import { ensureJobPortalLogin, requireJobPortalUserId } from '@/utils/jobPortalAuth';
@@ -523,31 +523,34 @@ const JobListPage: React.FC = () => {
} }
}; };
// 处理搜索功能 // 处理搜索功能(服务端搜索,不再做客户端过滤)
const handleSearch = () => { const handleSearch = async () => {
if (searchValue.trim()) { const term = searchValue.trim();
// 过滤职位列表 if (term) {
const filtered = jobList.filter((job) => { try {
const jobTitle = job.jobTitle || job.title || ''; setLoading(true);
const companyName = job.companyName || job.company || ''; const response = await getJobRecommend({ jobTitle: term });
const searchTerm = searchValue.toLowerCase(); if (response?.code === 200 && response?.data) {
setFilteredJobList(response.data);
return ( setSelectedJob(response.data.length > 0 ? response.data[0] : null);
jobTitle.toLowerCase().includes(searchTerm) || if (response.data.length === 0) {
companyName.toLowerCase().includes(searchTerm) message.warning('未找到相关职位');
); } else {
}); message.success(`找到 ${response.data.length} 个相关职位`);
}
setFilteredJobList(filtered); } else {
setSelectedJob(filtered.length > 0 ? filtered[0] : null); message.warning('未找到相关职位');
setFilteredJobList([]);
if (filtered.length === 0) { setSelectedJob(null);
message.warning('未找到相关职位'); }
} else { } catch (error) {
message.success(`找到 ${filtered.length} 个相关职位`); console.error('搜索职位失败:', error);
message.error('搜索职位失败,请重试');
} finally {
setLoading(false);
} }
} else { } else {
// 如果搜索框为空,显示所有职位 // 如果搜索框为空,恢复为当前分类的完整列表
setFilteredJobList(jobList); setFilteredJobList(jobList);
setSelectedJob(jobList.length > 0 ? jobList[0] : null); setSelectedJob(jobList.length > 0 ? jobList[0] : null);
} }