|
@@ -10,7 +10,7 @@
|
|
|
<template #description>
|
|
<template #description>
|
|
|
<div class="text-sm">{{ info.content }}</div>
|
|
<div class="text-sm">{{ info.content }}</div>
|
|
|
<div class="flex mt-1 items-center">
|
|
<div class="flex mt-1 items-center">
|
|
|
- <span class="text-xs text-[#797A8A]">16:00</span>
|
|
|
|
|
|
|
+ <span class="text-xs text-[#797A8A]">{{ timeStr }}</span>
|
|
|
<span class="flex-1"></span>
|
|
<span class="flex-1"></span>
|
|
|
<!-- <img src="@/assets/icon_pingjia.png" class="w-[24px]" alt="" /> -->
|
|
<!-- <img src="@/assets/icon_pingjia.png" class="w-[24px]" alt="" /> -->
|
|
|
<like-btn class="ml-[10px]" @like="like" :liked="info.isLiked">{{
|
|
<like-btn class="ml-[10px]" @like="like" :liked="info.isLiked">{{
|
|
@@ -28,6 +28,9 @@ import { LikeBtn } from '@/components/common'
|
|
|
import avatar from '@/assets/common-avatar.png'
|
|
import avatar from '@/assets/common-avatar.png'
|
|
|
import { fetchLikeComment } from '@/api'
|
|
import { fetchLikeComment } from '@/api'
|
|
|
import { useUserStore } from '@/store'
|
|
import { useUserStore } from '@/store'
|
|
|
|
|
+import { formatDistanceToNowStrict, isToday, format } from 'date-fns'
|
|
|
|
|
+import { computed } from 'vue'
|
|
|
|
|
+import zhCN from 'date-fns/locale/zh-CN'
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
info: {
|
|
info: {
|
|
@@ -39,6 +42,17 @@ const props = defineProps({
|
|
|
})
|
|
})
|
|
|
const emit = defineEmits(['update:info'])
|
|
const emit = defineEmits(['update:info'])
|
|
|
|
|
|
|
|
|
|
+const timeStr = computed(() => {
|
|
|
|
|
+ if (props.info.createdAt) {
|
|
|
|
|
+ if (isToday(new Date(props.info.createdAt))) {
|
|
|
|
|
+ return formatDistanceToNowStrict(new Date(props.info.createdAt), { addSuffix: true, locale: zhCN })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return format(new Date(props.info.createdAt), 'MM-dd HH:mm')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ''
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
const userStore = useUserStore()
|
|
const userStore = useUserStore()
|
|
|
function like() {
|
|
function like() {
|
|
|
fetchLikeComment(userStore.userInfo.id, props.info.id).then(res => {
|
|
fetchLikeComment(userStore.userInfo.id, props.info.id).then(res => {
|