|
|
|
@ -12,14 +12,15 @@
|
|
|
|
|
@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)" />
|
|
|
|
|
</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 +28,7 @@
|
|
|
|
|
<script>
|
|
|
|
|
import ScrollPane from '@/components/ScrollPane'
|
|
|
|
|
import { generateTitle } from '@/utils/i18n'
|
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: { ScrollPane },
|
|
|
|
@ -35,17 +37,21 @@ 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: {
|
|
|
|
|
$route() {
|
|
|
|
|
this.addViewTags()
|
|
|
|
|
this.addTags()
|
|
|
|
|
this.moveToCurrentTag()
|
|
|
|
|
},
|
|
|
|
|
visible(value) {
|
|
|
|
@ -57,14 +63,44 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.addViewTags()
|
|
|
|
|
this.initTags()
|
|
|
|
|
this.addTags()
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
generateTitle, // generateTitle by vue-i18n
|
|
|
|
|
isActive(route) {
|
|
|
|
|
return route.path === this.$route.path
|
|
|
|
|
},
|
|
|
|
|
addViewTags() {
|
|
|
|
|
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
|
|
|
|
|
},
|
|
|
|
|
initTags() {
|
|
|
|
|
const affixTags = this.affixTags = this.filterAffixTags(this.routers)
|
|
|
|
|
for (const tag of affixTags) {
|
|
|
|
|
// Must have tag name
|
|
|
|
|
if (tag.name) {
|
|
|
|
|
this.$store.dispatch('addVisitedView', tag)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
addTags() {
|
|
|
|
|
const { name } = this.$route
|
|
|
|
|
if (name) {
|
|
|
|
|
this.$store.dispatch('addView', this.$route)
|
|
|
|
@ -101,12 +137,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 +147,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
|
|
|
|
|