修改了对于缓存共用组件的路由页面的逻辑

master
toesbieya 6 years ago
parent 30405f3fdb
commit fc92310e5f
  1. 4
      vue/src/layout/component/KeepAlive.js
  2. 6
      vue/src/router/authority/module/purchase.js
  3. 6
      vue/src/router/authority/module/sell.js
  4. 14
      vue/src/router/constant/module/example.js
  5. 2
      vue/src/router/index.js
  6. 8
      vue/src/router/util.js
  7. 8
      vue/src/store/module/tagsView.js

@ -27,8 +27,8 @@ function pruneCacheEntry(cache, key, current) {
function getCacheKey(route, componentOptions) { function getCacheKey(route, componentOptions) {
if (KEY in componentOptions) return componentOptions[KEY] if (KEY in componentOptions) return componentOptions[KEY]
const {path, meta} = route const {path, fullPath, meta} = route
const key = meta && meta.isDetailPage ? path : getComponentName(componentOptions) const key = meta.usePathKey ? path : meta.useFullPathKey ? fullPath : getComponentName(componentOptions)
componentOptions[KEY] = key componentOptions[KEY] = key

@ -32,7 +32,8 @@ const router = {
} }
}, },
activeMenu: '/doc/purchase/order', activeMenu: '/doc/purchase/order',
isDetailPage: true usePathKey: true,
commonModule:'@/view/purchase/order/detail'
} }
}, },
{ {
@ -59,7 +60,8 @@ const router = {
} }
}, },
activeMenu: '/doc/purchase/inbound', activeMenu: '/doc/purchase/inbound',
isDetailPage: true usePathKey: true,
commonModule: '@/view/purchase/inbound/detail'
} }
} }
] ]

@ -32,7 +32,8 @@ const router = {
} }
}, },
activeMenu: '/doc/sell/order', activeMenu: '/doc/sell/order',
isDetailPage: true usePathKey: true,
commonModule:'@/view/sell/order/detail'
} }
}, },
{ {
@ -59,7 +60,8 @@ const router = {
} }
}, },
activeMenu: '/doc/sell/outbound', activeMenu: '/doc/sell/outbound',
isDetailPage: true usePathKey: true,
commonModule: '@/view/sell/outbound/detail'
} }
} }
] ]

@ -96,13 +96,23 @@ const router = {
path: 'detailPage1', path: 'detailPage1',
name: 'detailPage1', name: 'detailPage1',
component: lazyLoadView(import('@/view/example/detailPage')), component: lazyLoadView(import('@/view/example/detailPage')),
meta: {title: '详情页缓存1', noCache: false, isDetailPage: true} meta: {
title: '详情页缓存1',
noCache: false,
usePathKey: true,
commonModule: '@/view/example/detailPage'
}
}, },
{ {
path: 'detailPage2', path: 'detailPage2',
name: 'detailPage2', name: 'detailPage2',
component: lazyLoadView(import('@/view/example/detailPage')), component: lazyLoadView(import('@/view/example/detailPage')),
meta: {title: '详情页缓存2', noCache: false, isDetailPage: true} meta: {
title: '详情页缓存2',
noCache: false,
usePathKey: true,
commonModule: '@/view/example/detailPage'
}
} }
] ]
} }

@ -9,7 +9,7 @@
* 搜索选项显示name && meta.title * 搜索选项显示name && meta.title
* tab栏显示name && (meta.title || meta.dynamicTitle) * tab栏显示name && (meta.title || meta.dynamicTitle)
* tab栏固定显示meta.affix * tab栏固定显示meta.affix
* 页面不缓存!name && !meta.isDetailPage || meta.noCache * 页面不缓存!name && !meta.usePathKey && !meta.useFullPathKey || meta.noCache
* 打开iframemeta.iframe不会重复打开相同src的iframe * 打开iframemeta.iframe不会重复打开相同src的iframe
* */ * */
import Vue from 'vue' import Vue from 'vue'

@ -52,11 +52,9 @@ export function lazyLoadView(component) {
//判断是否需要一次额外的redirect跳转 //判断是否需要一次额外的redirect跳转
export function needExtraRedirect(to, from) { export function needExtraRedirect(to, from) {
//若是详情页之间的跳转,借助redirect避免组件复用 //若是共用组件的路由页面之间的跳转,借助redirect避免组件复用
const isToDetailPage = to.meta.isDetailPage, const a = to.meta.commonModule, b = from.meta.commonModule
isFromDetailPage = from.meta.isDetailPage return !isEmpty(a) && a === b
return isToDetailPage !== undefined && isToDetailPage === isFromDetailPage
} }
//初始化菜单和权限 //初始化菜单和权限

@ -22,9 +22,9 @@ const mutations = {
state.visitedViews.push({...view, title}) state.visitedViews.push({...view, title})
}, },
addCachedView(state, view) { addCachedView(state, view) {
const {noCache, iframe, isDetailPage} = view.meta || {} const {noCache, iframe, usePathKey, useFullPathKey} = view.meta || {}
if (noCache || iframe || !view.name && !isDetailPage) return if (noCache || iframe || !view.name && !usePathKey && !useFullPathKey) return
const key = getCachedViewKey(view) const key = getCachedViewKey(view)
@ -69,8 +69,8 @@ const actions = {
} }
function getCachedViewKey(view) { function getCachedViewKey(view) {
const isDetailPage = view.meta && view.meta.isDetailPage const {usePathKey, useFullPathKey} = view.meta || {}
return isDetailPage ? view.path : view.name return usePathKey ? view.path : useFullPathKey ? view.fullPath : view.name
} }
export default { export default {

Loading…
Cancel
Save