日付照会によるレポートの内容をLocal Storageにキャッシュ
7437 ワード
let CacheReportData = {
/**
*
* @param obj
* @param name
* @param startDate
* @param pagingData
* @returns {*}
*/
getCacheData: function(obj, name, startDate, pagingData) {
let localStorageCache = window.localStorage;
let localStorageCacheObj = localStorageCache.getItem(name);
try {
if (localStorageCacheObj.indexOf('obj-') === 0) {
localStorageCacheObj = localStorageCacheObj.slice(4);
for (const cache of JSON.parse(localStorageCacheObj)) {
//
if (cache.key === startDate && cache._current === pagingData._current) {
pagingData._current = cache._current;
pagingData._pageSize = cache._pageSize;
pagingData._total = cache._total;
return cache.values;
}
}
}
} catch (e) {}
},
/**
*
* @param obj
* @param name
* @param startDate
* @param list
* @param paging
*/
setCacheData: function(obj, name, startDate, list, paging) {
let cacheDatas = {};
cacheDatas.key = startDate;
cacheDatas.values = list;
cacheDatas._current = paging.current;
cacheDatas._pageSize = paging.pageSize;
cacheDatas._total = paging.total;
obj.state.cacheData.push(cacheDatas);
let v = JSON.stringify(obj.state.cacheData);
v = 'obj-' + v;
let localStorage = window.localStorage;
localStorage.setItem(name, v);
},
};
export default CacheReportData;