Add live status (#1493)

This commit is contained in:
the1812 2021-02-01 19:02:54 +08:00
parent db52e8b9a8
commit 75e451de33
4 changed files with 25 additions and 5 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -258,10 +258,14 @@
text-overflow: ellipsis;
}
}
.live-status,
.time {
font-size: 11px;
grid-area: time;
padding-right: 6px;
&.live {
color: var(--theme-color);
}
}
}
}

View File

@ -9,6 +9,10 @@ interface HistoryItem {
upID: number
href: string
}
interface LiveData {
liveStatus: number
liveStatusText: string
}
interface TimeData {
timestamp: number
time: Date
@ -81,11 +85,14 @@ const historyTimeGrouper = (historyItems: HistoryItem[]) => {
}
}
const formatTime = (date: Date) => {
const { yesterday } = getTimeData()
const { yesterday, today } = getTimeData()
const timestamp = Number(date)
if (timestamp >= yesterday) {
if (timestamp >= today) {
return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`
}
if (timestamp >= yesterday) {
return `昨天 ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`
}
return `${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`
}
const tabs: HistoryTab[] = [
@ -163,7 +170,13 @@ const tabs: HistoryTab[] = [
upName: item.uname,
coverUrl: item.user_cover,
title: item.title,
} as HistoryItem
liveStatus: item.live_status,
liveStatusText: ({
0: '未开播',
1: '直播中',
2: '轮播中',
} as Record<number, string>)[item.live_status],
} as HistoryItem & LiveData
})
return historyItems
}
@ -224,6 +237,9 @@ export class HistoryList extends NavbarComponent {
<div v-if="h.timeText" class="time" :title="h.time.toLocaleString()">
{{h.timeText}}
</div>
<div v-if="h.liveStatus !== undefined" class="live-status" :class="{ live: h.liveStatus === 1 }">
{{h.liveStatusText}}
</div>
</div>
</transition-group>
</div>