From e7f22e51057aa90e19afee1628dc68a0d7a6c99e Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期一, 11 七月 2022 08:51:57 +0800
Subject: [PATCH] 1.优化tagviews
---
src/layout/components/TagsView/index.vue | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/layout/components/TagsView/index.vue b/src/layout/components/TagsView/index.vue
index 12d2bc4..fc7779b 100644
--- a/src/layout/components/TagsView/index.vue
+++ b/src/layout/components/TagsView/index.vue
@@ -28,6 +28,7 @@
<script>
import ScrollPane from './ScrollPane'
import path from 'path'
+import { getCookie } from '@/utils/auth'
export default {
components: { ScrollPane },
@@ -64,8 +65,35 @@
mounted() {
this.initTags()
this.addTags()
+ this.beforeUnload()
},
methods: {
+ // 瑙e喅 vue-admin-template 鍒锋柊椤甸潰 TagsView 涓㈠け闂
+ beforeUnload() {
+ // 鐩戝惉椤甸潰鍒锋柊
+ window.addEventListener('beforeunload', () => {
+ // visitedViews鏁版嵁缁撴瀯澶鏉傛棤娉曠洿鎺SON.stringify澶勭悊锛屽厛杞崲闇�瑕佺殑鏁版嵁
+ const tabViews = this.visitedViews.map(item => {
+ return {
+ fullPath: item.fullPath,
+ hash: item.hash,
+ meta: { ...item.meta },
+ name: item.name,
+ params: { ...item.params },
+ path: item.path,
+ query: { ...item.query },
+ title: item.title
+ }
+ })
+ sessionStorage.setItem('tabViews', JSON.stringify(tabViews))
+ })
+
+ // 椤甸潰鍒濆鍖栧姞杞藉垽鏂紦瀛樹腑鏄惁鏈夋暟鎹�
+ const oldViews = JSON.parse(sessionStorage.getItem('tabViews')) || []
+ if (oldViews.length > 0) {
+ this.$store.state.tagsView.visitedViews = oldViews
+ }
+ },
isActive(route) {
return route.path === this.$route.path
},
--
Gitblit v1.9.3