animationLevel.ts 901 B

123456789101112131415161718192021222324
  1. export type AnimationLevel = 'standard' | 'lite'
  2. const LITE_BENCHMARK_THRESHOLD = 18
  3. const LITE_DEVICE_MEMORY_GB = 3
  4. export function resolveAnimationLevel(systemInfo?: WechatMiniprogram.SystemInfo): AnimationLevel {
  5. const info = systemInfo || wx.getSystemInfoSync()
  6. const benchmarkLevel = Number((info as WechatMiniprogram.SystemInfo & { benchmarkLevel?: number }).benchmarkLevel)
  7. const deviceMemory = Number((info as WechatMiniprogram.SystemInfo & { deviceMemory?: number }).deviceMemory)
  8. if (Number.isFinite(benchmarkLevel) && benchmarkLevel > 0 && benchmarkLevel <= LITE_BENCHMARK_THRESHOLD) {
  9. return 'lite'
  10. }
  11. if (Number.isFinite(deviceMemory) && deviceMemory > 0 && deviceMemory <= LITE_DEVICE_MEMORY_GB) {
  12. return 'lite'
  13. }
  14. return 'standard'
  15. }
  16. export function formatAnimationLevelText(level: AnimationLevel): string {
  17. return level === 'lite' ? '精简' : '标准'
  18. }