@ovine/core
Version:
Build flexible admin system with json.
37 lines (36 loc) • 1.13 kB
JavaScript
/**
* 路由状态持久化
*
* 1. 记录 打开着的 路由
* 2. 记录 url 地址参数
*/
import { uniqueId } from 'lodash';
import { app } from "../../app";
import { storage } from "../../constants";
import { getStore, setStore, clearStore } from "../../utils/store";
export const clearCachedTabs = () => {
clearStore(storage.routeTabs);
};
export const cacheTabs = (allTabs) => {
const list = [];
allTabs.forEach((tabEl) => {
var _a;
const { path: pathname = '', root: isRoot = '' } = tabEl.dataset;
// 404 不缓存
if (app.constants.notFound.route === pathname) {
return;
}
const label = ((_a = tabEl.querySelector('.chrome-tab-title')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '';
const item = { pathname, label, id: uniqueId() };
if (isRoot) {
item.isRoot = true;
}
list.push(item);
});
setStore(storage.routeTabs, list);
};
// TODO: 获取有效的 缓存路由
export const getValidCacheTabs = () => {
const list = getStore(storage.routeTabs) || [];
return list;
};