perf: 完善订单管理

This commit is contained in:
richarjiang
2026-04-05 21:03:18 +08:00
parent fdb13c32c2
commit 4633ceea8c
29 changed files with 1000 additions and 261 deletions

View File

@@ -0,0 +1,54 @@
/**
* System info utilities — replaces deprecated uni.getSystemInfoSync()
* with the recommended granular APIs.
*/
interface SystemLayout {
/** Status bar height in px */
readonly statusBarHeight: number
/** Window width in px */
readonly windowWidth: number
/** Custom nav bar height in px (status bar + title bar) */
readonly navBarHeight: number
}
let cached: SystemLayout | null = null
/**
* Returns layout dimensions using the new granular APIs.
* Falls back to getSystemInfoSync only if the new APIs are unavailable.
* Results are cached since these values never change during a session.
*/
export function getSystemLayout(): SystemLayout {
if (cached) return cached
let statusBarHeight = 20
let windowWidth = 375
try {
// New recommended APIs (WeChat base lib >= 2.25.3)
const windowInfo = uni.getWindowInfo()
const deviceInfo = uni.getDeviceInfo()
statusBarHeight = windowInfo.statusBarHeight ?? 20
windowWidth = windowInfo.windowWidth ?? 375
// Silence unused var — deviceInfo is here for future use
void deviceInfo
} catch {
// Fallback for older base lib versions
try {
const sysInfo = uni.getSystemInfoSync()
statusBarHeight = sysInfo.statusBarHeight ?? 20
windowWidth = sysInfo.windowWidth ?? 375
} catch {
// Use defaults
}
}
const navTitlePx = 88 * (windowWidth / 750)
const navBarHeight = Math.round(statusBarHeight + navTitlePx)
cached = { statusBarHeight, windowWidth, navBarHeight }
return cached
}