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