feat(projects): 新增多页签缓存功能

This commit is contained in:
Soybean
2021-11-20 21:30:49 +08:00
parent ffe987832f
commit d86f891c64
15 changed files with 132 additions and 43 deletions

View File

@ -1,3 +1,4 @@
export * from './helpers';
export * from './cache';
export * from './menus';
export * from './tab';

View File

@ -18,6 +18,7 @@ function addPartialProps(menuItem: GlobalMenuOption, icon?: string, children?: G
return item;
}
/** 将路由转换成菜单 */
export function transformRouteToMenu(routes: CustomRoute[]) {
const globalMenu: GlobalMenuOption[] = [];
routes.forEach(route => {

23
src/utils/router/tab.ts Normal file
View File

@ -0,0 +1,23 @@
import { EnumStorageKey } from '@/enum';
import type { MultiTabRoute } from '@/interface';
import { setLocal, getLocal } from '../storage';
/** 缓存多页签数据 */
export function setTabRouteStorage(data: MultiTabRoute[]) {
setLocal(EnumStorageKey['tab-route'], data);
}
/** 获取缓存的多页签数据 */
export function getTabRouteStorage() {
const routes: MultiTabRoute[] = [];
const data = getLocal<MultiTabRoute[]>(EnumStorageKey['tab-route']);
if (data) {
routes.push(...data);
}
return routes;
}
/** 清空多页签数据 */
export function clearTabRoutes() {
setTabRouteStorage([]);
}