diff --git a/src/api/home/types/home.ts b/src/api/home/types/home.ts index bd5c4853..cda833df 100644 --- a/src/api/home/types/home.ts +++ b/src/api/home/types/home.ts @@ -40,6 +40,7 @@ export interface HomeTopic { popularity: number user: HomeUserInfo status: number + upvote_time: number } // 首页响应数据的格式 diff --git a/src/api/topic/types/topic.ts b/src/api/topic/types/topic.ts index c804d81b..6059acd3 100644 --- a/src/api/topic/types/topic.ts +++ b/src/api/topic/types/topic.ts @@ -30,6 +30,7 @@ export interface TopicDetail { share: number[] category: string[] popularity: number + upvote_time: number } // 更新话题的请求数据 diff --git a/src/utils/time.ts b/src/utils/time.ts new file mode 100644 index 00000000..8b14daca --- /dev/null +++ b/src/utils/time.ts @@ -0,0 +1,21 @@ +/** + * 根据时间戳获取经过的小时数 + */ + +import dayjs from 'dayjs' + +export const hourDiff = (upvote_time: number, hours: number) => { + // 检查 upvote_time 是否有效,因为后端初始化为 0 + if (upvote_time === 0 || upvote_time === undefined) { + return false + } + + // 获取当前时间 + const currentTime = dayjs() + + // 获取 upvote_time,这里假设 upvote_time 是一个 UNIX 时间戳 + const upvoteTime = dayjs(upvote_time) + + // 计算时间差并返回比较结果 + return currentTime.diff(upvoteTime, 'hour') <= hours +} diff --git a/src/views/Home/content/article/components/ArticleContent.vue b/src/views/Home/content/article/components/ArticleContent.vue index 4360f87d..91beab02 100644 --- a/src/views/Home/content/article/components/ArticleContent.vue +++ b/src/views/Home/content/article/components/ArticleContent.vue @@ -1,6 +1,8 @@