2026-09-04 08:56:15 +08:00

46 lines
1015 B
TypeScript
Raw Permalink 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.

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')
}