diff --git a/frontend/components/ArticlesList/Item/index.vue b/frontend/components/ArticlesList/Item/index.vue index eaf5091..fa0022f 100644 --- a/frontend/components/ArticlesList/Item/index.vue +++ b/frontend/components/ArticlesList/Item/index.vue @@ -4,6 +4,23 @@ import type { Ref } from 'vue' import type { IArticleItem } from '~~/types/IArticleItem' const artlist = inject>('artlist') const [parent] = useAutoAnimate() +const formatTime = (createdAt: string): string => { + const created = new Date(createdAt) + const now = new Date() + const duration = (now.getTime() - created.getTime()) / 1000 / 60 + let ans = '刚刚' + if (duration > 0 && duration < 60) // 一小时内 + ans = `${(duration).toFixed(0)}分钟前` + else if (duration < 60 * 24) // 一天内 + ans = `${(duration / 60).toFixed(0)}小时前` + else if (duration < 60 * 24 * 30) // 一个月内 + ans = `${(duration / 60 / 24).toFixed(0)}天前` + else if (duration < 60 * 24 * 30 * 365) // 一年内 + ans = `${(duration / 60 / 24 / 30).toFixed(0)}月前` + else if (duration >= 60 * 24 * 30 * 365) // 超过一年 + ans = `${(duration / 60 / 24 / 30 / 365).toFixed(0)}年前` + return ans +} const hideHandler = (id: string) => { artlist && (artlist.value = artlist.value.filter(item => item.id !== id)) } diff --git a/frontend/components/ArticlesList/index.vue b/frontend/components/ArticlesList/index.vue index 47b3b8f..8c2c1cd 100644 --- a/frontend/components/ArticlesList/index.vue +++ b/frontend/components/ArticlesList/index.vue @@ -1,20 +1,22 @@