topfans/frontend/utils/handlers/progressHandler.js
2026-07-29 16:03:33 +08:00

46 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// frontend/utils/handlers/progressHandler.js
// 活动进度缓存 handler简单型
import { isProtectedKey } from '@/utils/cacheManager'
const PREFIX = 'progress_'
function listProgressKeys() {
try {
const info = uni.getStorageInfoSync()
return (info.keys || []).filter((k) => k.startsWith(PREFIX) && !isProtectedKey(k))
} catch (e) { return [] }
}
function computeSizeOf(keys) {
let total = 0
for (const k of keys) {
try {
const v = uni.getStorageSync(k)
if (v != null) total += JSON.stringify(v).length
} catch (e) { /* skip */ }
}
return total
}
export default {
id: 'progress',
label: '活动进度缓存',
description: '支持活动页断网浏览',
warning: false,
async computeSize() {
const keys = listProgressKeys()
return { sizeBytes: computeSizeOf(keys), keyCount: keys.length }
},
async clean() {
const keys = listProgressKeys()
let freed = 0
for (const k of keys) {
try {
const v = uni.getStorageSync(k)
if (v != null) freed += JSON.stringify(v).length
uni.removeStorageSync(k)
} catch (e) { /* skip */ }
}
return { freedBytes: freed, keyCount: keys.length }
},
}