UNPKG

@lvxiaowu/antd4

Version:

antd4-components

80 lines (70 loc) 3.71 kB
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import { Storage } from '@lvxiaowu/utils'; // 访问历史常量 var VISIT_HISTORY = 'VISIT_HISTORY'; export var VISIT_ID = 'VISIT_ID'; export function getVisitId() { return Storage.get(VISIT_ID) || 'LOCAL'; } export function setVisitId(id) { if (id && id !== getVisitId()) { Storage.set(VISIT_ID, id); } } export function setVisitHistory(current) { if (current) { var visitId = getVisitId(); var allHistory = Storage.get(VISIT_HISTORY) || {}; var currentHistory = allHistory[visitId] || []; var matchIndex = currentHistory.findIndex(function (item) { return item.id === current.id; }); if (matchIndex === -1) { currentHistory.push(_objectSpread(_objectSpread({}, current), {}, { time: Date.now() })); } else { currentHistory[matchIndex].time = Date.now(); } if (currentHistory.length > 10) { currentHistory = currentHistory.splice(0, 8); } Storage.set(VISIT_HISTORY, _objectSpread(_objectSpread({}, allHistory), {}, _defineProperty({}, visitId, currentHistory))); } } export function getVisitHistory(id) { var _Storage$get; var visitId = id !== null && id !== void 0 ? id : getVisitId(); var visitHistory = ((_Storage$get = Storage.get(VISIT_HISTORY)) === null || _Storage$get === void 0 ? void 0 : _Storage$get[visitId]) || []; return visitHistory.sort(function (a, b) { return b.time - a.time; }); } export function removeVisitHistory(id) { var visitId = getVisitId(); var allHistory = Storage.get(VISIT_HISTORY) || {}; var visitHistory = allHistory[visitId] || []; Storage.set(VISIT_HISTORY, _objectSpread(_objectSpread({}, allHistory), {}, _defineProperty({}, visitId, visitHistory.filter(function (item) { return item.id !== id; })))); } // 最后访问路径,用户登录进来直接跳转到上次最后访问的路径 var LAST_VISIT_PATH = 'LAST_VISIT_PATH'; export function setLastVisitPath(path) { if (path) { var visitId = getVisitId(); var allPath = Storage.get(LAST_VISIT_PATH) || {}; Storage.set(LAST_VISIT_PATH, _objectSpread(_objectSpread({}, allPath), {}, _defineProperty({}, visitId, path))); } } export function getLastVisitPath(id) { var _Storage$get2; var visitId = id !== null && id !== void 0 ? id : getVisitId(); return (_Storage$get2 = Storage.get(LAST_VISIT_PATH)) === null || _Storage$get2 === void 0 ? void 0 : _Storage$get2[visitId]; } export function removeLastVisitPath(id) { var visitId = id !== null && id !== void 0 ? id : getVisitId(); var allPath = Storage.get(LAST_VISIT_PATH) || {}; delete allPath[visitId]; Storage.set(LAST_VISIT_PATH, allPath); }