From fc92310e5f2ad0dc1b5748fa31f5c2f4dbe89329 Mon Sep 17 00:00:00 2001 From: toesbieya <1647775459@qq.com> Date: Thu, 6 Aug 2020 14:14:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=AF=B9=E4=BA=8E?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=85=B1=E7=94=A8=E7=BB=84=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E9=A1=B5=E9=9D=A2=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vue/src/layout/component/KeepAlive.js | 4 ++-- vue/src/router/authority/module/purchase.js | 6 ++++-- vue/src/router/authority/module/sell.js | 6 ++++-- vue/src/router/constant/module/example.js | 14 ++++++++++++-- vue/src/router/index.js | 2 +- vue/src/router/util.js | 8 +++----- vue/src/store/module/tagsView.js | 8 ++++---- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/vue/src/layout/component/KeepAlive.js b/vue/src/layout/component/KeepAlive.js index 9984000..8e94707 100644 --- a/vue/src/layout/component/KeepAlive.js +++ b/vue/src/layout/component/KeepAlive.js @@ -27,8 +27,8 @@ function pruneCacheEntry(cache, key, current) { function getCacheKey(route, componentOptions) { if (KEY in componentOptions) return componentOptions[KEY] - const {path, meta} = route - const key = meta && meta.isDetailPage ? path : getComponentName(componentOptions) + const {path, fullPath, meta} = route + const key = meta.usePathKey ? path : meta.useFullPathKey ? fullPath : getComponentName(componentOptions) componentOptions[KEY] = key diff --git a/vue/src/router/authority/module/purchase.js b/vue/src/router/authority/module/purchase.js index 5b72266..f1626cc 100644 --- a/vue/src/router/authority/module/purchase.js +++ b/vue/src/router/authority/module/purchase.js @@ -32,7 +32,8 @@ const router = { } }, activeMenu: '/doc/purchase/order', - isDetailPage: true + usePathKey: true, + commonModule:'@/view/purchase/order/detail' } }, { @@ -59,7 +60,8 @@ const router = { } }, activeMenu: '/doc/purchase/inbound', - isDetailPage: true + usePathKey: true, + commonModule: '@/view/purchase/inbound/detail' } } ] diff --git a/vue/src/router/authority/module/sell.js b/vue/src/router/authority/module/sell.js index 17608dd..ac65541 100644 --- a/vue/src/router/authority/module/sell.js +++ b/vue/src/router/authority/module/sell.js @@ -32,7 +32,8 @@ const router = { } }, activeMenu: '/doc/sell/order', - isDetailPage: true + usePathKey: true, + commonModule:'@/view/sell/order/detail' } }, { @@ -59,7 +60,8 @@ const router = { } }, activeMenu: '/doc/sell/outbound', - isDetailPage: true + usePathKey: true, + commonModule: '@/view/sell/outbound/detail' } } ] diff --git a/vue/src/router/constant/module/example.js b/vue/src/router/constant/module/example.js index ba1104a..a3ed90d 100644 --- a/vue/src/router/constant/module/example.js +++ b/vue/src/router/constant/module/example.js @@ -96,13 +96,23 @@ const router = { path: 'detailPage1', name: 'detailPage1', 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', name: 'detailPage2', component: lazyLoadView(import('@/view/example/detailPage')), - meta: {title: '详情页缓存2', noCache: false, isDetailPage: true} + meta: { + title: '详情页缓存2', + noCache: false, + usePathKey: true, + commonModule: '@/view/example/detailPage' + } } ] } diff --git a/vue/src/router/index.js b/vue/src/router/index.js index c1eca4b..d6e0139 100644 --- a/vue/src/router/index.js +++ b/vue/src/router/index.js @@ -9,7 +9,7 @@ * 搜索选项显示:name && meta.title * tab栏显示:name && (meta.title || meta.dynamicTitle) * tab栏固定显示:meta.affix -* 页面不缓存:!name && !meta.isDetailPage || meta.noCache +* 页面不缓存:!name && !meta.usePathKey && !meta.useFullPathKey || meta.noCache * 打开iframe:meta.iframe,不会重复打开相同src的iframe * */ import Vue from 'vue' diff --git a/vue/src/router/util.js b/vue/src/router/util.js index 9de3c21..f953f6f 100644 --- a/vue/src/router/util.js +++ b/vue/src/router/util.js @@ -52,11 +52,9 @@ export function lazyLoadView(component) { //判断是否需要一次额外的redirect跳转 export function needExtraRedirect(to, from) { - //若是详情页之间的跳转,借助redirect避免组件复用 - const isToDetailPage = to.meta.isDetailPage, - isFromDetailPage = from.meta.isDetailPage - - return isToDetailPage !== undefined && isToDetailPage === isFromDetailPage + //若是共用组件的路由页面之间的跳转,借助redirect避免组件复用 + const a = to.meta.commonModule, b = from.meta.commonModule + return !isEmpty(a) && a === b } //初始化菜单和权限 diff --git a/vue/src/store/module/tagsView.js b/vue/src/store/module/tagsView.js index 85a5d5c..f851f58 100644 --- a/vue/src/store/module/tagsView.js +++ b/vue/src/store/module/tagsView.js @@ -22,9 +22,9 @@ const mutations = { state.visitedViews.push({...view, title}) }, 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) @@ -69,8 +69,8 @@ const actions = { } function getCachedViewKey(view) { - const isDetailPage = view.meta && view.meta.isDetailPage - return isDetailPage ? view.path : view.name + const {usePathKey, useFullPathKey} = view.meta || {} + return usePathKey ? view.path : useFullPathKey ? view.fullPath : view.name } export default {