CN-1415 fix: 修复搜索历史排序与时间展示问题

This commit is contained in:
刘洪洪
2023-11-08 15:42:23 +08:00
parent 78105475fb
commit 1410f890f3
2 changed files with 4 additions and 5 deletions

View File

@@ -1407,10 +1407,10 @@ export const myHighLight = {
export const changeTimeByDate = (date) => {
if (date) {
const nowDate = Date.now()
const oldDate = Date.parse(date)
const oldDate = isNaN(date) ? Date.parse(date) : date
const diff = Math.floor((nowDate - oldDate) / 1000)
if (diff < 60) {
return 60 + i18n.global.t('entity.search.secondsAgo')
return diff + i18n.global.t('entity.search.secondsAgo')
} else if (diff >= 60 && diff < 3600) {
const minutes = Math.floor(diff / 60)
return minutes === 1 ? `${minutes} ${i18n.global.t('entity.search.minuteAgo')}` : `${minutes} ${i18n.global.t('entity.search.minutesAgo')}`
@@ -1418,7 +1418,7 @@ export const changeTimeByDate = (date) => {
const hours = Math.floor(diff / 3600)
return hours === 1 ? `${hours} ${i18n.global.t('entity.search.hourAgo')}` : `${hours} ${i18n.global.t('entity.search.hoursAgo')}`
} else {
return new Date(oldDate)
return (new Date(oldDate).toString()).replace(/GMT.*/, '')
}
}
}

View File

@@ -36,7 +36,6 @@
<div class="history__items-new">
<el-table
:data="history"
:default-sort="{ prop: 'date', order: 'descending' }"
scrollbar-always-on="false"
@row-click="selectHistory"
style="overflow-x: unset"
@@ -115,7 +114,7 @@ export default {
if (!_.isEmpty(oldHistory)) {
const oldArr = JSON.parse(oldHistory)
if (str === oldArr[0].str) {
oldArr[0].date = Date.now()
oldArr[0].date = this.dateFormatByAppearance(new Date())
} else {
oldArr.unshift(newItem)
}