From 041075633fef4ccc857b3cae9562a2ab78ebe80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Fri, 15 Feb 2019 15:26:48 +0800 Subject: [PATCH] fearure[TagsView]: add affix option (#1577) --- src/router/index.js | 5 +- src/store/modules/tagsView.js | 13 ++-- src/views/layout/components/TagsView.vue | 76 +++++++++++++++++++----- 3 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index a86e3a13..60524517 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -29,6 +29,7 @@ import nestedRouter from './modules/nested' icon: 'svg-name' the icon show in the sidebar noCache: true if true, the page will no be cached(default is false) breadcrumb: false if false, the item will hidden in breadcrumb(default is true) + affix: true if true, the tag will affix in the tags-view } **/ export const constantRouterMap = [ @@ -72,7 +73,7 @@ export const constantRouterMap = [ path: 'dashboard', component: () => import('@/views/dashboard/index'), name: 'Dashboard', - meta: { title: 'dashboard', icon: 'dashboard', noCache: true } + meta: { title: 'dashboard', icon: 'dashboard', noCache: true, affix: true } } ] }, @@ -85,7 +86,7 @@ export const constantRouterMap = [ path: 'index', component: () => import('@/views/documentation/index'), name: 'Documentation', - meta: { title: 'documentation', icon: 'documentation', noCache: true } + meta: { title: 'documentation', icon: 'documentation', affix: true } } ] }, diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index cbf9eeb7..378cbcd3 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -38,12 +38,9 @@ const tagsView = { }, DEL_OTHERS_VISITED_VIEWS: (state, view) => { - for (const [i, v] of state.visitedViews.entries()) { - if (v.path === view.path) { - state.visitedViews = state.visitedViews.slice(i, i + 1) - break - } - } + state.visitedViews = state.visitedViews.filter(v => { + return v.meta.affix || v.path === view.path + }) }, DEL_OTHERS_CACHED_VIEWS: (state, view) => { for (const i of state.cachedViews) { @@ -56,7 +53,9 @@ const tagsView = { }, DEL_ALL_VISITED_VIEWS: state => { - state.visitedViews = [] + // keep affix tags + const affixTags = state.visitedViews.filter(tag => tag.meta.affix) + state.visitedViews = affixTags }, DEL_ALL_CACHED_VIEWS: state => { state.cachedViews = [] diff --git a/src/views/layout/components/TagsView.vue b/src/views/layout/components/TagsView.vue index c16827b6..cfac9c7d 100644 --- a/src/views/layout/components/TagsView.vue +++ b/src/views/layout/components/TagsView.vue @@ -12,14 +12,15 @@ @click.middle.native="closeSelectedTag(tag)" @contextmenu.prevent.native="openMenu(tag,$event)"> {{ generateTitle(tag.title) }} - +
  • {{ $t('tagsView.refresh') }}
  • -
  • {{ $t('tagsView.close') }}
  • +
  • {{ + $t('tagsView.close') }}
  • {{ $t('tagsView.closeOthers') }}
  • -
  • {{ $t('tagsView.closeAll') }}
  • +
  • {{ $t('tagsView.closeAll') }}
@@ -27,6 +28,7 @@