perf: 优化消息时间格式

This commit is contained in:
kuaifan 2024-03-06 12:01:18 +08:00
parent e24978fdd7
commit ac17952cd3
3 changed files with 6 additions and 5 deletions

View File

@ -88,13 +88,14 @@ import {MarkdownPreview} from "../store/markdown";
/** /**
* 格式化时间 * 格式化时间
* @param date * @param date
* @param hiHours 小于多少小时只显示时间H:i
* @returns {*|string} * @returns {*|string}
*/ */
formatTime(date) { formatTime(date, hiHours = 6) {
let now = $A.Time(), let now = $A.Time(),
time = $A.Date(date, true), time = $A.Date(date, true),
string = ''; string = '';
if (Math.abs(now - time) < 3600 * 6 || $A.formatDate('Ymd', now) === $A.formatDate('Ymd', time)) { if (Math.abs(now - time) < 3600 * hiHours || $A.formatDate('Ymd', now) === $A.formatDate('Ymd', time)) {
string = $A.formatDate('H:i', time) string = $A.formatDate('H:i', time)
} else if ($A.formatDate('Y', now) === $A.formatDate('Y', time)) { } else if ($A.formatDate('Y', now) === $A.formatDate('Y', time)) {
string = $A.formatDate('m-d', time) string = $A.formatDate('m-d', time)
@ -152,7 +153,7 @@ import {MarkdownPreview} from "../store/markdown";
} else if (time == 0) { } else if (time == 0) {
return 0 + 's'; return 0 + 's';
} }
return this.formatTime(date) return this.formatTime(date, 6)
}, },
/** /**

View File

@ -219,7 +219,7 @@
<template v-else> <template v-else>
<!--时间--> <!--时间-->
<div v-if="timeShow" class="time" @click="timeShow=false">{{msgData.created_at}}</div> <div v-if="timeShow" class="time" @click="timeShow=false">{{msgData.created_at}}</div>
<div v-else class="time" :title="msgData.created_at" @click="timeShow=true">{{$A.formatTime(msgData.created_at)}}</div> <div v-else class="time" :title="msgData.created_at" @click="timeShow=true">{{$A.formatTime(msgData.created_at, 23)}}</div>
<!--阅读--> <!--阅读-->
<template v-if="!hidePercentage"> <template v-if="!hidePercentage">
<div v-if="msgData.send > 1 || dialogType === 'group'" class="percent" @click="openReadPercentage"> <div v-if="msgData.send > 1 || dialogType === 'group'" class="percent" @click="openReadPercentage">

View File

@ -103,7 +103,7 @@
</template> </template>
<span>{{dialog.name}}</span> <span>{{dialog.name}}</span>
<Icon v-if="dialog.type == 'user' && lastMsgReadDone(dialog.last_msg) && dialog.dialog_user.userid != userId" :type="lastMsgReadDone(dialog.last_msg)"/> <Icon v-if="dialog.type == 'user' && lastMsgReadDone(dialog.last_msg) && dialog.dialog_user.userid != userId" :type="lastMsgReadDone(dialog.last_msg)"/>
<em v-if="dialog.last_at">{{$A.formatTime(dialog.last_at)}}</em> <em v-if="dialog.last_at">{{$A.formatTime(dialog.last_at, 23)}}</em>
</div> </div>
<div class="dialog-text no-dark-content"> <div class="dialog-text no-dark-content">
<template v-if="dialog.extra_draft_has && dialog.id != dialogId"> <template v-if="dialog.extra_draft_has && dialog.id != dialogId">