Skip to content

Commit 49c53c5

Browse files
committed
Fixed: Complete the type
1 parent bed130c commit 49c53c5

2 files changed

Lines changed: 47 additions & 9 deletions

File tree

src/app/pages/connect/connect.component.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<elements-chat></elements-chat>
33

44
<div #contentWindow *ngIf="isDirect">
5-
<div class="terminal-connect" *ngIf="view && view.connectMethod?.component === 'koko'">
6-
<div *ngIf="view.connectMethod?.value === 'web_sftp'" style="height: 100%; width: 100%">
5+
<div class="terminal-connect" *ngIf="view && isTerminalComponent()">
6+
<div *ngIf="isWebSftp()" style="height: 100%; width: 100%">
77
<elements-content-window *ngIf="view" [view]="view"></elements-content-window>
88
</div>
99

10-
<div *ngIf="view.connectMethod?.value === 'web_cli'" style="height: 100%; width: 100%">
10+
<div *ngIf="isWebCliOrGui()" style="height: 100%; width: 100%">
1111
<div class="card-header">
1212
<div class="card-header-left">
1313
<div class="card-title">
@@ -70,7 +70,7 @@
7070
</div>
7171
</div>
7272

73-
<div class="gui" *ngIf="view && (view.connectMethod?.component === 'lion')">
73+
<div class="gui" *ngIf="view && isGuiComponent()">
7474
<div class="timer-container">
7575
<div class="timer">
7676
<div [class.active]="isActive" class="status-dot"></div>
@@ -103,12 +103,12 @@
103103
<div #contentWindow *ngIf="view">
104104
<app-face-monitor></app-face-monitor>
105105

106-
<div class="terminal-connect" *ngIf="view && view.connectMethod?.component === 'koko'">
107-
<div *ngIf="view.connectMethod?.value === 'web_sftp'" style="height: 100%; width: 100%">
106+
<div class="terminal-connect" *ngIf="view && isTerminalComponent()">
107+
<div *ngIf="isWebSftp()" style="height: 100%; width: 100%">
108108
<elements-content-window *ngIf="view" [view]="view"></elements-content-window>
109109
</div>
110110

111-
<div *ngIf="view.connectMethod?.value === 'web_cli'" style="height: 100%; width: 100%">
111+
<div *ngIf="isWebCliOrGui()" style="height: 100%; width: 100%">
112112
<div class="card-header">
113113
<div class="card-header-left">
114114
<div class="card-title">
@@ -175,7 +175,7 @@
175175
</div>
176176
</div>
177177

178-
<div class="gui" *ngIf="view && (view.connectMethod?.component === 'lion' || view.connectMethod?.component === 'tinker')">
178+
<div class="gui" *ngIf="view && isGuiComponent()">
179179
<div class="timer-container">
180180
<div class="timer">
181181
<div [class.active]="isActive" class="status-dot"></div>

src/app/pages/connect/connect.component.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export class PagesConnectComponent implements OnInit, OnDestroy {
3232
public isActive: boolean = true;
3333
public isTimerStopped: boolean = false;
3434
public showActionIcons: boolean = false;
35+
private readonly guiComponents: Set<string> = new Set(['lion', 'tinker', 'razor', 'panda']);
36+
private readonly terminalComponents: Set<string> = new Set(['koko', 'chen', 'magnus', 'nec']);
3537

3638
// Direct 模式相关属性
3739
public endpoint: Endpoint;
@@ -106,7 +108,8 @@ export class PagesConnectComponent implements OnInit, OnDestroy {
106108
private checkDirectMode() {
107109
const params = this._route.snapshot.queryParams;
108110
// 检查是否有 direct: true 参数,或者同时有 account, asset, protocol 参数
109-
this.isDirect = params['direct'] === 'true' || !!(params['account'] && params['asset'] && params['protocol']);
111+
this.isDirect =
112+
params['direct'] === 'true' || !!(params['account'] && params['asset'] && params['protocol']);
110113

111114
if (this.isDirect) {
112115
this.accountId = params['account'];
@@ -342,6 +345,8 @@ export class PagesConnectComponent implements OnInit, OnDestroy {
342345
this.view.active = true;
343346
}
344347

348+
console.log('view', this.view);
349+
345350
if (this.view) {
346351
this._viewSrv.addView(this.view);
347352
this._viewSrv.activeView(this.view);
@@ -562,4 +567,37 @@ export class PagesConnectComponent implements OnInit, OnDestroy {
562567
return ['k8s', 'website'].includes(assetInfo.protocol);
563568
}
564569
}
570+
571+
/**
572+
* 判断当前视图是否为 GUI 组件
573+
*/
574+
public isGuiComponent(): boolean {
575+
const componentName = this.view?.connectMethod?.component as string | undefined;
576+
return !!componentName && this.guiComponents.has(componentName);
577+
}
578+
579+
/**
580+
* 判断当前视图是否为终端类组件
581+
*/
582+
public isTerminalComponent(): boolean {
583+
const componentName = this.view?.connectMethod?.component as string | undefined;
584+
return !!componentName && this.terminalComponents.has(componentName);
585+
}
586+
587+
/**
588+
* 是否为 Web SFTP
589+
*/
590+
public isWebSftp(): boolean {
591+
return this.view?.connectMethod?.value === 'web_sftp';
592+
}
593+
594+
/**
595+
* 是否为 Web CLI 或 Web GUI
596+
*/
597+
public isWebCliOrGui(): boolean {
598+
const value = this.view?.connectMethod?.value as string | undefined;
599+
return (
600+
value === 'web_cli' || value === 'web_gui' || value === 'db_guide' || value === 'vnc_guide'
601+
);
602+
}
565603
}

0 commit comments

Comments
 (0)