diff --git a/src/pages/JobPortal/Detail/index.tsx b/src/pages/JobPortal/Detail/index.tsx index 4c4fe90..249b874 100644 --- a/src/pages/JobPortal/Detail/index.tsx +++ b/src/pages/JobPortal/Detail/index.tsx @@ -34,7 +34,7 @@ import { import { isJobPortalLoggedIn } from '@/utils/jobPortalAuth'; import { favoriteJob, unfavoriteJob, applyJob } from '@/services/jobportal/user'; import { ensureJobPortalLogin, PORTAL_LOGIN_URL } from '@/utils/jobPortalAuth'; -import { getDictLabel, findTreeLabelById } from '@/utils/jobPortalDict'; +import { getDictLabel, resolveIndustryLabel } from '@/utils/jobPortalDict'; import { getDictValueEnum } from '@/services/system/dict'; import { getCmsIndustryTreeList } from '@/services/classify/industry'; import type { DictValueEnumObj } from '@/components/DictTag'; @@ -113,9 +113,9 @@ const transformJobData = (jobData: any) => {

3. 具备良好的团队协作能力;

`, companyInfo: { - name: jobData.companyName || jobData.company || jobData.companyVo?.name, - scale: jobData.companyVo?.scale ?? jobData.scale ?? '', - industry: jobData.companyVo?.industry ?? jobData.industry ?? '', + name: jobData.companyName || jobData.companyVo?.name || jobData.company, + scale: jobData.scale ?? '', + industry: jobData.industry ?? '', description: jobData.companyVo?.companyDescription || jobData.companyDescription @@ -217,20 +217,22 @@ const JobDetailPage: React.FC = () => { }, []); const companyMetaItems = useMemo(() => { - const company = originalJobData?.companyVo || {}; - const rawScale = company.scale ?? originalJobData?.scale ?? jobDetail.companyInfo?.scale; - const rawIndustry = - company.industry ?? originalJobData?.industry ?? jobDetail.companyInfo?.industry; + if (!originalJobData) { + return []; + } + const rawScale = originalJobData.scale; + const rawIndustry = originalJobData.industry; const items: string[] = []; - const scaleLabel = getDictLabel(scaleEnum, rawScale) || rawScale; - const industryLabel = findTreeLabelById(industryTree, rawIndustry) || rawIndustry; - - if (scaleLabel) items.push(scaleLabel); + if (rawScale != null && rawScale !== '') { + const scaleLabel = getDictLabel(scaleEnum, rawScale) || String(rawScale); + if (scaleLabel) items.push(scaleLabel); + } + const industryLabel = resolveIndustryLabel(industryTree, rawIndustry); if (industryLabel) items.push(industryLabel); return items; - }, [originalJobData, jobDetail.companyInfo, scaleEnum, industryTree]); + }, [originalJobData, scaleEnum, industryTree]); useEffect(() => { // 首先尝试从传递的数据中获取职位信息 diff --git a/src/pages/JobPortal/List/index.tsx b/src/pages/JobPortal/List/index.tsx index 48c9cbe..dcdf056 100644 --- a/src/pages/JobPortal/List/index.tsx +++ b/src/pages/JobPortal/List/index.tsx @@ -29,7 +29,7 @@ import { getDictValueEnum } from '@/services/system/dict'; import JobPortalHeader from '@/components/JobPortalHeader'; import { favoriteJob, unfavoriteJob, applyJob } from '@/services/jobportal/user'; import { ensureJobPortalLogin, PORTAL_LOGIN_URL } from '@/utils/jobPortalAuth'; -import { getDictLabel, findTreeLabelById } from '@/utils/jobPortalDict'; +import { getDictLabel, findTreeLabelById, resolveIndustryLabel } from '@/utils/jobPortalDict'; import { getJobTitleTreeSelect } from '@/services/common/jobTitle'; import { getCmsIndustryTreeList } from '@/services/classify/industry'; import type { DictValueEnumObj } from '@/components/DictTag'; @@ -256,15 +256,15 @@ const JobListPage: React.FC = () => { const selectedCompanyMetaItems = useMemo(() => { if (!selectedJob) return []; - const company = selectedJob.companyVo || {}; - const rawScale = company.scale ?? selectedJob.scale; - const rawIndustry = company.industry ?? selectedJob.industry; + const rawScale = selectedJob.scale; + const rawIndustry = selectedJob.industry; const items: string[] = []; - const scaleLabel = getDictLabel(scaleEnum, rawScale) || rawScale; - const industryLabel = findTreeLabelById(industryTree, rawIndustry) || rawIndustry; - - if (scaleLabel) items.push(scaleLabel); + if (rawScale != null && rawScale !== '') { + const scaleLabel = getDictLabel(scaleEnum, rawScale) || String(rawScale); + if (scaleLabel) items.push(scaleLabel); + } + const industryLabel = resolveIndustryLabel(industryTree, rawIndustry); if (industryLabel) items.push(industryLabel); return items; }, [selectedJob, scaleEnum, industryTree]); diff --git a/src/utils/jobPortalDict.ts b/src/utils/jobPortalDict.ts index 3df68d2..7569f44 100644 --- a/src/utils/jobPortalDict.ts +++ b/src/utils/jobPortalDict.ts @@ -60,5 +60,18 @@ export function findTreeLabelById( return ''; } +/** 所属行业:数字 id 走行业树,已是文案则直接展示 */ +export function resolveIndustryLabel( + tree: any[] | undefined, + value?: string | number | null, +): string { + const str = value == null ? '' : String(value).trim(); + if (!str) return ''; + if (/^\d+$/.test(str)) { + return findTreeLabelById(tree, str) || str; + } + return str; +} + /** @deprecated 使用 findTreeLabelById */ export const findIndustryLabelInTree = findTreeLabelById;