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/views/jcsz/wldw.vue                  |    2 +-
 src/store/modules/user.js                |   13 +++++++++----
 src/views/jcsz/jsqd.vue                  |    2 +-
 src/layout/components/TagsView/index.vue |   28 ++++++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 6 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
     },
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index 3f0f241..7f65049 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -90,7 +90,7 @@
   },
 
   // user logout
-  logout({ commit, state }) {
+  logout({ commit, state, dispatch }) {
     return new Promise((resolve, reject) => {
       const usercode = getCookie('navTabId')
       const username = getCookie('admin')
@@ -112,10 +112,15 @@
           removeCookie('navTabId')
           removeCookie('usertype')
           removeCookie('userid')
-        }
-        commit('RESET_STATE')
 
-        resolve()
+          // reset visited views and cached views
+          dispatch('tagsView/delAllViews', null, { root: true })
+          sessionStorage.removeItem('tabViews')
+
+          commit('RESET_STATE')
+
+          resolve()
+        }
       }).catch(error => {
         reject(error)
       })
diff --git a/src/views/jcsz/jsqd.vue b/src/views/jcsz/jsqd.vue
index 3428180..db1b229 100644
--- a/src/views/jcsz/jsqd.vue
+++ b/src/views/jcsz/jsqd.vue
@@ -509,7 +509,7 @@
 
 const SER_HZ = /^[\u4e00-\u9fa5]+$/
 export default {
-  name: 'Zzjg',
+  name: 'JSQD',
   components: {
     Pagination
   },
diff --git a/src/views/jcsz/wldw.vue b/src/views/jcsz/wldw.vue
index 816270d..3b1de99 100644
--- a/src/views/jcsz/wldw.vue
+++ b/src/views/jcsz/wldw.vue
@@ -210,7 +210,7 @@
 
 const SER_HZ = /^[\u4e00-\u9fa5]+$/
 export default {
-  name: 'Zzjg',
+  name: 'WLDW',
   components: {
     Pagination
   },

--
Gitblit v1.9.3