feat: add function of disable closing page;

新增:禁用关闭页面功能;
master
chenghongxing 4 years ago
parent 313af63f33
commit 3d3e56de12
  1. 16
      src/layouts/tabs/TabsHead.vue
  2. 22
      src/layouts/tabs/TabsView.vue
  3. 5
      src/router/config.js

@ -16,9 +16,9 @@
</a-tooltip> </a-tooltip>
<a-tab-pane v-for="page in pageList" :key="page.fullPath"> <a-tab-pane v-for="page in pageList" :key="page.fullPath">
<div slot="tab" class="tab" @contextmenu="e => onContextmenu(page.fullPath, e)"> <div slot="tab" class="tab" @contextmenu="e => onContextmenu(page.fullPath, e)">
<a-icon v-if="page.fullPath === active || page.loading" @click="onRefresh(page)" class="icon-sync" :type="page.loading ? 'loading' : 'sync'" /> <a-icon @click="onRefresh(page)" :class="['icon-sync', {'hide': page.fullPath !== active && !page.loading}]" :type="page.loading ? 'loading' : 'sync'" />
<span @click="onTabClick(page.fullPath)" >{{pageName(page)}}</span> <div class="title" @click="onTabClick(page.fullPath)" >{{pageName(page)}}</div>
<a-icon @click="onClose(page.fullPath)" class="icon-close" type="close"/> <a-icon v-if="!page.unclose" @click="onClose(page.fullPath)" class="icon-close" type="close"/>
</div> </div>
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
@ -107,6 +107,11 @@
padding: 0 16px; padding: 0 16px;
font-size: 14px; font-size: 14px;
user-select: none; user-select: none;
transition: all 0.2s;
.title{
display: inline-block;
height: 100%;
}
.icon-close{ .icon-close{
font-size: 12px; font-size: 12px;
margin-left: 6px; margin-left: 6px;
@ -119,9 +124,14 @@
.icon-sync{ .icon-sync{
margin-left: -4px; margin-left: -4px;
color: @primary-4; color: @primary-4;
transition: all 0.3s ease-in-out;
&:hover{ &:hover{
color: @primary-color; color: @primary-color;
} }
font-size: 14px;
&.hide{
font-size: 0;
}
} }
} }
.tabs-head{ .tabs-head{

@ -153,8 +153,9 @@ export default {
}, },
closeOthers (pageKey) { closeOthers (pageKey) {
// //
this.clearCaches = this.pageList.filter(item => item.fullPath !== pageKey).map(item => item.cachedKey) const clearPages = this.pageList.filter(item => item.fullPath !== pageKey && !item.unclose)
this.pageList = this.pageList.filter(item => item.fullPath === pageKey) this.clearCaches = clearPages.map(item => item.cachedKey)
this.pageList = this.pageList.filter(item => !clearPages.includes(item))
// //
if (this.activePage != pageKey) { if (this.activePage != pageKey) {
this.activePage = pageKey this.activePage = pageKey
@ -164,8 +165,9 @@ export default {
closeLeft (pageKey) { closeLeft (pageKey) {
const index = this.pageList.findIndex(item => item.fullPath === pageKey) const index = this.pageList.findIndex(item => item.fullPath === pageKey)
// //
this.clearCaches = this.pageList.filter((item, i) => i < index).map(item => item.cachedKey) const clearPages = this.pageList.filter((item, i) => i < index && !item.unclose)
this.pageList = this.pageList.slice(index) this.clearCaches = clearPages.map(item => item.cachedKey)
this.pageList = this.pageList.filter(item => !clearPages.includes(item))
// //
if (!this.pageList.find(item => item.fullPath === this.activePage)) { if (!this.pageList.find(item => item.fullPath === this.activePage)) {
this.activePage = pageKey this.activePage = pageKey
@ -175,8 +177,9 @@ export default {
closeRight (pageKey) { closeRight (pageKey) {
// //
const index = this.pageList.findIndex(item => item.fullPath === pageKey) const index = this.pageList.findIndex(item => item.fullPath === pageKey)
this.clearCaches = this.pageList.filter((item, i) => i > index).map(item => item.cachedKey) const clearPages = this.pageList.filter((item, i) => i > index && !item.unclose)
this.pageList = this.pageList.slice(0, index + 1) this.clearCaches = clearPages.map(item => item.cachedKey)
this.pageList = this.pageList.filter(item => !clearPages.includes(item))
// //
if (!this.pageList.find(item => item.fullPath === this.activePage)) { if (!this.pageList.find(item => item.fullPath === this.activePage)) {
this.activePage = pageKey this.activePage = pageKey
@ -243,7 +246,11 @@ export default {
sessionStorage.setItem(process.env.VUE_APP_TBAS_KEY, JSON.stringify(tabs)) sessionStorage.setItem(process.env.VUE_APP_TBAS_KEY, JSON.stringify(tabs))
}, },
createPage(route) { createPage(route) {
return {keyPath: route.matched[route.matched.length - 1].path, fullPath: route.fullPath, loading: false} return {
keyPath: route.matched[route.matched.length - 1].path,
fullPath: route.fullPath, loading: false,
unclose: route.meta && route.meta.page && (route.meta.page.closable === false),
}
}, },
/** /**
* 设置页面缓存的key * 设置页面缓存的key
@ -251,6 +258,7 @@ export default {
*/ */
setCachedKey(route) { setCachedKey(route) {
const page = this.pageList.find(item => item.fullPath === route.fullPath) const page = this.pageList.find(item => item.fullPath === route.fullPath)
page.unclose = route.meta && route.meta.page && (route.meta.page.closable === false)
if (!page._init_) { if (!page._init_) {
page.cachedKey = this.$refs.tabContent.$vnode.key page.cachedKey = this.$refs.tabContent.$vnode.key
page._init_ = true page._init_ = true

@ -37,6 +37,11 @@ const options = {
{ {
path: 'workplace', path: 'workplace',
name: '工作台', name: '工作台',
meta: {
page: {
closable: false
}
},
component: () => import('@/pages/dashboard/workplace'), component: () => import('@/pages/dashboard/workplace'),
}, },
{ {

Loading…
Cancel
Save