mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): 添加页面缓存、记录在tab中的缓存页面的滚动条位置
This commit is contained in:
35
src/utils/router/cache.ts
Normal file
35
src/utils/router/cache.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
/**
|
||||
* 获取缓存的路由对应组件的名称
|
||||
* @param routes - 转换后的vue路由
|
||||
*/
|
||||
export function getCacheRoutes(routes: RouteRecordRaw[]) {
|
||||
const cacheNames: string[] = [];
|
||||
routes.forEach(route => {
|
||||
// 只需要获取二级路由的缓存的组件名
|
||||
if (hasChildren(route)) {
|
||||
route.children!.forEach(item => {
|
||||
if (isKeepAlive(item)) {
|
||||
cacheNames.push(item.name as string);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return cacheNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由是否缓存
|
||||
* @param route
|
||||
*/
|
||||
function isKeepAlive(route: RouteRecordRaw) {
|
||||
return Boolean(route?.meta?.keepAlive);
|
||||
}
|
||||
/**
|
||||
* 是否有二级路由
|
||||
* @param route
|
||||
*/
|
||||
function hasChildren(route: RouteRecordRaw) {
|
||||
return Boolean(route.children && route.children.length);
|
||||
}
|
Reference in New Issue
Block a user