UNPKG

mrcio-ui

Version:

105 lines (91 loc) 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._Cache = undefined; var _react = require("react"); var _react2 = _interopRequireDefault(_react); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Cache 缓存 * @Author gufuyan * @Date 2018-08-30 */ var CacheFn = //函数参数默认值 function CacheFn() { _classCallCheck(this, CacheFn); this.setCookie = function (key, value, exdays) { var d = new Date(); d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); var expires = "expires=" + d.toUTCString(); //document.cookie = key + "=" + value + "; " + expires+"; " + "domain=chinasie.com; path=/"; document.cookie = key + "=" + value + "; " + expires; }; this.getCookie = function (key) { if (!key) return null; var allcookies = document.cookie; var cookie_pos = allcookies.indexOf(key + "="); if (cookie_pos != -1) { cookie_pos += key.length + 1; var cookie_end = allcookies.indexOf(";", cookie_pos); if (cookie_end == -1) { cookie_end = allcookies.length; } return unescape(allcookies.substring(cookie_pos, cookie_end)); } return null; }; this.setLocal = function (key, value) { try { // ios safari 无痕模式下,直接使用 localStorage.setItem 会报错 localStorage.setItem(key, value); } catch (ex) { // 开发环境下提示 error // if (__DEV__) { console.error('localStorage.setItem报错, ', ex.message); // } } }; this.getLocal = function (key) { var value = void 0; try { value = localStorage.getItem(key); } catch (ex) { // 开发环境下提示error // if (__DEV__) { console.error('localStorage.getItem报错, ', ex.message); // } } finally { return value; } }; this.setSession = function (key, value) { try { // ios safari 无痕模式下,直接使用 localStorage.setItem 会报错 sessionStorage.setItem(key, value); } catch (ex) { // 开发环境下提示 error // if (__DEV__) { console.error('sessionStorage.setItem报错, ', ex.message); // } } }; this.getSession = function (key) { var value = void 0; try { value = sessionStorage.getItem(key); } catch (ex) { // 开发环境下提示error // if (__DEV__) { console.error('sessionStorage.getItem报错, ', ex.message); // } } finally { return value; } }; }; var _Cache = new CacheFn(); exports._Cache = _Cache; //# sourceMappingURL=cache.js.map