UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

52 lines (49 loc) 1.61 kB
import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; import _createClass from '@babel/runtime/helpers/createClass'; import { getPersist, savePersist } from '../storage/persist-data.mjs'; import '../env/env.mjs'; var LocationStorage = /*#__PURE__*/function () { function LocationStorage() { _classCallCheck(this, LocationStorage); } return _createClass(LocationStorage, null, [{ key: "getLocationFromSessionStorage", value: // 从sessionStorage获取缓存位置信息 function getLocationFromSessionStorage() { var storageSession = window.sessionStorage.getItem('position'); if (storageSession) { try { var location = JSON.parse(storageSession); return location; } catch (_a) { return null; } } return null; } // 从localStorage获取缓存位置信息 }, { key: "getLocationFromLocalStorage", value: function getLocationFromLocalStorage() { var persistPosition = getPersist('position'); if (persistPosition) { try { var location = JSON.parse(persistPosition); return location; } catch (_a) { return null; } } return null; } // 存储缓存位置信息到sessionStorage和localStorage }, { key: "setLocationToStorage", value: function setLocationToStorage(location, expireMS) { window.sessionStorage.setItem('position', JSON.stringify(location)); savePersist('position', JSON.stringify(location), expireMS); } }]); }(); export { LocationStorage as default };