Browse Source

bug修复

chenrui 3 years ago
parent
commit
1ad899b1ab
2 changed files with 25 additions and 23 deletions
  1. 23 23
      src/utils/mixin.js
  2. 2 0
      src/views/Home.vue

+ 23 - 23
src/utils/mixin.js

@@ -77,33 +77,33 @@ const AppDeviceEnquire = {
 // 所有页
 const commonMixin = {
   watch: {
-    '$store.state.app.loadingStatus': function (a,b) {
-      if(!a){
-        if(this.disabled!== undefined){
+    '$store.state.app.loadingStatus': function (a, b) {
+      if (!a) {
+        if (this.disabled !== undefined) {
           this.disabled = a
         }
-        if(this.spinning!== undefined){
+        if (this.spinning !== undefined) {
           this.spinning = a
         }
       }
     }
   },
-  methods:{
+  methods: {
     // 清除组件缓存
-    clearCompCache(cache,keys,key){
-      if (cache[key]&&cache[key].componentInstance){
+    clearCompCache (cache, keys, key) {
+      if (cache[key] && cache[key].componentInstance) {
         cache[key].componentInstance.$destroy()
         if (keys.length) {
-            var index = keys.indexOf(key);
-            if (index > -1) {
-                keys.splice(index, 1);
-            }
+          var index = keys.indexOf(key)
+          if (index > -1) {
+            keys.splice(index, 1)
+          }
         }
-        delete cache[key];
+        delete cache[key]
       }
     }
   },
-  beforeRouteLeave(to, from, next) {
+  beforeRouteLeave (to, from, next) {
     const newVal = to
     const oldVal = from
     // 是否时同一个父级菜单下的页面
@@ -120,28 +120,28 @@ const commonMixin = {
     // console.log(hasChildren,oa||ob||oc||oxt)
     const key = this.$vnode.key
     const parentNode = this.$vnode.parent
-    const cache = parentNode&&parentNode.componentInstance?parentNode.componentInstance.cache:null
-    const keys = parentNode&&parentNode.componentInstance?parentNode.componentInstance.keys:null
+    const cache = parentNode && parentNode.componentInstance ? parentNode.componentInstance.cache : null
+    const keys = parentNode && parentNode.componentInstance ? parentNode.componentInstance.keys : null
     const closeTabPages = this.$store.state.app.closeTabPages
     const multiTab = this.$store.state.app.multiTab
     // console.log(closeTabPages,key)
     // 清空同级路由的组件缓存
-    if(hasChildren&&(oa||ob||oc||oxt)&&cache&&keys){
-      this.clearCompCache(cache,keys,key)
+    if (hasChildren && (oa || ob || oc || oxt) && cache && keys) {
+      this.clearCompCache(cache, keys, key)
       // 单页签模式
-      if(!multiTab){
+      if (!multiTab) {
         this.$store.state.app.isNewTab = false
         this.$store.state.app.updateList = true
       }
     }
     // 单页签模式,并且不是同级菜单的清空组件
-    if(!multiTab&&!hasChildren){
-      this.clearCompCache(cache,keys,key)
+    if (!multiTab && !hasChildren) {
+      this.clearCompCache(cache, keys, key)
     }
     // 批量清空组件缓存
-    if(closeTabPages.length&&cache&&keys){
-      for(let i=0;i<closeTabPages.length;i++){
-        this.clearCompCache(cache,keys,closeTabPages[i])
+    if (closeTabPages && closeTabPages.length && cache && keys) {
+      for (let i = 0; i < closeTabPages.length; i++) {
+        this.clearCompCache(cache, keys, closeTabPages[i])
       }
       this.$store.state.app.closeTabPages = []
     }

+ 2 - 0
src/views/Home.vue

@@ -211,6 +211,7 @@
 </template>
 
 <script>
+import { commonMixin } from '@/utils/mixin'
 import { mapGetters } from 'vuex'
 import ResetPwd from '@/views/user/ResetPwd.vue'
 import newProduct from '@/views/productManagement/newProduct/modal.vue'
@@ -219,6 +220,7 @@ import { bizStateCount, bizData, dealerData } from '@/api/data'
 export default {
   name: 'Home',
   components: { ResetPwd, newProduct },
+  mixins: [commonMixin],
   data () {
     return {
       message: '欢迎登录' + process.env.VUE_APP_PRO_NAME,