const __NEXT_NAME__ = 'EliteSysClient';

export const Local = {
  // 设置键名
  setKey(key) {
    return `${__NEXT_NAME__}:${key}`;
  },
  
  // 设置永久缓存
  set(key, val) {
    try {
      uni.setStorageSync(Local.setKey(key), JSON.stringify(val));
    } catch (e) {
      console.error('Set storage failed:', e);
    }
  },
  
  // 获取永久缓存
  get(key) {
    try {
      const json = uni.getStorageSync(Local.setKey(key));
      return json ? JSON.parse(json) : null;
    } catch (e) {
      console.error('Get storage failed:', e);
      return null;
    }
  },
  
  // 移除永久缓存
  remove(key) {
    try {
      uni.removeStorageSync(Local.setKey(key));
    } catch (e) {
      console.error('Remove storage failed:', e);
    }
  },
  
  // 移除全部永久缓存
  clear() {
    try {
      uni.clearStorageSync();
    } catch (e) {
      console.error('Clear storage failed:', e);
    }
  },
};
