feat: upvote_time
This commit is contained in:
parent
233db9288d
commit
5324186cad
|
@ -40,6 +40,7 @@ export interface HomeTopic {
|
||||||
popularity: number
|
popularity: number
|
||||||
user: HomeUserInfo
|
user: HomeUserInfo
|
||||||
status: number
|
status: number
|
||||||
|
upvote_time: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// 首页响应数据的格式
|
// 首页响应数据的格式
|
||||||
|
|
|
@ -30,6 +30,7 @@ export interface TopicDetail {
|
||||||
share: number[]
|
share: number[]
|
||||||
category: string[]
|
category: string[]
|
||||||
popularity: number
|
popularity: number
|
||||||
|
upvote_time: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新话题的请求数据
|
// 更新话题的请求数据
|
||||||
|
|
21
src/utils/time.ts
Normal file
21
src/utils/time.ts
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, onMounted, onBeforeUnmount, onBeforeMount } from 'vue'
|
import { ref, watch, onMounted, onBeforeUnmount, onBeforeMount } from 'vue'
|
||||||
import SingleTopic from './SingleTopic.vue'
|
import SingleTopic from './SingleTopic.vue'
|
||||||
|
// 导入计算时间差的函数
|
||||||
|
import { hourDiff } from '@/utils/time'
|
||||||
|
|
||||||
import { HomeTopic } from '@/api'
|
import { HomeTopic } from '@/api'
|
||||||
|
|
||||||
|
@ -93,11 +95,13 @@ onBeforeUnmount(() => {
|
||||||
<template>
|
<template>
|
||||||
<div class="topic-container" ref="content">
|
<div class="topic-container" ref="content">
|
||||||
<TransitionGroup name="list" tag="div">
|
<TransitionGroup name="list" tag="div">
|
||||||
<!-- 热度 > 100 则话题处于被推状态 -->
|
<!-- 被推时间在 10h 之内 -->
|
||||||
<div
|
<div
|
||||||
v-for="topic in topics"
|
v-for="topic in topics"
|
||||||
:key="topic.tid"
|
:key="topic.tid"
|
||||||
:class="topic.popularity >= 100 ? 'kungalgame-comet-surround' : ''"
|
:class="
|
||||||
|
hourDiff(topic.upvote_time, 10) ? 'kungalgame-comet-surround' : ''
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<span></span>
|
<span></span>
|
||||||
<span></span>
|
<span></span>
|
||||||
|
|
|
@ -42,7 +42,8 @@ onMounted(async () => {
|
||||||
<div class="title">{{ kun.title }}</div>
|
<div class="title">{{ kun.title }}</div>
|
||||||
<div class="hot">
|
<div class="hot">
|
||||||
<Icon icon="bi:fire" />
|
<Icon icon="bi:fire" />
|
||||||
<span>{{ kun.popularity }}</span>
|
<!-- 后端计算小数不精确,一律 ceil -->
|
||||||
|
<span>{{ Math.ceil(kun.popularity) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</router-link>
|
</router-link>
|
||||||
|
|
|
@ -18,6 +18,9 @@ import Tags from '../components/Tags.vue'
|
||||||
import { TopicDetail } from '@/api/topic/types/topic'
|
import { TopicDetail } from '@/api/topic/types/topic'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
// 导入计算时间差的函数
|
||||||
|
import { hourDiff } from '@/utils/time'
|
||||||
|
|
||||||
const topicData = defineProps<{
|
const topicData = defineProps<{
|
||||||
topicData: TopicDetail
|
topicData: TopicDetail
|
||||||
}>()
|
}>()
|
||||||
|
@ -38,13 +41,14 @@ const {
|
||||||
status,
|
status,
|
||||||
share,
|
share,
|
||||||
category,
|
category,
|
||||||
popularity,
|
// popularity,
|
||||||
|
upvote_time,
|
||||||
} = topicData.topicData
|
} = topicData.topicData
|
||||||
|
|
||||||
// 话题的状态
|
// 话题的状态
|
||||||
const loliStatus = computed(() => {
|
const loliStatus = computed(() => {
|
||||||
// 热度 > 100 则显示被推
|
// 被推在 10h 之内则显示被推
|
||||||
if (popularity >= 100) {
|
if (hourDiff(upvote_time, 10)) {
|
||||||
return 'featured'
|
return 'featured'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue