export default class storage {
  static PREFIX = "_sagacloud_admin_store_";
  static set(key, value, fn?) {
    let _value = null;
    try {
      _value = JSON.stringify(value);
    } catch (e) {
      _value = value;
    }
    sessionStorage.setItem(storage.PREFIX + key, _value);
    fn && fn();
  }
  static get(key, fn?) {
    if (!key) {
      return null;
    }
    if (typeof key === "object") {
      throw new Error("key不能是一个对象。");
    }
    var _value = sessionStorage.getItem(storage.PREFIX + key);
    if (_value !== null) {
      try {
        return JSON.parse(_value);
      } catch (e) {}
    }
    return _value;
  }
  static remove(key) {
    sessionStorage.removeItem(storage.PREFIX + key);
  }
}
