fix:bug解决

This commit is contained in:
李伊帆
2026-10-28 10:36:39 +08:00
parent c369127166
commit 91bca314ba
57 changed files with 2839 additions and 384 deletions

View File

@@ -1,10 +1,12 @@
const missCounts = new Map<string, number>()
const lastSeenAt = new Map<string, number>()
/** 已向云端上报离线的设备,避免轮询重复写库 */
const cloudOfflineReported = new Set<string>()
/** 连续扫描未命中次数达到该值后才判定离线 */
const OFFLINE_AFTER_MISSES = 2
/** 最近一次 BLE 命中后的宽限期(避免切换页面时瞬时扫不到) */
const ONLINE_GRACE_MS = 45_000
const ONLINE_GRACE_MS = 25_000
function deviceKey(deviceId: string | number | undefined): string {
return deviceId != null ? String(deviceId) : ''
@@ -15,6 +17,7 @@ export function recordPresenceHit(deviceId: string | number) {
if (!key) return
missCounts.set(key, 0)
lastSeenAt.set(key, Date.now())
cloudOfflineReported.delete(key)
}
export function recordPresenceMiss(deviceId: string | number) {
@@ -44,9 +47,23 @@ export function resetPresenceState(deviceId?: string | number) {
if (deviceId == null) {
missCounts.clear()
lastSeenAt.clear()
cloudOfflineReported.clear()
return
}
const key = deviceKey(deviceId)
missCounts.delete(key)
lastSeenAt.delete(key)
cloudOfflineReported.delete(key)
}
export function shouldReportPresenceOfflineToCloud(deviceId: string | number): boolean {
const key = deviceKey(deviceId)
if (!key) return false
return !cloudOfflineReported.has(key)
}
export function markPresenceOfflineReportedToCloud(deviceId: string | number) {
const key = deviceKey(deviceId)
if (!key) return
cloudOfflineReported.add(key)
}