perf: 修复tab页缓存问题

pull/370/head
xiaojunnuo 2025-04-08 23:31:25 +08:00
parent a0eeb17d73
commit 64e5449ab3
5 changed files with 24 additions and 18 deletions

View File

@ -22,7 +22,7 @@ function buildAccessedMenus(menus: any) {
}
}
const item: any = {
...sub
...sub,
};
list.push(item);
@ -40,7 +40,7 @@ export function setupCommonGuard(router: Router) {
// 记录已经加载的页面
const loadedPaths = new Set<string>();
router.beforeEach(async (to) => {
router.beforeEach(async to => {
const settingStore = useSettingStore();
await settingStore.initOnce();
@ -53,7 +53,7 @@ export function setupCommonGuard(router: Router) {
return true;
});
router.afterEach((to) => {
router.afterEach(to => {
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行
loadedPaths.add(to.path);
@ -71,6 +71,10 @@ export function setupCommonGuard(router: Router) {
*/
function setupAccessGuard(router: Router) {
router.beforeEach(async (to, from) => {
if (to.matched && to.matched.length > 2) {
to.matched.splice(1, to.matched.length - 2);
}
const accessStore = useAccessStore();
// 是否已经生成过动态路由
if (!accessStore.isAccessChecked) {
@ -93,7 +97,7 @@ function setupAccessGuard(router: Router) {
}
// 基本路由,这些路由不需要进入权限拦截
const needAuth = to.matched.some((r) => {
const needAuth = to.matched.some(r => {
return r.meta?.auth || r.meta?.permission;
});
@ -108,7 +112,7 @@ function setupAccessGuard(router: Router) {
// 如不需要,直接删除 query
query: to.fullPath === DEFAULT_HOME_PATH ? {} : { redirect: encodeURIComponent(to.fullPath) },
// 携带当前跳转的页面,登录后重新跳转该页面
replace: true
replace: true,
};
}
return true;

View File

@ -65,7 +65,7 @@ export default router;
// // 多页控制 打开新的页面
// const pageStore = usePageStore();
// // for (const item of to.matched) {
// // pageStore.cachePush(item.name);
// // pageStore.keepAlivePush(item.name);
// // }
// pageStore.open(to);
// // 更改标题

View File

@ -40,11 +40,11 @@ function transformOneResource(resource: any, parent: any) {
if (route.component == null) {
route.component = LayoutPass;
}
if (route?.meta?.cache !== true) {
if (route?.meta?.keepAlive !== true) {
if (route.meta == null) {
route.meta = {};
}
route.meta.cache = false;
route.meta.keepAlive = false;
}
}
if (resource.children) {

View File

@ -20,7 +20,7 @@ export const certdResources = [
component: "/certd/pipeline/index.vue",
meta: {
icon: "ion:analytics-sharp",
cache: true,
keepAlive: true,
},
},
{
@ -39,7 +39,7 @@ export const certdResources = [
component: "/certd/history/index.vue",
meta: {
icon: "ion:timer-outline",
cache: true,
keepAlive: true,
},
},
{
@ -51,6 +51,7 @@ export const certdResources = [
icon: "ion:shield-checkmark-outline",
auth: true,
isMenu: true,
keepAlive: true,
},
},
{
@ -61,6 +62,7 @@ export const certdResources = [
meta: {
icon: "ion:videocam-outline",
auth: true,
keepAlive: true,
},
},
{
@ -71,7 +73,7 @@ export const certdResources = [
meta: {
icon: "ion:settings-outline",
auth: true,
cache: true,
keepAlive: true,
},
children: [
{
@ -82,7 +84,7 @@ export const certdResources = [
meta: {
icon: "ion:disc-outline",
auth: true,
cache: true,
keepAlive: true,
},
},
{
@ -114,7 +116,7 @@ export const certdResources = [
meta: {
icon: "hugeicons:api",
auth: true,
cache: true,
keepAlive: true,
},
},
{
@ -125,7 +127,7 @@ export const certdResources = [
meta: {
icon: "ion:megaphone-outline",
auth: true,
cache: true,
keepAlive: true,
},
},
{

View File

@ -47,7 +47,7 @@ export const sysResources = [
meta: {
icon: "ion:earth-outline",
permission: "sys:settings:view",
cache: true,
keepAlive: true,
},
},
{
@ -111,7 +111,7 @@ export const sysResources = [
meta: {
icon: "ion:extension-puzzle-outline",
permission: "sys:settings:view",
cache: true,
keepAlive: true,
},
},
{
@ -123,7 +123,7 @@ export const sysResources = [
isMenu: false,
icon: "ion:extension-puzzle",
permission: "sys:settings:view",
cache: true,
keepAlive: true,
},
},
{
@ -148,7 +148,7 @@ export const sysResources = [
meta: {
icon: "ion:golf-outline",
permission: "sys:settings:view",
cache: true,
keepAlive: true,
},
},
{