let bleName: string | null = null let bleMac: string | null = null // 读取本地存储字符串;vue3 的 getStorageSync 无 key 时返回 "",统一转成 null function getStorageStr(key: string): string | null { const t = uni.getStorageSync(key) as string return (t != null && t.length > 0) ? t : null } // 保存蓝牙名字 export function setName(name: string) { bleName = name uni.setStorageSync('bleName', name) } // 读取蓝牙名字 export function getName(): string | null { if (bleName != null) { return bleName } bleName = getStorageStr('bleName') return bleName } // 保存蓝牙mac export function setMac(mac: string) { bleMac = mac uni.setStorageSync('bleMac', mac) } // 读取蓝牙mac export function getMac(): string | null { if (bleMac != null) { return bleMac } bleMac = getStorageStr('bleMac') return bleMac } export function clearAllData() { bleName = null bleMac = null uni.removeStorageSync('bleName') uni.removeStorageSync('bleMac') }