chore: miscellaneous modifications

This commit is contained in:
vben
2020-11-21 22:47:10 +08:00
parent 814f9a7add
commit f7aa93f5b0
18 changed files with 33 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
import { dataURLtoBlob, urlToBase64 } from './stream';
import { dataURLtoBlob, urlToBase64 } from './base64';
/**
* Download online pictures

View File

@@ -7,8 +7,8 @@ const ls = createStorage(localStorage);
const ss = createStorage();
interface CacheStore {
local?: any;
session?: any;
local: Record<string, any>;
session: Record<string, any>;
}
/**
@@ -25,14 +25,14 @@ function initCache() {
cacheStore.local = ls.get(BASE_LOCAL_CACHE_KEY) || {};
cacheStore.session = ss.get(BASE_SESSION_CACHE_KEY) || {};
}
initCache();
export function setLocal(key: string, value: any, immediate = false) {
cacheStore.local[BASE_LOCAL_CACHE_KEY] = cacheStore.local[BASE_LOCAL_CACHE_KEY] || {};
cacheStore.local[BASE_LOCAL_CACHE_KEY][key] = value;
if (immediate) {
const localCache = cacheStore.local;
ls.set(BASE_LOCAL_CACHE_KEY, localCache);
ls.set(BASE_LOCAL_CACHE_KEY, cacheStore.local);
}
}
@@ -43,6 +43,7 @@ export function getLocal<T>(key: string): T | null {
return null;
}
}
export function removeLocal(key: string) {
if (cacheStore.local[BASE_LOCAL_CACHE_KEY]) {
Reflect.deleteProperty(cacheStore.local[BASE_LOCAL_CACHE_KEY], key);
@@ -91,8 +92,6 @@ export function clearAll() {
const localCache = cacheStore.local;
const sessionCache = cacheStore.session;
// const ss = createStorage();
ls.set(BASE_LOCAL_CACHE_KEY, localCache);
ss.set(BASE_SESSION_CACHE_KEY, sessionCache);
});
@@ -114,6 +113,7 @@ export function clearAll() {
}
}
}
if (isIeFn() && (document as any).attachEvent) {
(document as any).attachEvent('onstorage', storageChange);
} else {

View File

@@ -158,6 +158,7 @@ export function forEach<T = any>(
export function treeMap(treeData: any[], opt: { children?: string; conversion: Fn }) {
return treeData.map((item) => treeMapEach(item, opt));
}
/**
* @description: 提取tree指定结构
*/