H5端首页显示内容修改

This commit is contained in:
冯辉
2025-11-18 10:57:59 +08:00
parent 7ee291158e
commit 5c7bd3a6bc
5 changed files with 40 additions and 30 deletions

View File

@@ -443,6 +443,32 @@ function getClass(index) {
return '';
}
}
// 格式化发布时间
function formatPublishTime(dateString) {
if (!dateString) return '';
const date = new Date(dateString);
const now = new Date();
const diffTime = Math.abs(now - date);
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
if (diffDays === 0) {
return '今天发布';
} else if (diffDays === 1) {
return '昨天发布';
} else if (diffDays < 7) {
return `${diffDays}天前发布`;
} else if (diffDays < 30) {
const weeks = Math.floor(diffDays / 7);
return `${weeks}周前发布`;
} else {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
}
}
</script>
<style lang="stylus" scoped>