瀏覽代碼

修复缓存问题

zhengjinyi 2 年之前
父節點
當前提交
30237ada2c
共有 4 個文件被更改,包括 39 次插入66 次删除
  1. 8 3
      src/layout/components/AppMain.vue
  2. 11 53
      src/router/modules/user.js
  3. 19 9
      src/store/modules/tagsView.js
  4. 1 1
      src/views/user/record/list.vue

+ 8 - 3
src/layout/components/AppMain.vue

@@ -1,7 +1,7 @@
 <template>
   <section class="app-main">
     <transition name="fade-transform" mode="out-in">
-      <keep-alive>
+      <keep-alive :include="cachedViews">
         <router-view :key="key" />
       </keep-alive>
     </transition>
@@ -13,9 +13,11 @@ export default {
   name: 'AppMain',
   computed: {
     cachedViews() {
+      console.log('cachedViews', this.$store.state.tagsView.cachedViews)
       return this.$store.state.tagsView.cachedViews
     },
     key() {
+      console.log('path', this.$route.path)
       return this.$route.path
     }
   }
@@ -30,15 +32,18 @@ export default {
   position: relative;
   overflow: hidden;
 }
-.fixed-header+.app-main {
+
+.fixed-header + .app-main {
   padding-top: 50px;
 }
+
 .hasTagsView {
   .app-main {
     /* 84 = navbar + tags-view = 50 + 34 */
     min-height: calc(100vh - 84px);
   }
-  .fixed-header+.app-main {
+
+  .fixed-header + .app-main {
     padding-top: 84px;
   }
 }

+ 11 - 53
src/router/modules/user.js

@@ -5,65 +5,23 @@ import Layout from '@/layout'
 const userRouter = {
   path: '/user',
   component: Layout,
-  redirect: '/user/club',
+  redirect: '/user/list',
   alwaysShow: true, // will always show the root menu
-  name: 'userSetting', // name必须和后台配置一致,不然匹配不到
+  name: 'UserSitting', // name必须和后台配置一致,不然匹配不到
   meta: { title: '用户管理', icon: 'user' },
   children: [
     {
-      path: 'record',
-      component: () => import('@/views/index'),
-      redirect: '/user/record/list',
-      name: 'UserRecordMenu',
-      meta: { title: '用户行为记录', icon: 'international' },
-      children: [
-        {
-          path: 'list',
-          hidden: true,
-          component: () => import('@/views/user/record/list'),
-          name: 'RecordList',
-          meta: { title: '用户行为记录', activeMenu: '/user/record' }
-        },
-        {
-          path: 'detail',
-          hidden: true,
-          component: () => import('@/views/user/record/detail-list.vue'),
-          name: 'RecordDtails',
-          meta: { title: '查看详情', activeMenu: '/user/record/' }
-        }
-      ]
+      path: 'record-list',
+      component: () => import('@/views/user/record/list'),
+      name: 'RecordList',
+      meta: { title: '用户行为记录', icon: 'international', activeMenu: '/user/list' }
     },
     {
-      path: 'club',
-      name: 'UserClubMenu',
-      redirect: '/user/club/list',
-      alwaysShow: true,
-      component: () => import('@/views/index'),
-      meta: { title: '机构管理' },
-      children: [
-        {
-          path: 'list',
-          name: 'ClubList',
-          component: () => import('@/views/user/club/list'),
-          meta: { title: '机构列表' }
-        }
-      ]
-    },
-    {
-      path: 'supplier',
-      name: 'UserSupplierMenu',
-      redirect: '/user/supplier/list',
-      alwaysShow: true,
-      component: () => import('@/views/index'),
-      meta: { title: '供应商管理', useDefault: true },
-      children: [
-        {
-          path: 'list',
-          name: 'SupplierAllList',
-          component: () => import('@/views/user/supplier/list'),
-          meta: { title: '供应商列表' }
-        }
-      ]
+      path: 'detail-list',
+      hidden: true,
+      component: () => import('@/views/user/record/detail-list'),
+      name: 'RecordDtails',
+      meta: { title: '查看详情', noCache: true, activeMenu: '/user/list' }
     }
   ]
 }

+ 19 - 9
src/store/modules/tagsView.js

@@ -1,6 +1,6 @@
 const state = {
   visitedViews: [],
-  cachedViews: ['AppChildMain']
+  cachedViews: []
 }
 
 const mutations = {
@@ -28,8 +28,13 @@ const mutations = {
     }
   },
   DEL_CACHED_VIEW: (state, view) => {
-    const index = state.cachedViews.indexOf(view.name)
-    index > -1 && state.cachedViews.splice(index, 1)
+    for (const i of state.cachedViews) {
+      if (i === view.name) {
+        const index = state.cachedViews.indexOf(i)
+        state.cachedViews.splice(index, 1)
+        break
+      }
+    }
   },
 
   DEL_OTHERS_VISITED_VIEWS: (state, view) => {
@@ -38,12 +43,12 @@ const mutations = {
     })
   },
   DEL_OTHERS_CACHED_VIEWS: (state, view) => {
-    const index = state.cachedViews.indexOf(view.name)
-    if (index > -1) {
-      state.cachedViews = state.cachedViews.slice(index, index + 1)
-    } else {
-      // if index = -1, there is no cached tags
-      state.cachedViews = []
+    for (const i of state.cachedViews) {
+      if (i === view.name) {
+        const index = state.cachedViews.indexOf(i)
+        state.cachedViews = state.cachedViews.slice(index, index + 1)
+        break
+      }
     }
   },
 
@@ -63,6 +68,11 @@ const mutations = {
         break
       }
     }
+  },
+  // 清空全部页面
+  CLEAR_ALL_VIEW: (state) => {
+    state.visitedViews = []
+    state.cachedViews = []
   }
 }
 

+ 1 - 1
src/views/user/record/list.vue

@@ -442,7 +442,7 @@ export default {
     },
     // 查看详情
     handleRecordDetail(row) {
-      this.$router.push({ path: '/user/record/detail', query: { ip: row.ip, accessDate: row.accessDate, userId: row.userId }})
+      this.$router.push({ path: '/user/detail-list', query: { ip: row.ip, accessDate: row.accessDate, userId: row.userId }})
     },
 
     // 导出