Переглянути джерело

菜单切换 页签关闭后再打开需要刷新,不能直接使用缓存。

linwenxin 1 рік тому
батько
коміт
de2c4a62a7

+ 15 - 6
src/layout/components/AppMain.vue

@@ -2,9 +2,9 @@
   <section class="app-main" :style="{ paddingTop: show ? '140px' : '80px' }">
     <div class="app-main-view">
       <keep-alive>
-        <router-view v-if="$route.meta.isCache == 1" :key="$route.name" />
+        <router-view v-if="$route.meta.isCache == 1" :key="nameKey" />
       </keep-alive>
-      <router-view v-if="$route.meta.isCache != 1" :key="$route.name"/>
+      <router-view v-if="$route.meta.isCache != 1" :key="nameKey" />
       <zj-watermark color="rgba(200,200,200,.3)" position="absolute" :str="str" zIndex="99" />
     </div>
   </section>
@@ -12,15 +12,22 @@
 
 <script>
 import { mapGetters } from 'vuex'
-
 export default {
   name: 'AppMain',
+  data(){
+    return {
+      key:0
+    }
+  },
   computed: {
     ...mapGetters(['show']),
     str() {
       return this.$store.state?.user?.name
-    }
-  }
+    },
+    nameKey(){
+      return this.$store.state.tagsView.visitedViews.find(item=>item?.name===this.$route?.name)?.nameKey || "0"
+    },
+  },
 }
 </script>
 
@@ -32,10 +39,12 @@ export default {
   position: relative;
   overflow: hidden;
 }
-.fixed-header + .app-main {
+
+.fixed-header+.app-main {
   /* padding-top: 50px; */
   /* padding-top: 80px; */
 }
+
 .app-main-view {
   width: 100%;
   height: 100%;

+ 1 - 1
src/layout/components/TagsView/index.vue

@@ -113,7 +113,7 @@ export default {
     addTags() {
       const { name } = this.$route
       if (name) {
-        this.$store.dispatch('tagsView/addView', this.$route)
+        this.$store.dispatch('tagsView/addView', {...this.$route, nameKey:`${this.$route.name}_${Math.floor(Date.now() / 1000)}`})
       }
       return false
     },

+ 3 - 1
src/permission.js

@@ -27,6 +27,7 @@ function getc(obj) {
     return getc(obj.children[0])
   }
 }
+
 router.beforeEach(async (to, from, next) => {
   NProgress.start()
   document.title = getPageTitle(to.meta.title)
@@ -124,6 +125,7 @@ function buildRoute(route, parentUrl = '', bool = true) {
 
       try {
         item.component = _import(`${fullUrl}/index`)
+        item.component.name = item.name
       } catch (e) {
         console.log(e)
       }
@@ -161,7 +163,7 @@ function buildRoute(route, parentUrl = '', bool = true) {
     } else if (type == 2) {
       try {
         item.component = _import(`${fullUrl}/index`)
-
+        item.component.name = item.name
         if (!pages.find(ite => ite.path === item.path)) {
           item.path = `${item.path}${bool ? '' : ''}`
           pages.push(item)