预约面试功能开发
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:
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import { useParams, history, useLocation } from '@umijs/max';
|
||||
import { useParams, history, useLocation, useSearchParams } from '@umijs/max';
|
||||
import {
|
||||
Card,
|
||||
Typography,
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
getEmptyCompetitivenessRadar,
|
||||
} from '@/services/jobportal/competitiveness';
|
||||
import { isJobPortalLoggedIn } from '@/utils/jobPortalAuth';
|
||||
import { favoriteJob, unfavoriteJob, applyJob, browseJob } from '@/services/jobportal/user';
|
||||
import { favoriteJob, unfavoriteJob, applyJob, browseJob, getJobDetail } from '@/services/jobportal/user';
|
||||
import { ensureJobPortalLogin, requireJobPortalUserId } from '@/utils/jobPortalAuth';
|
||||
import { getDictLabel, resolveIndustryLabel } from '@/utils/jobPortalDict';
|
||||
import { getDictValueEnum } from '@/services/system/dict';
|
||||
@@ -174,6 +174,7 @@ const mockJobDetail = {
|
||||
const JobDetailPage: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const location = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const [jobDetail, setJobDetail] = useState(mockJobDetail);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isFavorited, setIsFavorited] = useState(false);
|
||||
@@ -236,18 +237,44 @@ const JobDetailPage: React.FC = () => {
|
||||
const transformedJobData = transformJobData(passedJobData);
|
||||
setJobDetail(transformedJobData);
|
||||
// 根据 isCollection 字段设置收藏状态
|
||||
// isCollection 为 null 或 0 表示未收藏,其他值表示已收藏
|
||||
setIsFavorited(passedJobData?.isCollection !== null && passedJobData?.isCollection !== 0 && passedJobData?.isCollection !== undefined);
|
||||
} else {
|
||||
// 如果没有传递数据,则根据id从API获取数据
|
||||
// fetchJobDetail(id);
|
||||
// 默认未收藏
|
||||
setOriginalJobData(null);
|
||||
setIsFavorited(false);
|
||||
// 直接刷新页面时,从 URL 参数或 route param 获取 jobId,调 API 获取数据
|
||||
const jobIdFromUrl = searchParams.get('jobId');
|
||||
if (jobIdFromUrl) {
|
||||
fetchJobDetailFromApi(jobIdFromUrl);
|
||||
} else {
|
||||
setOriginalJobData(null);
|
||||
setIsFavorited(false);
|
||||
}
|
||||
}
|
||||
|
||||
}, [id, location.state]);
|
||||
|
||||
// 页面直接刷新时调接口获取岗位详情
|
||||
const fetchJobDetailFromApi = async (jobId: string) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const res = await getJobDetail(jobId);
|
||||
if (res?.code === 200 && res?.data) {
|
||||
const jobData = res.data;
|
||||
setOriginalJobData(jobData);
|
||||
const transformed = transformJobData(jobData);
|
||||
setJobDetail(transformed);
|
||||
setIsFavorited(jobData?.isCollection !== null && jobData?.isCollection !== 0 && jobData?.isCollection !== undefined);
|
||||
} else {
|
||||
setOriginalJobData(null);
|
||||
setIsFavorited(false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取岗位详情失败:', error);
|
||||
setOriginalJobData(null);
|
||||
setIsFavorited(false);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 仅登录且有真实岗位 id 时请求竞争力
|
||||
useEffect(() => {
|
||||
if (!isJobPortalLoggedIn()) {
|
||||
|
||||
Reference in New Issue
Block a user