From a1dfc360fcab5a9b5b4a3a86599ddc141b79e80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?piexlMax=28=E5=A5=87=E6=B7=BC?= Date: Tue, 30 Sep 2025 13:46:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=B7=AF=E7=94=B1):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=8E=A7=E5=88=B6=E6=A0=87=E7=AD=BE=E9=A1=B5?= =?UTF-8?q?keep-alive=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/core/config.js | 3 ++- web/src/pinia/modules/router.js | 35 +++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/web/src/core/config.js b/web/src/core/config.js index 63a89edc6..6c971778d 100644 --- a/web/src/core/config.js +++ b/web/src/core/config.js @@ -5,10 +5,11 @@ import packageInfo from '../../package.json' const greenText = (text) => `\x1b[32m${text}\x1b[0m` -const config = { +export const config = { appName: 'Gin-Vue-Admin', appLogo: 'logo.png', showViteLogo: true, + KeepAliveTabs: true, logs: [] } diff --git a/web/src/pinia/modules/router.js b/web/src/pinia/modules/router.js index ff1eb7613..c5c49ea08 100644 --- a/web/src/pinia/modules/router.js +++ b/web/src/pinia/modules/router.js @@ -5,6 +5,7 @@ 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"; const notLayoutRouterArr = [] const keepAliveRoutersArr = [] @@ -55,24 +56,24 @@ export const useRouterStore = defineStore('router', () => { // 1. 首先添加原有的keepAlive配置 keepArrTemp.push(...keepAliveRoutersArr) - - history.forEach((item) => { - // 2. 为所有history中的路由强制启用keep-alive - // 通过routeMap获取路由信息,然后通过pathInfo获取组件名 - const routeInfo = routeMap[item.name] - if (routeInfo && routeInfo.meta && routeInfo.meta.path) { - const componentName = pathInfo[routeInfo.meta.path] - if (componentName) { - keepArrTemp.push(componentName) + if (config.KeepAliveTabs) { + history.forEach((item) => { + // 2. 为所有history中的路由强制启用keep-alive + // 通过routeMap获取路由信息,然后通过pathInfo获取组件名 + const routeInfo = routeMap[item.name] + if (routeInfo && routeInfo.meta && routeInfo.meta.path) { + const componentName = pathInfo[routeInfo.meta.path] + if (componentName) { + keepArrTemp.push(componentName) + } } - } - - // 3. 如果子路由在tabs中打开,父路由也需要keepAlive - if (nameMap[item.name]) { - keepArrTemp.push(nameMap[item.name]) - } - }) - + + // 3. 如果子路由在tabs中打开,父路由也需要keepAlive + if (nameMap[item.name]) { + keepArrTemp.push(nameMap[item.name]) + } + }) + } keepAliveRouters.value = Array.from(new Set(keepArrTemp)) }