更新
This commit is contained in:
@@ -16,7 +16,7 @@ export const useAppStore = defineStore('app', () => {
|
||||
layout_side_width: 256,
|
||||
layout_side_collapsed_width: 80,
|
||||
layout_side_item_height: 48,
|
||||
show_watermark: true,
|
||||
show_watermark: false,
|
||||
side_mode: 'normal',
|
||||
// 页面过渡动画配置
|
||||
transition_type: 'slide'
|
||||
|
||||
@@ -4,8 +4,8 @@ import { asyncMenu } from '@/api/menu'
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, watchEffect } from 'vue'
|
||||
import pathInfo from '@/pathInfo.json'
|
||||
import {useRoute} from "vue-router";
|
||||
import {config} from "@/core/config.js";
|
||||
import { useRoute } from 'vue-router'
|
||||
import { config } from '@/core/config.js'
|
||||
|
||||
const notLayoutRouterArr = []
|
||||
const keepAliveRoutersArr = []
|
||||
@@ -34,10 +34,7 @@ const KeepAliveFilter = (routes) => {
|
||||
routes &&
|
||||
routes.forEach((item) => {
|
||||
// 子菜单中有 keep-alive 的,父菜单也必须 keep-alive,否则无效。这里将子菜单中有 keep-alive 的父菜单也加入。
|
||||
if (
|
||||
(item.children && item.children.some((ch) => ch.meta.keepAlive)) ||
|
||||
item.meta.keepAlive
|
||||
) {
|
||||
if ((item.children && item.children.some((ch) => ch.meta.keepAlive)) || item.meta.keepAlive) {
|
||||
const path = item.meta.path
|
||||
keepAliveRoutersArr.push(pathInfo[path])
|
||||
nameMap[item.name] = pathInfo[path]
|
||||
@@ -53,7 +50,7 @@ export const useRouterStore = defineStore('router', () => {
|
||||
const asyncRouterFlag = ref(0)
|
||||
const setKeepAliveRouters = (history) => {
|
||||
const keepArrTemp = []
|
||||
|
||||
|
||||
// 1. 首先添加原有的keepAlive配置
|
||||
keepArrTemp.push(...keepAliveRoutersArr)
|
||||
if (config.KeepAliveTabs) {
|
||||
@@ -67,7 +64,7 @@ export const useRouterStore = defineStore('router', () => {
|
||||
keepArrTemp.push(componentName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 3. 如果子路由在tabs中打开,父路由也需要keepAlive
|
||||
if (nameMap[item.name]) {
|
||||
keepArrTemp.push(nameMap[item.name])
|
||||
@@ -77,7 +74,6 @@ export const useRouterStore = defineStore('router', () => {
|
||||
keepAliveRouters.value = Array.from(new Set(keepArrTemp))
|
||||
}
|
||||
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
emitter.on('setKeepAlive', setKeepAliveRouters)
|
||||
@@ -104,29 +100,29 @@ export const useRouterStore = defineStore('router', () => {
|
||||
|
||||
const findTopActive = (menuMap, routeName) => {
|
||||
for (let topName in menuMap) {
|
||||
const topItem = menuMap[topName];
|
||||
if (topItem.children?.some(item => item.name === routeName)) {
|
||||
return topName;
|
||||
const topItem = menuMap[topName]
|
||||
if (topItem.children?.some((item) => item.name === routeName)) {
|
||||
return topName
|
||||
}
|
||||
const foundName = findTopActive(topItem.children || {}, routeName);
|
||||
const foundName = findTopActive(topItem.children || {}, routeName)
|
||||
if (foundName) {
|
||||
return topName;
|
||||
return topName
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return null
|
||||
}
|
||||
|
||||
watchEffect(() => {
|
||||
let topActive = sessionStorage.getItem('topActive')
|
||||
// 初始化菜单内容,防止重复添加
|
||||
topMenu.value = [];
|
||||
topMenu.value = []
|
||||
asyncRouters.value[0]?.children.forEach((item) => {
|
||||
if (item.hidden) return
|
||||
menuMap[item.name] = item
|
||||
topMenu.value.push({ ...item, children: [] })
|
||||
})
|
||||
if (!topActive || topActive === 'undefined' || topActive === 'null') {
|
||||
topActive = findTopActive(menuMap, route.name);
|
||||
topActive = findTopActive(menuMap, route.name)
|
||||
}
|
||||
setLeftMenu(topActive)
|
||||
})
|
||||
@@ -164,7 +160,7 @@ export const useRouterStore = defineStore('router', () => {
|
||||
if (notLayoutRouterArr.length !== 0) {
|
||||
baseRouter.push(...notLayoutRouterArr)
|
||||
}
|
||||
console.log('baseRouter', baseRouter)
|
||||
// console.log('baseRouter', baseRouter)
|
||||
asyncRouterHandle(baseRouter)
|
||||
KeepAliveFilter(asyncRouter)
|
||||
asyncRouters.value = baseRouter
|
||||
|
||||
Reference in New Issue
Block a user