/**
 * 存储平台适配器
 * 封装微信小程序 Storage API
 */

export function getStorage<T>(key: string, defaultValue?: T): T | undefined {
    try {
        const value = wx.getStorageSync(key);
        return value !== '' ? value : defaultValue;
    } catch {
        return defaultValue;
    }
}

export function setStorage(key: string, value: any): void {
    try {
        wx.setStorageSync(key, value);
    } catch (e) {
        console.error('setStorage failed:', key, e);
    }
}

export function removeStorage(key: string): void {
    try {
        wx.removeStorageSync(key);
    } catch (e) {
        console.error('removeStorage failed:', key, e);
    }
}
