From 708849c998d5c4c67a7d7da341c88d7c4e5cc65c Mon Sep 17 00:00:00 2001 From: Pan Date: Thu, 31 Jan 2019 17:22:49 +0800 Subject: [PATCH 1/5] add affix tag --- src/icons/svg/affix.svg | 1 + src/router/index.js | 5 +- src/store/modules/tagsView.js | 13 ++--- src/views/layout/components/TagsView.vue | 74 +++++++++++++++++++----- 4 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 src/icons/svg/affix.svg diff --git a/src/icons/svg/affix.svg b/src/icons/svg/affix.svg new file mode 100644 index 00000000000..34979fd81c9 --- /dev/null +++ b/src/icons/svg/affix.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index f42046ee15b..d03d7336ce9 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', noCache: true, affix: true } } ] }, diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index cbf9eeb7b5b..378cbcd3dae 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 c16827b6b78..b9b986f34f2 100644 --- a/src/views/layout/components/TagsView.vue +++ b/src/views/layout/components/TagsView.vue @@ -12,14 +12,16 @@ @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 +29,7 @@