add affix tag
This commit is contained in:
parent
3b9abde89a
commit
708849c998
|
@ -0,0 +1 @@
|
|||
<svg class="icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="128" height="128"><defs><style/></defs><path d="M719.36 92.672l212.992 210.944c24.064 20.992 26.624 56.832 5.632 80.896-20.992 24.064-56.832 26.624-80.896 5.632a29.34 29.34 0 0 1-5.632-5.632l-21.504-16.896-217.6 307.2 68.096 68.096c20.992 24.064 18.432 59.904-5.632 80.896-21.504 18.944-53.76 18.944-75.264 0L198.656 420.352c-20.992-24.064-18.432-59.904 5.632-80.896 21.504-18.944 53.76-18.944 75.264 0l67.584 68.096 307.2-217.6-15.872-16.384c-24.064-20.992-26.624-56.832-5.632-80.896 20.992-24.064 56.832-26.624 80.896-5.632a29.34 29.34 0 0 1 5.632 5.632zM397.824 703.488l-79.872-78.848c-64.512 77.824-166.4 190.976-184.832 214.528-27.136 33.28-47.616 71.68-61.44 112.128 40.448-13.312 78.848-34.304 112.128-60.928 23.552-18.432 136.704-120.32 214.016-185.856v-1.024z"/></svg>
|
After Width: | Height: | Size: 861 B |
|
@ -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 }
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -12,14 +12,16 @@
|
|||
@click.middle.native="closeSelectedTag(tag)"
|
||||
@contextmenu.prevent.native="openMenu(tag,$event)">
|
||||
{{ generateTitle(tag.title) }}
|
||||
<span class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" />
|
||||
<span v-if="!tag.meta.affix" class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" />
|
||||
<svg-icon v-else class-name="affix-icon" icon-class="affix" />
|
||||
</router-link>
|
||||
</scroll-pane>
|
||||
<ul v-show="visible" :style="{left:left+'px',top:top+'px'}" class="contextmenu">
|
||||
<li @click="refreshSelectedTag(selectedTag)">{{ $t('tagsView.refresh') }}</li>
|
||||
<li @click="closeSelectedTag(selectedTag)">{{ $t('tagsView.close') }}</li>
|
||||
<li v-if="!(selectedTag.meta&&selectedTag.meta.affix)" @click="closeSelectedTag(selectedTag)">{{
|
||||
$t('tagsView.close') }}</li>
|
||||
<li @click="closeOthersTags">{{ $t('tagsView.closeOthers') }}</li>
|
||||
<li @click="closeAllTags">{{ $t('tagsView.closeAll') }}</li>
|
||||
<li @click="closeAllTags(selectedTag)">{{ $t('tagsView.closeAll') }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -27,6 +29,7 @@
|
|||
<script>
|
||||
import ScrollPane from '@/components/ScrollPane'
|
||||
import { generateTitle } from '@/utils/i18n'
|
||||
import path from 'path'
|
||||
|
||||
export default {
|
||||
components: { ScrollPane },
|
||||
|
@ -35,12 +38,16 @@ export default {
|
|||
visible: false,
|
||||
top: 0,
|
||||
left: 0,
|
||||
selectedTag: {}
|
||||
selectedTag: {},
|
||||
affixTags: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
visitedViews() {
|
||||
return this.$store.state.tagsView.visitedViews
|
||||
},
|
||||
routers() {
|
||||
return this.$store.state.permission.routers
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
@ -57,6 +64,7 @@ export default {
|
|||
}
|
||||
},
|
||||
mounted() {
|
||||
this.initViewTags()
|
||||
this.addViewTags()
|
||||
},
|
||||
methods: {
|
||||
|
@ -64,6 +72,35 @@ export default {
|
|||
isActive(route) {
|
||||
return route.path === this.$route.path
|
||||
},
|
||||
filterAffixTags(routes, basePath = '/') {
|
||||
let tags = []
|
||||
routes.forEach(route => {
|
||||
if (route.meta && route.meta.affix) {
|
||||
tags.push({
|
||||
path: path.resolve(basePath, route.path),
|
||||
name: route.name,
|
||||
meta: { ...route.meta }
|
||||
})
|
||||
}
|
||||
if (route.children) {
|
||||
const tempTags = this.filterAffixTags(route.children, route.path)
|
||||
if (tempTags.length >= 1) {
|
||||
tags = [...tags, ...tempTags]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return tags
|
||||
},
|
||||
initViewTags() {
|
||||
const affixTags = this.affixTags = this.filterAffixTags(this.routers)
|
||||
for (const tag of affixTags) {
|
||||
// Must have tag name
|
||||
if (tag.name) {
|
||||
this.$store.dispatch('addView', tag)
|
||||
}
|
||||
}
|
||||
},
|
||||
addViewTags() {
|
||||
const { name } = this.$route
|
||||
if (name) {
|
||||
|
@ -101,12 +138,7 @@ export default {
|
|||
closeSelectedTag(view) {
|
||||
this.$store.dispatch('delView', view).then(({ visitedViews }) => {
|
||||
if (this.isActive(view)) {
|
||||
const latestView = visitedViews.slice(-1)[0]
|
||||
if (latestView) {
|
||||
this.$router.push(latestView)
|
||||
} else {
|
||||
this.$router.push('/')
|
||||
}
|
||||
this.toLastView(visitedViews)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -116,9 +148,22 @@ export default {
|
|||
this.moveToCurrentTag()
|
||||
})
|
||||
},
|
||||
closeAllTags() {
|
||||
this.$store.dispatch('delAllViews')
|
||||
this.$router.push('/')
|
||||
closeAllTags(view) {
|
||||
this.$store.dispatch('delAllViews').then(({ visitedViews }) => {
|
||||
if (this.affixTags.some(tag => tag.path === view.path)) {
|
||||
return
|
||||
}
|
||||
this.toLastView(visitedViews)
|
||||
})
|
||||
},
|
||||
toLastView(visitedViews) {
|
||||
const latestView = visitedViews.slice(-1)[0]
|
||||
if (latestView) {
|
||||
this.$router.push(latestView)
|
||||
} else {
|
||||
// You can set another route
|
||||
this.$router.push('/')
|
||||
}
|
||||
},
|
||||
openMenu(tag, e) {
|
||||
const menuMinWidth = 105
|
||||
|
@ -186,6 +231,9 @@ export default {
|
|||
margin-right: 2px;
|
||||
}
|
||||
}
|
||||
.affix-icon{
|
||||
margin-left: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.contextmenu {
|
||||
|
|
Loading…
Reference in New Issue