fix: 修复抽烟记录第一条不显示距离上次时间的问题
- 第一条记录现在显示距离当前时间的间隔 - 后续记录显示距离上一条记录的间隔 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+27
-8
@@ -66,18 +66,37 @@ export const useLogsStore = defineStore('logs', {
|
||||
|
||||
return sortedLogs.map((log, index) => {
|
||||
const type = normalizeLogType(log)
|
||||
|
||||
// 计算间隔时间:当前记录与上一条记录的间隔(上一条是 index-1,因为已倒序)
|
||||
|
||||
// 计算间隔时间
|
||||
let interval = ''
|
||||
if (index > 0) {
|
||||
const currentTime = getTime(log)
|
||||
const prevTime = getTime(sortedLogs[index - 1])
|
||||
const diff = prevTime - currentTime // 上一条时间 - 当前时间(因为已倒序)
|
||||
|
||||
const currentTime = getTime(log)
|
||||
|
||||
if (index === 0) {
|
||||
// 第一条记录:显示距离当前时间的间隔
|
||||
const now = Date.now()
|
||||
const diff = now - currentTime
|
||||
|
||||
if (diff > 0) {
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60))
|
||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
|
||||
|
||||
|
||||
if (hours > 0) {
|
||||
interval = `${hours}小时${minutes}分`
|
||||
} else if (minutes > 0) {
|
||||
interval = `${minutes}分钟`
|
||||
} else {
|
||||
interval = '刚刚'
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 后续记录:显示距离上一条记录的间隔
|
||||
const prevTime = getTime(sortedLogs[index - 1])
|
||||
const diff = prevTime - currentTime
|
||||
|
||||
if (diff > 0) {
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60))
|
||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
|
||||
|
||||
if (hours > 0) {
|
||||
interval = `${hours}小时${minutes}分`
|
||||
} else if (minutes > 0) {
|
||||
|
||||
Reference in New Issue
Block a user