Skip to content

Latest commit

 

History

History
 
 

library_local_storage_complete_yseventeen

# library_local_storage_complete_yseventeen

**依赖库设计**

本地存储逻辑依赖库-完整版,封装localStorage操作方法,包括 :

1. 将值存储到本地存储中。

2. 从本地存储中获取值。
3. 从本地存储中删除值。
4. ...等

## logics/config.js
通过修改config文件的 type 配置可以轻松切换操作的本地存储类型,

类型支持 **window.localStorage, window.sessionStorage**;

```javascript
type: "localStorage", // 本地存储类型 localStorage/sessionStorage
prefix: "newpayV2.3", // 名称前缀一般设置为:项目名 + 项目版本,末尾会自动加上"_";
expire: 60 * 60, //过期时间 单位:秒
isEncrypt: true, // 默认加密
SECRET_KEY: CryptoJS.enc.Utf8.parse("778998nt57121345"), //十六位十六进制数作为密钥
SECRET_IV:  CryptoJS.enc.Utf8.parse("nt657ab258931477"),// / 十六位十六进制数作为密钥偏移量
```



### 逻辑

* **setStorage**: 设置本地存储。

  入参1:【key】 string,必填;设置本地存储的名;
  入参2:【value】 string,必填;设置本地存储的值;
  入参3:【expire】 string,非必填,默认 60*60;设置本地存储的过期时间单位:秒;
  无出参;

* **getStorage**:根据Key获取指定的本地存储,支持过期删除,未过期期间被调用自动续期进行保活。

  入参1:【key】 string,必填;本地存储的名;
  出参1:string

* **removeStorage**:根据 Key 删除指定的本地存储。

  入参1:【key】 string,必填;客户端存储的名;

* **clearStorage**:清空本地存储。

  无入参;
  无出参;

* **getAllStorage**:获取全部本地存储。

  无入参;
  出参1:返回{key:string,val:string}[]格式的数组数据;

* **getStorageArrLength**:获取本地存储的数组长度。

  无入参;
  出参1:{string} 返回数组长度;

* **getStorageKeyForIndex**:根据索引获取本地存储的key。

  入参1:【index】 number,必填;索引值;

  出参1:{string} 返回该条索引对应的本地存储的Key值;

* **getStorageKeys**:获取本地存储所有的key值。

  无入参;
  出参1:返回{string[]}格式的数组对象;

* **hasStorage**:传入Key判断本地存储中是否存在

  入参1:【key】 string,必填;本地存储的名;

  出参1:返回{boolean} true/false;




## 使用步骤说明
1. 应用引用依赖库

2. 无需配置

3. 逻辑调用示例截图

   ![image info](./Screenshot/1710929655863.jpg)
   ![image info](./Screenshot/[email protected])

​	![image info](./Screenshot/[email protected])

![image info](./Screenshot/[email protected])



## 应用演示链接

https://dev-yseventeenlcap-yseventeen.app.codewave.163.com/dashboard/test