From 1863cd8f62be61f3298261ffb247ad74e6ff84fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E8=BE=89?= <13935151924@163.com> Date: Thu, 13 Nov 2025 12:23:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=BD=8D=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=8F=91=E5=B8=83=E6=97=B6=E9=97=B4=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageA/pages/UnitDetails/UnitDetails.vue | 37 ++++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/packageA/pages/UnitDetails/UnitDetails.vue b/packageA/pages/UnitDetails/UnitDetails.vue index 2198201..138d967 100644 --- a/packageA/pages/UnitDetails/UnitDetails.vue +++ b/packageA/pages/UnitDetails/UnitDetails.vue @@ -48,15 +48,12 @@ - {{ getExperienceLabel(job.experience) }} - {{ getEducationLabel(job.education) }} - 招聘{{ job.vacancies }}人 @@ -66,8 +63,7 @@ {{ job.jobLocation }} - - {{ job.postingDate.split(' ')[0] }} + {{ formatPublishTime(job.postingDate) }} @@ -323,7 +319,7 @@ } } - // 格式化发布时间 + // 格式化发布时间为相对时间 function formatPublishTime(publishTime) { if (!publishTime) return ''; @@ -331,17 +327,30 @@ const date = new Date(publishTime); const now = new Date(); const diffTime = Math.abs(now - date); - const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); + const diffSeconds = Math.floor(diffTime / 1000); + const diffMinutes = Math.floor(diffSeconds / 60); + const diffHours = Math.floor(diffMinutes / 60); + const diffDays = Math.floor(diffHours / 24); + const diffWeeks = Math.floor(diffDays / 7); + const diffMonths = Math.floor(diffDays / 30); + const diffYears = Math.floor(diffDays / 365); - if (diffDays === 1) { - return '今天发布'; - } else if (diffDays <= 7) { + if (diffSeconds < 60) { + return '刚刚发布'; + } else if (diffMinutes < 60) { + return `${diffMinutes}分钟前发布`; + } else if (diffHours < 24) { + return `${diffHours}小时前发布`; + } else if (diffDays === 1) { + return '昨天发布'; + } else if (diffDays < 7) { return `${diffDays}天前发布`; + } else if (diffWeeks < 4) { + return `${diffWeeks}周前发布`; + } else if (diffMonths < 12) { + return `${diffMonths}个月前发布`; } else { - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - return `${year}-${month}-${day}发布`; + return `${diffYears}年前发布`; } } catch (error) { console.error('格式化发布时间失败:', error);