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);