Browse Source

Merge remote-tracking branch 'origin/master'

gt 2 years ago
parent
commit
f4137aaa9b
2 changed files with 45 additions and 2 deletions
  1. 37 2
      chuanyi-admin/src/App.vue
  2. 8 0
      chuanyi-admin/src/store/modules/tagsView.js

+ 37 - 2
chuanyi-admin/src/App.vue

@@ -6,7 +6,39 @@
 
 
 <script>
 <script>
 export default {
 export default {
-  name: 'App'
+  name: 'App',
+  computed: {
+    visitedViews() {
+      return this.$store.getters.visitedViews
+    }
+  },
+  created() {
+    this.beforeUnload()
+  },
+  methods: {
+    beforeUnload() {
+      window.addEventListener('beforeunload', () => {
+        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.dispatch('tagsView/setVisitedViews', oldViews)
+      }
+    }
+  }
 }
 }
 </script>
 </script>
 
 
@@ -14,14 +46,17 @@ export default {
 .sy-content {
 .sy-content {
   margin: 15px;
   margin: 15px;
 }
 }
+
 .btn_custom_cancel {
 .btn_custom_cancel {
   float: right;
   float: right;
   margin-left: 10px !important;
   margin-left: 10px !important;
 }
 }
+
 .el-icon-delete {
 .el-icon-delete {
   color: red;
   color: red;
 }
 }
-.el-icon-delete + span {
+
+.el-icon-delete+span {
   color: red;
   color: red;
 }
 }
 </style>
 </style>

+ 8 - 0
chuanyi-admin/src/store/modules/tagsView.js

@@ -63,6 +63,10 @@ const mutations = {
         break
         break
       }
       }
     }
     }
+  },
+
+  SET_VISITED_VIEWS: (state, arr) => {
+    state.visitedViews = arr
   }
   }
 }
 }
 
 
@@ -149,6 +153,10 @@ const actions = {
 
 
   updateVisitedView({ commit }, view) {
   updateVisitedView({ commit }, view) {
     commit('UPDATE_VISITED_VIEW', view)
     commit('UPDATE_VISITED_VIEW', view)
+  },
+
+  setVisitedViews({ commit }, arr) {
+    commit('SET_VISITED_VIEWS', arr)
   }
   }
 }
 }