perf: 优化时间格式

This commit is contained in:
Pang 2024-03-09 10:16:09 +08:00
parent 50893929d6
commit 55a922c7b3
3 changed files with 13 additions and 12 deletions

View File

@ -98,21 +98,22 @@ import {MarkdownPreview} from "../store/markdown";
/** /**
* 格式化时间 * 格式化时间
* @param date * @param date
* @param hiHours 小于多少小时只显示时间H:i
* @returns {*|string} * @returns {*|string}
*/ */
formatTime(date, hiHours = 6) { formatTime(date) {
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 * hiHours || $A.formatDate('Ymd', now) === $A.formatDate('Ymd', time)) { if ($A.formatDate('Ymd', now) === $A.formatDate('Ymd', time)) {
string = $A.formatDate('H:i', time) return $A.formatDate('H:i', time)
} else if ($A.formatDate('Y', now) === $A.formatDate('Y', time)) {
string = $A.formatDate('m-d', time)
} else {
string = $A.formatDate('Y-m-d', time)
} }
return string || ''; if ($A.formatDate('Ymd', now - 86400) === $A.formatDate('Ymd', time)) {
return `${$A.L('昨天')} ${$A.formatDate('H:i', time)}`
}
if ($A.formatDate('Y', now) === $A.formatDate('Y', time)) {
return $A.formatDate('m-d', time)
}
return $A.formatDate('Y-m-d', time);
}, },
/** /**
@ -163,7 +164,7 @@ import {MarkdownPreview} from "../store/markdown";
} else if (time == 0) { } else if (time == 0) {
return 0 + 's'; return 0 + 's';
} }
return this.formatTime(date, 6) return this.formatTime(date)
}, },
/** /**

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, 23)}}</div> <div v-else class="time" :title="msgData.created_at" @click="timeShow=true">{{$A.formatTime(msgData.created_at)}}</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, 23)}}</em> <em v-if="dialog.last_at">{{$A.formatTime(dialog.last_at)}}</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">