From f6e7e623917e91cd4f84f7a78b99425cf41464e8 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 29 Sep 2020 16:38:41 +0800 Subject: [PATCH] =?UTF-8?q?bugfixed=20tabs=EF=BC=8C=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=97=B6=EF=BC=8C=E8=B7=AF=E7=94=B1=E6=9C=AA?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- portal/src/app/main/tabs/tabs.component.html | 2 +- portal/src/app/main/tabs/tabs.component.ts | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/portal/src/app/main/tabs/tabs.component.html b/portal/src/app/main/tabs/tabs.component.html index 1122480..c053092 100644 --- a/portal/src/app/main/tabs/tabs.component.html +++ b/portal/src/app/main/tabs/tabs.component.html @@ -14,7 +14,7 @@ {{tab.component && tab.component.instance.title || tab.name || tab.url}} - +
diff --git a/portal/src/app/main/tabs/tabs.component.ts b/portal/src/app/main/tabs/tabs.component.ts index 46aa0a0..d460b2f 100644 --- a/portal/src/app/main/tabs/tabs.component.ts +++ b/portal/src/app/main/tabs/tabs.component.ts @@ -98,13 +98,25 @@ export class TabsComponent implements OnInit, OnDestroy, AfterViewInit { } onTabClose(index): void { - const tab = this.tabs.splice(index, 1)[0]; - if (this.current >= index && this.current > 0) { - this.current--; + if (this.tabs.length === 1) { + //TODO 打开默认页 + return; } + + const tab = this.tabs.splice(index, 1)[0]; if (tab.component) { tab.component.destroy(); } + if (this.current > index) { + this.current--; + } else if (this.current === index) { + if (this.current >= this.tabs.length) { + this.current = this.tabs.length - 1; + } + // 用修改路由的方式触发 + this.router.navigate(['/admin/' + this.tabs[this.current].route]); + return; + } } loadTab(index): void { -- GitLab