兰宝车间质量管理系统-前端
疯狂的狮子Li
2025-01-20 5e440a7dc434c43eb828fa62cf9c12b0078b8565
src/plugins/cache.ts
@@ -1,77 +1,79 @@
const sessionCache = {
   set(key: string, value: any) {
      if (!sessionStorage) {
         return;
      }
      if (key != null && value != null) {
         sessionStorage.setItem(key, value);
      }
   },
   get(key: string) {
      if (!sessionStorage) {
         return null;
      }
      if (key == null) {
         return null;
      }
      return sessionStorage.getItem(key);
   },
   setJSON(key: string, jsonValue: any) {
      if (jsonValue != null) {
         this.set(key, JSON.stringify(jsonValue));
      }
   },
   getJSON(key: string) {
      const value = this.get(key);
      if (value != null) {
         return JSON.parse(value);
      }
   },
   remove(key: string) {
      sessionStorage.removeItem(key);
   }
  set(key: string, value: any) {
    if (!sessionStorage) {
      return;
    }
    if (key != null && value != null) {
      sessionStorage.setItem(key, value);
    }
  },
  get(key: string) {
    if (!sessionStorage) {
      return null;
    }
    if (key == null) {
      return null;
    }
    return sessionStorage.getItem(key);
  },
  setJSON(key: string, jsonValue: any) {
    if (jsonValue != null) {
      this.set(key, JSON.stringify(jsonValue));
    }
  },
  getJSON(key: string) {
    const value = this.get(key);
    if (value != null) {
      return JSON.parse(value);
    }
    return null;
  },
  remove(key: string) {
    sessionStorage.removeItem(key);
  }
};
const localCache = {
   set(key: string, value: any) {
      if (!localStorage) {
         return;
      }
      if (key != null && value != null) {
         localStorage.setItem(key, value);
      }
   },
   get(key: string) {
      if (!localStorage) {
         return null;
      }
      if (key == null) {
         return null;
      }
      return localStorage.getItem(key);
   },
   setJSON(key: string, jsonValue: any) {
      if (jsonValue != null) {
         this.set(key, JSON.stringify(jsonValue));
      }
   },
   getJSON(key: string) {
      const value = this.get(key);
      if (value != null) {
         return JSON.parse(value);
      }
   },
   remove(key: string) {
      localStorage.removeItem(key);
   }
  set(key: string, value: any) {
    if (!localStorage) {
      return;
    }
    if (key != null && value != null) {
      localStorage.setItem(key, value);
    }
  },
  get(key: string) {
    if (!localStorage) {
      return null;
    }
    if (key == null) {
      return null;
    }
    return localStorage.getItem(key);
  },
  setJSON(key: string, jsonValue: any) {
    if (jsonValue != null) {
      this.set(key, JSON.stringify(jsonValue));
    }
  },
  getJSON(key: string) {
    const value = this.get(key);
    if (value != null) {
      return JSON.parse(value);
    }
    return null;
  },
  remove(key: string) {
    localStorage.removeItem(key);
  }
};
export default {
   /**
    * 会话级缓存
    */
   session: sessionCache,
   /**
    * 本地缓存
    */
   local: localCache
  /**
   * 会话级缓存
   */
  session: sessionCache,
  /**
   * 本地缓存
   */
  local: localCache
};