时间展示优化

feasure-livedata
lld 2026-03-29 20:53:15 +08:00
parent f49fc45272
commit e5ea9577ac
1 changed files with 17 additions and 2 deletions

View File

@ -19,8 +19,10 @@
@click="gotoDevice(item)" @click="gotoDevice(item)"
class="message-item" class="message-item"
> >
<!-- 时间标签 --> <!-- 时间标签如果是第一条或者与上一条时间不同才显示 -->
<view class="time-label">{{ formatTime(item.time) }}</view> <view class="time-label" v-if="index === 0 || !isSameMinute(item.time, messageList[index - 1].time)">
{{ formatTime(item.time) }}
</view>
<!-- &lt;!&ndash; 点赞消息卡片 &ndash;&gt; <!-- &lt;!&ndash; 点赞消息卡片 &ndash;&gt;
<view class="like-card" v-if="item.type === 'like'"> <view class="like-card" v-if="item.type === 'like'">
@ -140,6 +142,19 @@ export default {
this.getSortDate(); this.getSortDate();
}, },
methods: { methods: {
goTo(id) {
this.scrollId = id;
},
//
isSameMinute(time1, time2) {
const date1 = new Date(time1);
const date2 = new Date(time2);
return date1.getFullYear() === date2.getFullYear() &&
date1.getMonth() === date2.getMonth() &&
date1.getDate() === date2.getDate() &&
date1.getHours() === date2.getHours() &&
date1.getMinutes() === date2.getMinutes();
},
formatTime(timeStr) { formatTime(timeStr) {
const now = new Date(); const now = new Date();
const target = new Date(timeStr); const target = new Date(timeStr);