feat(admin): 增加工作台大屏和转码通知
This commit is contained in:
1 parent
2b2c6bd708
commit
a266d44483
10 files changed
+860
-172
No files matched your search
@@ -0,0 +1,51 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
const SEEN_KEY = 'transcode-notice-seen'
|
||||
|
||||
export const TRANSCODE_NOTICE_SEEN = 'transcode-notice-seen'
|
||||
|
||||
export interface NoticeCounts {
|
||||
running: number
|
||||
success: number
|
||||
failed: number
|
||||
}
|
||||
|
||||
/** 上次打开通知页时已经看过的数量。 */
|
||||
export function readSeen(): NoticeCounts {
|
||||
try {
|
||||
const raw = localStorage.getItem(SEEN_KEY)
|
||||
if (!raw) return { running: 0, success: 0, failed: 0 }
|
||||
const data = JSON.parse(raw) as NoticeCounts
|
||||
return {
|
||||
running: Number(data.running || 0),
|
||||
success: Number(data.success || 0),
|
||||
failed: Number(data.failed || 0)
|
||||
}
|
||||
} catch {
|
||||
return { running: 0, success: 0, failed: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
/** 比上次查看多出来的数量,看过的不再计入角标。 */
|
||||
export function unreadCounts(current: NoticeCounts): NoticeCounts {
|
||||
const seen = readSeen()
|
||||
return {
|
||||
running: Math.max(0, current.running - seen.running),
|
||||
success: Math.max(0, current.success - seen.success),
|
||||
failed: Math.max(0, current.failed - seen.failed)
|
||||
}
|
||||
}
|
||||
|
||||
/** 把当前数量记为已读,并通知顶栏收起角标。 */
|
||||
export function markTranscodeNoticeSeen(current: NoticeCounts) {
|
||||
const seen = readSeen()
|
||||
localStorage.setItem(
|
||||
SEEN_KEY,
|
||||
JSON.stringify({
|
||||
running: Math.max(seen.running, current.running),
|
||||
success: Math.max(seen.success, current.success),
|
||||
failed: Math.max(seen.failed, current.failed)
|
||||
})
|
||||
)
|
||||
window.dispatchEvent(new Event(TRANSCODE_NOTICE_SEEN))
|
||||
}
|
||||
Reference in new issue
Block a user