style: fix some style

This commit is contained in:
xiaoxian521
2021-04-25 13:55:01 +08:00
parent 05b106203c
commit a21700ee02
6 changed files with 110 additions and 44 deletions

View File

@@ -1,42 +1,46 @@
interface ProxyStorage {
getItem(key: string): any
setItem(Key: string, value: string): void
removeItem(key: string): void
getItem(key: string): any;
setItem(Key: string, value: string): void;
removeItem(key: string): void;
clear(): void;
}
//sessionStorage operate
class sessionStorageProxy implements ProxyStorage {
protected storage: ProxyStorage
protected storage: ProxyStorage;
constructor(storageModel: ProxyStorage) {
this.storage = storageModel
this.storage = storageModel;
}
// 存
// 存
public setItem(key: string, value: any): void {
this.storage.setItem(key, JSON.stringify(value))
this.storage.setItem(key, JSON.stringify(value));
}
// 取
public getItem(key: string): any {
return JSON.parse(this.storage.getItem(key)) || null
return JSON.parse(this.storage.getItem(key)) || null;
}
// 删
public removeItem(key: string): void {
this.storage.removeItem(key)
this.storage.removeItem(key);
}
// 清空
public clear(): void {
this.storage.clear();
}
}
//localStorage operate
class localStorageProxy extends sessionStorageProxy implements ProxyStorage {
constructor(localStorage: ProxyStorage) {
super(localStorage)
super(localStorage);
}
}
export const storageSession = new sessionStorageProxy(sessionStorage)
export const storageSession = new sessionStorageProxy(sessionStorage);
export const storageLocal = new localStorageProxy(localStorage)
export const storageLocal = new localStorageProxy(localStorage);