H5端首页显示内容修改
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user