mirror of
https://github.com/stardrophere/InsightRadar.git
synced 2026-06-05 23:32:49 +08:00
optimize
This commit is contained in:
@@ -135,6 +135,9 @@ function getHotLevel(score: number): { label: string; color: string; bg: string
|
||||
}
|
||||
|
||||
function formatRelativeTime(dateStr: string): string {
|
||||
if (!dateStr.endsWith('Z') && !dateStr.includes('+')) {
|
||||
dateStr += 'Z' // 补偿 SQLite 丢失的 UTC 时区标识
|
||||
}
|
||||
const now = Date.now()
|
||||
const target = new Date(dateStr).getTime()
|
||||
const diff = now - target
|
||||
|
||||
@@ -47,8 +47,15 @@ function getPlatformIcon(name: string): string {
|
||||
}
|
||||
|
||||
/** 格式化时间 */
|
||||
function safeParseTime(dateStr: string): number {
|
||||
if (!dateStr.endsWith('Z') && !dateStr.includes('+')) {
|
||||
dateStr += 'Z'
|
||||
}
|
||||
return new Date(dateStr).getTime()
|
||||
}
|
||||
|
||||
function formatTime(dateStr: string): string {
|
||||
const d = new Date(dateStr)
|
||||
const d = new Date(safeParseTime(dateStr))
|
||||
const now = Date.now()
|
||||
const diff = now - d.getTime()
|
||||
const minutes = Math.floor(diff / 60000)
|
||||
@@ -75,7 +82,7 @@ const revisionChains = computed<RevisionChain[]>(() => {
|
||||
const chains: RevisionChain[] = []
|
||||
for (const [event_id, items] of groups) {
|
||||
// 组内按时间升序
|
||||
items.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime())
|
||||
items.sort((a, b) => safeParseTime(a.created_at) - safeParseTime(b.created_at))
|
||||
|
||||
// 拼接标题链,避免重复(相邻记录的 revised 与下一条 previous 通常相同)
|
||||
const titles: string[] = [items[0].previous_headline]
|
||||
@@ -102,7 +109,7 @@ const revisionChains = computed<RevisionChain[]>(() => {
|
||||
}
|
||||
|
||||
// 最终按最新修改时间降序
|
||||
chains.sort((a, b) => new Date(b.last_at).getTime() - new Date(a.last_at).getTime())
|
||||
chains.sort((a, b) => safeParseTime(b.last_at) - safeParseTime(a.last_at))
|
||||
return chains
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user